@agentier/core 0.1.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.
@@ -0,0 +1,86 @@
1
+ import type { ZodType } from 'zod';
2
+ import type { Message } from './message';
3
+ /**
4
+ * Contextual information provided to a tool's execute function at invocation time.
5
+ */
6
+ export interface ToolContext {
7
+ /** The unique identifier of the current tool call. */
8
+ callId: string;
9
+ /** An abort signal that is triggered when the agent loop is cancelled or times out. */
10
+ signal: AbortSignal;
11
+ /** The full conversation history up to and including the assistant message that triggered this call. */
12
+ messages: Message[];
13
+ }
14
+ /**
15
+ * A plain JSON Schema object describing tool parameters.
16
+ * Used as an alternative to Zod schemas when defining tools.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * const schema: JsonSchema = {
21
+ * type: 'object',
22
+ * properties: {
23
+ * city: { type: 'string', description: 'City name' },
24
+ * },
25
+ * required: ['city'],
26
+ * }
27
+ * ```
28
+ */
29
+ export interface JsonSchema {
30
+ /** Must be `'object'` for tool parameter schemas. */
31
+ type: 'object';
32
+ /** A map of property names to their JSON Schema definitions. */
33
+ properties: Record<string, unknown>;
34
+ /** An array of property names that are required. */
35
+ required?: string[];
36
+ /** Additional JSON Schema keywords. */
37
+ [key: string]: unknown;
38
+ }
39
+ /**
40
+ * The JSON representation of a tool sent to the model provider.
41
+ * This is the wire format that model APIs expect.
42
+ */
43
+ export interface ToolJsonSchema {
44
+ /** The tool name as it will appear to the model. */
45
+ name: string;
46
+ /** A human-readable description of what the tool does. */
47
+ description: string;
48
+ /** The JSON Schema describing the tool's accepted parameters. */
49
+ parameters: Record<string, unknown>;
50
+ }
51
+ /**
52
+ * Defines a tool that the agent can invoke during its reasoning loop.
53
+ *
54
+ * @typeParam TParams - The type of the validated parameters object passed to `execute`.
55
+ * @typeParam TResult - The type of the value returned by `execute`.
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * const weatherTool: Tool<{ city: string }, string> = {
60
+ * name: 'get_weather',
61
+ * description: 'Get the current weather for a city',
62
+ * parameters: z.object({ city: z.string() }),
63
+ * execute: async ({ city }) => `Sunny in ${city}`,
64
+ * }
65
+ * ```
66
+ */
67
+ export interface Tool<TParams = Record<string, unknown>, TResult = unknown> {
68
+ /** The unique name identifying this tool. */
69
+ name: string;
70
+ /** A description of what the tool does, shown to the model to guide tool selection. */
71
+ description: string;
72
+ /** A Zod schema or plain JSON Schema that defines and validates the tool's parameters. */
73
+ parameters: ZodType<TParams> | JsonSchema;
74
+ /**
75
+ * Executes the tool with validated parameters.
76
+ *
77
+ * @param params - The validated parameters parsed from the model's tool call arguments.
78
+ * @param context - Contextual information including the call ID, abort signal, and message history.
79
+ * @returns A promise resolving to the tool's result value.
80
+ */
81
+ execute: (params: TParams, context: ToolContext) => Promise<TResult>;
82
+ /** @internal Resolved JSON Schema representation, set by {@link defineTool} or lazily by the agent. */
83
+ _jsonSchema?: Record<string, unknown>;
84
+ /** @internal Whether {@link parameters} is a Zod schema (as opposed to a plain JSON Schema). */
85
+ _isZod?: boolean;
86
+ }
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@agentier/core",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/index.js",
10
+ "types": "./dist/index.d.ts"
11
+ }
12
+ },
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "scripts": {
17
+ "build": "bun build ./src/index.ts --outdir ./dist --target node",
18
+ "test": "bun test",
19
+ "typecheck": "tsc --noEmit"
20
+ },
21
+ "dependencies": {
22
+ "zod": "^3.23.0",
23
+ "zod-to-json-schema": "^3.23.0"
24
+ },
25
+ "devDependencies": {
26
+ "typescript": "^5.5.0",
27
+ "@types/bun": "latest"
28
+ }
29
+ }