Skip to content

Addition: flame agent #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions chopper/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.dart_tool/
11 changes: 11 additions & 0 deletions chopper/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## 1.1.1

- Fixed system promp

## 1.1.0

- Updated agent to enable commandless mode

## 1.0.0

- Initial version.
3 changes: 3 additions & 0 deletions chopper/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Agent Reamde File

This is a sample readme file for agent. You add description about the agent and any other instruction or information.
30 changes: 30 additions & 0 deletions chopper/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.

include: package:lints/recommended.yaml

# Uncomment the following section to specify additional rules.

# linter:
# rules:
# - camel_case_types

# analyzer:
# exclude:
# - path/to/excluded/files/**

# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints

# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options
128 changes: 128 additions & 0 deletions chopper/assets/examples/basic_example/definition.chopper.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions chopper/assets/examples/basic_example/definition.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import 'dart:async';

import 'package:chopper/chopper.dart';

part 'definition.chopper.dart';

@ChopperApi(baseUrl: '/resources')
abstract class MyService extends ChopperService {
static MyService create(ChopperClient client) => _$MyService(client);

@Get(path: '/{id}')
Future<Response> getResource(
@Path() String id,
);

@Get(path: '/', headers: {'foo': 'bar'})
Future<Response<Map>> getMapResource(
@Query() String id,
);

@Get(path: '/resources')
Future<Response<List<Map>>> getListResources();

@Post(path: '/')
Future<Response> postResourceUrlEncoded(
@Field('a') String toto,
@Field() String b,
);

@Post(path: '/multi')
@multipart
Future<Response> postResources(
@Part('1') Map a,
@Part('2') Map b,
@Part('3') String c,
);

@Post(path: '/file')
@multipart
Future<Response> postFile(
@Part('file') List<int> bytes,
);
}
24 changes: 24 additions & 0 deletions chopper/assets/examples/basic_example/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:chopper/chopper.dart';

import 'definition.dart';

Future<void> main() async {
final chopper = ChopperClient(
baseUrl: Uri.parse('http://localhost:8000'),
services: [
// the generated service
MyService.create(ChopperClient()),
],
converter: JsonConverter(),
);

final myService = chopper.getService<MyService>();

final response = await myService.getMapResource('1');
print(response.body);

final list = await myService.getListResources();
print(list.body);

chopper.dispose();
}
44 changes: 44 additions & 0 deletions chopper/assets/examples/basic_example/tag.chopper.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

87 changes: 87 additions & 0 deletions chopper/assets/examples/basic_example/tag.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/// @author luwenjie on 2024/3/20 11:38:11
///
///
///
import "package:chopper/chopper.dart";

import 'definition.dart';

part 'tag.chopper.dart';

Future<void> main() async {
final chopper = ChopperClient(
baseUrl: Uri.parse('http://localhost:8000'),
services: [
// the generated service
TagService.create(ChopperClient()),
],
interceptors: [
TagInterceptor(),
],
converter: JsonConverter(),
);

final myService = chopper.getService<MyService>();

final response = await myService.getMapResource('1');
print(response.body);

final list = await myService.getListResources();
print(list.body);
chopper.dispose();
}

// add a uniform appId header for some path
class BizTag {
final int appId;

BizTag({this.appId = 0});
}

class IncludeBodyNullOrEmptyTag {
bool includeNull = false;
bool includeEmpty = false;

IncludeBodyNullOrEmptyTag(this.includeNull, this.includeEmpty);
}

class TagConverter extends JsonConverter {
FutureOr<Request> convertRequest(Request request) {
final tag = request.tag;
if (tag is IncludeBodyNullOrEmptyTag) {
if (request.body is Map) {
final Map body = request.body as Map;
final Map bodyCopy = {};
for (final MapEntry entry in body.entries) {
if (!tag.includeNull && entry.value == null) continue;
if (!tag.includeEmpty && entry.value == "") continue;
bodyCopy[entry.key] = entry.value;
}
request = request.copyWith(body: bodyCopy);
}
}
}
}

class TagInterceptor implements RequestInterceptor {
FutureOr<Request> onRequest(Request request) {
final tag = request.tag;
if (tag is BizTag) {
request.headers["x-appId"] = tag.appId;
}
return request;
}
}

@ChopperApi(baseUrl: '/tag')
abstract class TagService extends ChopperService {
static TagService create(ChopperClient client) => _$TagService(client);

@get(path: '/bizRequest')
Future<Response> requestWithTag({@Tag() BizTag tag = const BizTag()});

@get(path: '/include')
Future<Response> includeBodyNullOrEmptyTag(
{@Tag()
IncludeBodyNullOrEmptyTag tag = const IncludeBodyNullOrEmptyTag()});
}
Loading