@adonis-agora/agent 0.6.0 → 0.7.1
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 +47 -0
- package/dist/src/ai-tool-ref.d.ts +13 -3
- package/dist/src/ai-tool-ref.d.ts.map +1 -1
- package/dist/src/ai-tool-ref.js +33 -6
- 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,52 @@
|
|
|
1
1
|
# @adonis-agora/agent
|
|
2
2
|
|
|
3
|
+
## 0.7.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#21](https://github.com/DavideCarvalho/adonis-agent/pull/21) [`d02b26b`](https://github.com/DavideCarvalho/adonis-agent/commit/d02b26bea2acd8d6f7daac166116a6813d321a02) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Internal: simplify `readAiToolMeta` metadata resolution
|
|
8
|
+
|
|
9
|
+
Refactor the tool-metadata lookup so the two authoring mechanisms (`@AiTool`
|
|
10
|
+
decorator and `static tool`) and the two subjects (the value, its constructor)
|
|
11
|
+
are composed explicitly — `metaOn(target) ?? metaOn(ctor)` — instead of a flat
|
|
12
|
+
four-way fallback chain. No behavior or API change; discovery of both forms is
|
|
13
|
+
unchanged (mutation-proven).
|
|
14
|
+
|
|
15
|
+
## 0.7.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- [#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
|
|
20
|
+
|
|
21
|
+
A tool class can now declare its metadata with a `static tool = { name, kind, description, input, … }`
|
|
22
|
+
config instead of the `@AiTool({ … })` decorator — the same shape, mirroring
|
|
23
|
+
`@adonis-agora/durable`'s `static workflow`. Discovery, registration, and execution are identical;
|
|
24
|
+
`readAiToolMeta` now reads the static config when no decorator is present.
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import type {
|
|
28
|
+
AiToolCtx,
|
|
29
|
+
AiToolOptions,
|
|
30
|
+
ToolHandler,
|
|
31
|
+
} from "@adonis-agora/agent";
|
|
32
|
+
import { z } from "zod";
|
|
33
|
+
|
|
34
|
+
export default class GetWeather implements ToolHandler<{ city: string }> {
|
|
35
|
+
static tool = {
|
|
36
|
+
name: "getWeather",
|
|
37
|
+
kind: "read",
|
|
38
|
+
description: "Get the weather",
|
|
39
|
+
input: z.object({ city: z.string() }),
|
|
40
|
+
} satisfies AiToolOptions;
|
|
41
|
+
|
|
42
|
+
async execute(input: { city: string }, ctx: AiToolCtx) {
|
|
43
|
+
return { tempC: 21 };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The `@AiTool` decorator and the functional `defineTool(...)` forms are unchanged.
|
|
49
|
+
|
|
3
50
|
## 0.6.0
|
|
4
51
|
|
|
5
52
|
### 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,17 @@ 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:
|
|
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: each mechanism is tried on the value, then on its
|
|
62
|
+
* constructor (so an instance resolves the class's metadata).
|
|
63
|
+
*/
|
|
54
64
|
export declare function readAiToolMeta(target: unknown): AiToolMeta | undefined;
|
|
55
65
|
/** A tool expressed as data + handler (from {@link defineTool}), not an `@AiTool` class. */
|
|
56
66
|
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,EA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MtE;AAED,4FAA4F;AAC5F,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE,WAAW,CAAC;CACtB;AAED,oGAAoG;AACpG,MAAM,WAAW,qBAAsB,SAAQ,cAAc;IAC3D,QAAQ,CAAC,CAAC,gBAAgB,CAAC,EAAE,IAAI,CAAC;CACnC;AAED,kGAAkG;AAClG,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,qBAAqB,CAQtF;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,CAAC,GAAG,OAAO,EACpC,OAAO,EAAE,aAAa,EACtB,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,SAAS,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,GAChE,qBAAqB,CAcvB"}
|
package/dist/src/ai-tool-ref.js
CHANGED
|
@@ -31,17 +31,44 @@ export function AiTool(options) {
|
|
|
31
31
|
return target;
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
|
-
/** Read the
|
|
35
|
-
|
|
34
|
+
/** Read the `@AiTool` decorator's stamped {@link AI_TOOL_META_KEY} metadata off a value, if present. */
|
|
35
|
+
function decoratorMeta(target) {
|
|
36
36
|
if (target === null || (typeof target !== 'function' && typeof target !== 'object')) {
|
|
37
37
|
return undefined;
|
|
38
38
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
return target[AI_TOOL_META_KEY];
|
|
40
|
+
}
|
|
41
|
+
/** Read a class's tool metadata off its `static tool = { name, kind, … }` config, if any. */
|
|
42
|
+
function staticToolMeta(target) {
|
|
43
|
+
if (typeof target !== 'function')
|
|
44
|
+
return undefined;
|
|
45
|
+
const config = target.tool;
|
|
46
|
+
if (config && typeof config === 'object' && typeof config.name === 'string') {
|
|
47
|
+
return config;
|
|
48
|
+
}
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
/** Resolve either authoring mechanism — `@AiTool` decorator or `static tool` — from one value. */
|
|
52
|
+
function metaOn(target) {
|
|
53
|
+
return decoratorMeta(target) ?? staticToolMeta(target);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Read a tool class's {@link AiToolMeta}. Two authoring forms are supported:
|
|
57
|
+
*
|
|
58
|
+
* 1. The `@AiTool({ … })` decorator (stamps {@link AI_TOOL_META_KEY}).
|
|
59
|
+
* 2. A decorator-free `static tool = { name, kind, description, input, … }` config on the class — the
|
|
60
|
+
* same shape, mirroring `@adonis-agora/durable`'s `static workflow`. Preferred where you'd rather
|
|
61
|
+
* not rely on decorators.
|
|
62
|
+
*
|
|
63
|
+
* Accepts either the class itself or an instance: each mechanism is tried on the value, then on its
|
|
64
|
+
* constructor (so an instance resolves the class's metadata).
|
|
65
|
+
*/
|
|
66
|
+
export function readAiToolMeta(target) {
|
|
67
|
+
if (target === null || (typeof target !== 'function' && typeof target !== 'object')) {
|
|
68
|
+
return undefined;
|
|
42
69
|
}
|
|
43
70
|
const ctor = target.constructor;
|
|
44
|
-
return ctor
|
|
71
|
+
return metaOn(target) ?? metaOn(ctor);
|
|
45
72
|
}
|
|
46
73
|
/** Narrows an arbitrary module export to a branded functional tool for boot-time registration. */
|
|
47
74
|
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,MA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