@adonis-agora/agent 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/dist/src/ai-tool-ref.d.ts +12 -3
- package/dist/src/ai-tool-ref.d.ts.map +1 -1
- package/dist/src/ai-tool-ref.js +25 -2
- package/dist/src/ai-tool-ref.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
# @adonis-agora/agent
|
|
2
2
|
|
|
3
|
+
## 0.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#19](https://github.com/DavideCarvalho/adonis-agent/pull/19) [`c3d7b14`](https://github.com/DavideCarvalho/adonis-agent/commit/c3d7b140cdf32ef4324e18d84a13860ff0eb1a7c) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Add a decorator-free `static tool` authoring form for class tools
|
|
8
|
+
|
|
9
|
+
A tool class can now declare its metadata with a `static tool = { name, kind, description, input, … }`
|
|
10
|
+
config instead of the `@AiTool({ … })` decorator — the same shape, mirroring
|
|
11
|
+
`@adonis-agora/durable`'s `static workflow`. Discovery, registration, and execution are identical;
|
|
12
|
+
`readAiToolMeta` now reads the static config when no decorator is present.
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import type {
|
|
16
|
+
AiToolCtx,
|
|
17
|
+
AiToolOptions,
|
|
18
|
+
ToolHandler,
|
|
19
|
+
} from "@adonis-agora/agent";
|
|
20
|
+
import { z } from "zod";
|
|
21
|
+
|
|
22
|
+
export default class GetWeather implements ToolHandler<{ city: string }> {
|
|
23
|
+
static tool = {
|
|
24
|
+
name: "getWeather",
|
|
25
|
+
kind: "read",
|
|
26
|
+
description: "Get the weather",
|
|
27
|
+
input: z.object({ city: z.string() }),
|
|
28
|
+
} satisfies AiToolOptions;
|
|
29
|
+
|
|
30
|
+
async execute(input: { city: string }, ctx: AiToolCtx) {
|
|
31
|
+
return { tempC: 21 };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
The `@AiTool` decorator and the functional `defineTool(...)` forms are unchanged.
|
|
37
|
+
|
|
3
38
|
## 0.6.0
|
|
4
39
|
|
|
5
40
|
### Minor Changes
|
|
@@ -33,9 +33,9 @@ export interface AiToolOptions {
|
|
|
33
33
|
*/
|
|
34
34
|
ability?: string;
|
|
35
35
|
}
|
|
36
|
-
/** The metadata
|
|
36
|
+
/** The metadata a tool class carries for discovery + registration — from `@AiTool` or `static tool`. */
|
|
37
37
|
export type AiToolMeta = AiToolOptions;
|
|
38
|
-
/** Structural shape of
|
|
38
|
+
/** Structural shape of a tool class: a constructor whose instance implements `execute`. */
|
|
39
39
|
export type ToolClass = abstract new (...args: never[]) => ToolHandler;
|
|
40
40
|
/**
|
|
41
41
|
* Marks a class as an AI tool. The class must implement `execute(input, ctx)`. The provider's
|
|
@@ -50,7 +50,16 @@ export type ToolClass = abstract new (...args: never[]) => ToolHandler;
|
|
|
50
50
|
* ```
|
|
51
51
|
*/
|
|
52
52
|
export declare function AiTool(options: AiToolOptions): <T extends ToolClass>(target: T) => T;
|
|
53
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* Read a tool class's {@link AiToolMeta}. Two authoring forms are supported, in this order:
|
|
55
|
+
*
|
|
56
|
+
* 1. The `@AiTool({ … })` decorator (stamps {@link AI_TOOL_META_KEY}).
|
|
57
|
+
* 2. A decorator-free `static tool = { name, kind, description, input, … }` config on the class — the
|
|
58
|
+
* same shape, mirroring `@adonis-agora/durable`'s `static workflow`. Preferred where you'd rather
|
|
59
|
+
* not rely on decorators.
|
|
60
|
+
*
|
|
61
|
+
* Accepts either the class itself or an instance (whose constructor carries the config).
|
|
62
|
+
*/
|
|
54
63
|
export declare function readAiToolMeta(target: unknown): AiToolMeta | undefined;
|
|
55
64
|
/** A tool expressed as data + handler (from {@link defineTool}), not an `@AiTool` class. */
|
|
56
65
|
export interface FunctionalTool {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-tool-ref.d.ts","sourceRoot":"","sources":["../../src/ai-tool-ref.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,EAAE,OAAO,MAAgD,CAAC;AAEvF;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,OAAO,MAAmD,CAAC;AAE1F,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,IAAI,EAAE,MAAM,GAAG,QAAQ,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,KAAK,EAAE,gBAAgB,CAAC;IACxB,oGAAoG;IACpG,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,
|
|
1
|
+
{"version":3,"file":"ai-tool-ref.d.ts","sourceRoot":"","sources":["../../src/ai-tool-ref.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,EAAE,OAAO,MAAgD,CAAC;AAEvF;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,OAAO,MAAmD,CAAC;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/dist/src/ai-tool-ref.js
CHANGED
|
@@ -31,7 +31,26 @@ export function AiTool(options) {
|
|
|
31
31
|
return target;
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
|
-
/** Read
|
|
34
|
+
/** Read a class's tool metadata off its `static tool = { name, kind, … }` config, if any. */
|
|
35
|
+
function staticToolMeta(target) {
|
|
36
|
+
if (typeof target !== 'function')
|
|
37
|
+
return undefined;
|
|
38
|
+
const config = target.tool;
|
|
39
|
+
if (config && typeof config === 'object' && typeof config.name === 'string') {
|
|
40
|
+
return config;
|
|
41
|
+
}
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Read a tool class's {@link AiToolMeta}. Two authoring forms are supported, in this order:
|
|
46
|
+
*
|
|
47
|
+
* 1. The `@AiTool({ … })` decorator (stamps {@link AI_TOOL_META_KEY}).
|
|
48
|
+
* 2. A decorator-free `static tool = { name, kind, description, input, … }` config on the class — the
|
|
49
|
+
* same shape, mirroring `@adonis-agora/durable`'s `static workflow`. Preferred where you'd rather
|
|
50
|
+
* not rely on decorators.
|
|
51
|
+
*
|
|
52
|
+
* Accepts either the class itself or an instance (whose constructor carries the config).
|
|
53
|
+
*/
|
|
35
54
|
export function readAiToolMeta(target) {
|
|
36
55
|
if (target === null || (typeof target !== 'function' && typeof target !== 'object')) {
|
|
37
56
|
return undefined;
|
|
@@ -41,7 +60,11 @@ export function readAiToolMeta(target) {
|
|
|
41
60
|
return direct;
|
|
42
61
|
}
|
|
43
62
|
const ctor = target.constructor;
|
|
44
|
-
|
|
63
|
+
const fromCtor = ctor?.[AI_TOOL_META_KEY];
|
|
64
|
+
if (fromCtor !== undefined) {
|
|
65
|
+
return fromCtor;
|
|
66
|
+
}
|
|
67
|
+
return staticToolMeta(target) ?? staticToolMeta(ctor);
|
|
45
68
|
}
|
|
46
69
|
/** Narrows an arbitrary module export to a branded functional tool for boot-time registration. */
|
|
47
70
|
export function isBrandedFunctionalTool(value) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-tool-ref.js","sourceRoot":"","sources":["../../src/ai-tool-ref.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAkB,MAAM,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;AAEvF;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAkB,MAAM,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;AA8B1F;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,MAAM,CAAC,OAAsB;IAC3C,OAAO,CAAsB,MAAS,EAAK,EAAE;QAC3C,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,gBAAgB,EAAE;YAC9C,KAAK,EAAE,OAAO;YACd,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,IAAI;SACnB,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC;AAED,
|
|
1
|
+
{"version":3,"file":"ai-tool-ref.js","sourceRoot":"","sources":["../../src/ai-tool-ref.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAkB,MAAM,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;AAEvF;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAkB,MAAM,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;AA8B1F;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,MAAM,CAAC,OAAsB;IAC3C,OAAO,CAAsB,MAAS,EAAK,EAAE;QAC3C,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,gBAAgB,EAAE;YAC9C,KAAK,EAAE,OAAO;YACd,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,IAAI;SACnB,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC;AAED,6FAA6F;AAC7F,SAAS,cAAc,CAAC,MAAe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