@astropods/adapter-ai-sdk 0.5.1-next.9 → 0.6.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/README.md +52 -0
- package/dist/adapter.d.ts +6 -0
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +38 -4
- package/dist/adapter.js.map +1 -1
- package/dist/file-tools.d.ts +4 -0
- package/dist/file-tools.d.ts.map +1 -0
- package/dist/file-tools.js +39 -0
- package/dist/file-tools.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -95,6 +95,57 @@ serve(agent, {
|
|
|
95
95
|
|
|
96
96
|
An agent without call options needs no `callOptions`.
|
|
97
97
|
|
|
98
|
+
## The chosen model
|
|
99
|
+
|
|
100
|
+
Pass the models a chat user can pick from as `models`; the first is the default. With two or more, the web chat shows a model picker, and `StreamOptions.model` is the pick. It is undefined when no model was picked, as on a Slack turn. Pass it through `callOptions`, and return the model from `prepareCall`:
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
const MODELS = ["claude-sonnet-4-6", "claude-opus-4-7"];
|
|
104
|
+
|
|
105
|
+
const agent = new ToolLoopAgent({
|
|
106
|
+
model: gateway.chat(MODELS[0]),
|
|
107
|
+
callOptionsSchema: z.object({ model: z.string().optional() }),
|
|
108
|
+
prepareCall: ({ options, ...rest }) => ({
|
|
109
|
+
...rest,
|
|
110
|
+
model: options.model ? gateway.chat(options.model) : rest.model,
|
|
111
|
+
}),
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
serve(agent, {
|
|
115
|
+
name: "My Agent",
|
|
116
|
+
models: MODELS,
|
|
117
|
+
callOptions: (turn) => ({ model: turn.model }),
|
|
118
|
+
});
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Files
|
|
122
|
+
|
|
123
|
+
The adapter appends each attached file's name and path to the turn's text. `fileTools()` gives the model tools that open those paths. They work on files of any size without loading a file into the prompt:
|
|
124
|
+
|
|
125
|
+
| Tool | What it does |
|
|
126
|
+
|------|--------------|
|
|
127
|
+
| `inspect_file` | Reports a file's kind (PDF, DOCX, XLSX, text), its size, its text length, and for a table each sheet's columns and row count. |
|
|
128
|
+
| `read_file` | Returns one 20,000-character page of a PDF, DOCX, or text file, with `nextOffset` for the next page. |
|
|
129
|
+
| `read_table` | Returns one page of rows from a CSV or XLSX file, 100 by default, with `nextOffset` for the next page. |
|
|
130
|
+
| `create_file` | Writes a text file to the files dir, attaches it to the reply with `attachFile`, and returns its name and the path to read it back. |
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
import { ToolLoopAgent } from "ai";
|
|
134
|
+
import { fileTools, serve } from "@astropods/adapter-ai-sdk";
|
|
135
|
+
|
|
136
|
+
const agent = new ToolLoopAgent({
|
|
137
|
+
model,
|
|
138
|
+
instructions: "Answer questions about the files the user attaches.",
|
|
139
|
+
tools: { ...fileTools() },
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
serve(agent, { supportsFiles: true });
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
The tools open only the files attached to or created in the current conversation, so a follow-up question can go back to an earlier file. The list is saved with the files, so it lasts through a restart. The tools return a file's contents and do no analysis. For counts or totals over a large table, give the agent a query engine such as DuckDB on the attachment's `path`, as the adapter-core README describes.
|
|
146
|
+
|
|
147
|
+
An image the message carries inline (`StreamOptions.images`) reaches the model with the turn, as in the Mastra adapter. The conversation history keeps only the image's name, because one image's data URI could fill `maxHistoryBytes`, so the model sees the image on that turn only. A larger image, or one from earlier in a Slack thread, arrives as a file in `attachments`, which the file tools cannot view.
|
|
148
|
+
|
|
98
149
|
## API
|
|
99
150
|
|
|
100
151
|
### `serve(agent, options?)`
|
|
@@ -107,6 +158,7 @@ Connects the agent to the messaging service.
|
|
|
107
158
|
| `instructions` | `string` | Optional. System prompt shown in the playground when provided. |
|
|
108
159
|
| `callOptions` | `(options: StreamOptions) => CALL_OPTIONS` | Optional. Builds the agent's call options for each turn. See [The sender's name](#the-senders-name). |
|
|
109
160
|
| `memory` | `boolean` | Send each conversation's earlier turns to the model. Defaults to `true`; `false` sends only `prompt`. |
|
|
161
|
+
| `supportsFiles` | `boolean` | Declare that the agent reads attached files, which turns on web chat uploads. Defaults to `false`. Slack sends files either way. |
|
|
110
162
|
| `maxTurns` | `number` | Turns of history each conversation keeps. Defaults to `20`; `0` turns history off. |
|
|
111
163
|
| `maxHistoryBytes` | `number` | Serialized size a conversation's history may reach. Defaults to 256 KiB, about 64K tokens. |
|
|
112
164
|
| `maxConversations` | `number` | Conversations kept in memory; the least recently used is forgotten first. Defaults to `200`. |
|
package/dist/adapter.d.ts
CHANGED
|
@@ -10,8 +10,12 @@ export interface AISDKAdapterOptions<CALL_OPTIONS = never> {
|
|
|
10
10
|
* agent reads per-turn context such as `userName`.
|
|
11
11
|
*/
|
|
12
12
|
callOptions?: (options: StreamOptions) => CALL_OPTIONS;
|
|
13
|
+
/** Models a chat user can pick from, the first being the default. The pick arrives as `StreamOptions.model`. */
|
|
14
|
+
models?: string[];
|
|
13
15
|
/** Send each conversation's earlier turns to the model as `messages`. Defaults to `true`; `false` sends only `prompt`. */
|
|
14
16
|
memory?: boolean;
|
|
17
|
+
/** Declare that the agent reads attached files, which enables web chat uploads. Defaults to `false`. */
|
|
18
|
+
supportsFiles?: boolean;
|
|
15
19
|
/** Turns of history each conversation keeps. Defaults to 20. */
|
|
16
20
|
maxTurns?: number;
|
|
17
21
|
/** Serialized size a conversation's history may reach, in bytes. Defaults to 256 KiB, about 64K tokens. */
|
|
@@ -23,8 +27,10 @@ export declare class AISDKAdapter<TOOLS extends ToolSet = ToolSet, CALL_OPTIONS
|
|
|
23
27
|
private agent;
|
|
24
28
|
readonly name: string;
|
|
25
29
|
private readonly instructions;
|
|
30
|
+
private readonly supportsFiles;
|
|
26
31
|
private readonly callOptions?;
|
|
27
32
|
private readonly history;
|
|
33
|
+
private readonly models;
|
|
28
34
|
constructor(agent: Agent<CALL_OPTIONS, TOOLS, any>, options?: AISDKAdapterOptions<CALL_OPTIONS>);
|
|
29
35
|
stream(prompt: string, hooks: StreamHooks, options: StreamOptions): Promise<void>;
|
|
30
36
|
getConfig(): AgentConfig;
|
package/dist/adapter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAgB,OAAO,EAAE,MAAM,IAAI,CAAC;AAEvD,OAAO,KAAK,EACV,YAAY,EACZ,WAAW,EACX,WAAW,EACX,aAAa,EACd,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAgB,OAAO,EAAE,MAAM,IAAI,CAAC;AAEvD,OAAO,KAAK,EACV,YAAY,EACZ,WAAW,EACX,WAAW,EACX,aAAa,EACd,MAAM,yBAAyB,CAAC;AAKjC,MAAM,WAAW,mBAAmB,CAAC,YAAY,GAAG,KAAK;IACvD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,4GAA4G;IAC5G,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,YAAY,CAAC;IACvD,gHAAgH;IAChH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,0HAA0H;IAC1H,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,wGAAwG;IACxG,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,gEAAgE;IAChE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2GAA2G;IAC3G,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,kGAAkG;IAClG,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,qBAAa,YAAY,CAAC,KAAK,SAAS,OAAO,GAAG,OAAO,EAAE,YAAY,GAAG,KAAK,CAC7E,YAAW,YAAY;IAUrB,OAAO,CAAC,KAAK;IARf,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAU;IACxC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,CAA2C;IACxE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkC;IAC1D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuB;gBAGpC,KAAK,EAAE,KAAK,CAAC,YAAY,EAAE,KAAK,EAAE,GAAG,CAAC,EAC9C,OAAO,GAAE,mBAAmB,CAAC,YAAY,CAAM;IAe3C,MAAM,CACV,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,WAAW,EAClB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,IAAI,CAAC;IAoIhB,SAAS,IAAI,WAAW;CA0BzB"}
|
package/dist/adapter.js
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
|
+
import { attachmentNote } from "@astropods/adapter-core/files";
|
|
1
2
|
import { ConversationHistory } from "./history";
|
|
2
3
|
export class AISDKAdapter {
|
|
3
4
|
agent;
|
|
4
5
|
name;
|
|
5
6
|
instructions;
|
|
7
|
+
supportsFiles;
|
|
6
8
|
callOptions;
|
|
7
9
|
history;
|
|
10
|
+
models;
|
|
8
11
|
constructor(agent, options = {}) {
|
|
9
12
|
this.agent = agent;
|
|
10
13
|
this.name = options.name ?? agent.id ?? "AI SDK Agent";
|
|
11
14
|
this.instructions = options.instructions ?? "";
|
|
15
|
+
this.supportsFiles = options.supportsFiles ?? false;
|
|
12
16
|
this.callOptions = options.callOptions;
|
|
17
|
+
this.models = options.models;
|
|
13
18
|
const history = new ConversationHistory({
|
|
14
19
|
maxTurns: options.maxTurns ?? 20,
|
|
15
20
|
maxHistoryBytes: options.maxHistoryBytes ?? 256 * 1024,
|
|
@@ -23,13 +28,40 @@ export class AISDKAdapter {
|
|
|
23
28
|
if (history && options.history) {
|
|
24
29
|
history.replace(conversationId, options.history.messages.map(({ role, content }) => ({ role, content })));
|
|
25
30
|
}
|
|
26
|
-
const
|
|
31
|
+
const images = options.images ?? [];
|
|
32
|
+
const note = attachmentNote(options.attachments ?? [], images);
|
|
33
|
+
const text = note ? (prompt ? `${prompt}\n\n${note}` : note) : prompt;
|
|
34
|
+
const turn = images.length === 0
|
|
35
|
+
? { role: "user", content: text }
|
|
36
|
+
: {
|
|
37
|
+
role: "user",
|
|
38
|
+
content: [
|
|
39
|
+
...(text ? [{ type: "text", text }] : []),
|
|
40
|
+
...images.map((img) => ({
|
|
41
|
+
type: "image",
|
|
42
|
+
image: img.url,
|
|
43
|
+
// Without a mediaType the model reads the bytes as image/jpeg.
|
|
44
|
+
mediaType: img.mimeType ?? /^data:([^;,]+)[;,]/.exec(img.url)?.[1],
|
|
45
|
+
})),
|
|
46
|
+
],
|
|
47
|
+
};
|
|
48
|
+
// One image's data URI can fill maxHistoryBytes, so history keeps only the names.
|
|
49
|
+
const remembered = images.length === 0
|
|
50
|
+
? turn
|
|
51
|
+
: {
|
|
52
|
+
role: "user",
|
|
53
|
+
content: [text, `(Attached images: ${images.map((img) => img.name).join(", ")})`]
|
|
54
|
+
.filter(Boolean)
|
|
55
|
+
.join("\n\n"),
|
|
56
|
+
};
|
|
27
57
|
let failed = false;
|
|
28
58
|
let aborted = false;
|
|
29
59
|
try {
|
|
30
60
|
const input = history
|
|
31
|
-
? { messages: [...history.messages(conversationId),
|
|
32
|
-
:
|
|
61
|
+
? { messages: [...history.messages(conversationId), turn], abortSignal: options.signal }
|
|
62
|
+
: images.length > 0
|
|
63
|
+
? { messages: [turn], abortSignal: options.signal }
|
|
64
|
+
: { prompt: text, abortSignal: options.signal };
|
|
33
65
|
// `options` is required or forbidden depending on CALL_OPTIONS, which a
|
|
34
66
|
// generic class cannot narrow.
|
|
35
67
|
const result = await this.agent.stream((this.callOptions ? { ...input, options: this.callOptions(options) } : input));
|
|
@@ -92,7 +124,7 @@ export class AISDKAdapter {
|
|
|
92
124
|
history.shrink(conversationId);
|
|
93
125
|
return;
|
|
94
126
|
}
|
|
95
|
-
history.append(conversationId, [
|
|
127
|
+
history.append(conversationId, [remembered, ...(await turnMessages)]);
|
|
96
128
|
}
|
|
97
129
|
catch (err) {
|
|
98
130
|
if (history && !options.signal?.aborted)
|
|
@@ -115,6 +147,8 @@ export class AISDKAdapter {
|
|
|
115
147
|
tools: toolConfigs,
|
|
116
148
|
// With memory off the agent keeps its own, which the adapter cannot reset.
|
|
117
149
|
supportsHistory: this.history !== undefined,
|
|
150
|
+
supportsFiles: this.supportsFiles,
|
|
151
|
+
...(this.models ? { models: this.models } : {}),
|
|
118
152
|
};
|
|
119
153
|
}
|
|
120
154
|
}
|
package/dist/adapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AA0BhD,MAAM,OAAO,YAAY;IAWb;IARD,IAAI,CAAS;IACL,YAAY,CAAS;IACrB,aAAa,CAAU;IACvB,WAAW,CAA4C;IACvD,OAAO,CAAkC;IACzC,MAAM,CAAuB;IAE9C,YACU,KAAsC,EAC9C,UAA6C,EAAE;QADvC,UAAK,GAAL,KAAK,CAAiC;QAG9C,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,KAAK,CAAC,EAAE,IAAI,cAAc,C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C,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAChD,CAAC;IACJ,CAAC;CACF;AAED,wGAAwG;AACxG,KAAK,UAAU,gBAAgB,CAAC,MAAc;IAC5C,IAAI,kBAAkB,IAAI,MAAM,EAAE,CAAC;QACjC,OAAO,MAAO,MAA4D,CAAC,gBAAgB,CAAC;IAC9F,CAAC;IACD,OAAO,CAAC,MAAO,MAAkE,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC;AACvG,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type Tool } from "ai";
|
|
2
|
+
/** File tools that never load a whole file into the prompt: `tools: { ...fileTools() }`. */
|
|
3
|
+
export declare function fileTools(): Record<"inspect_file" | "read_file" | "read_table" | "create_file", Tool>;
|
|
4
|
+
//# sourceMappingURL=file-tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-tools.d.ts","sourceRoot":"","sources":["../src/file-tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,IAAI,EAAE,MAAM,IAAI,CAAC;AAUrC,4FAA4F;AAC5F,wBAAgB,SAAS,IAAI,MAAM,CAAC,cAAc,GAAG,WAAW,GAAG,YAAY,GAAG,aAAa,EAAE,IAAI,CAAC,CA2BrG"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { tool } from "ai";
|
|
2
|
+
import { FILE_TOOL_DESCRIPTIONS, createFile, inspectFile, readFilePage, readTable, } from "@astropods/adapter-core/files";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
/** File tools that never load a whole file into the prompt: `tools: { ...fileTools() }`. */
|
|
5
|
+
export function fileTools() {
|
|
6
|
+
return {
|
|
7
|
+
inspect_file: tool({
|
|
8
|
+
description: FILE_TOOL_DESCRIPTIONS.inspect_file,
|
|
9
|
+
inputSchema: z.object({ path: z.string() }),
|
|
10
|
+
execute: ({ path }) => inspectFile(path),
|
|
11
|
+
}),
|
|
12
|
+
read_file: tool({
|
|
13
|
+
description: FILE_TOOL_DESCRIPTIONS.read_file,
|
|
14
|
+
inputSchema: z.object({ path: z.string(), offset: z.number().int().min(0).optional() }),
|
|
15
|
+
execute: ({ path, offset }) => readFilePage(path, offset),
|
|
16
|
+
}),
|
|
17
|
+
read_table: tool({
|
|
18
|
+
description: FILE_TOOL_DESCRIPTIONS.read_table,
|
|
19
|
+
inputSchema: tablePageSchema,
|
|
20
|
+
execute: ({ path, ...page }) => readTable(path, page),
|
|
21
|
+
}),
|
|
22
|
+
create_file: tool({
|
|
23
|
+
description: FILE_TOOL_DESCRIPTIONS.create_file,
|
|
24
|
+
inputSchema: z.object({
|
|
25
|
+
name: z.string().describe("File name with extension, no directories"),
|
|
26
|
+
content: z.string(),
|
|
27
|
+
mimeType: z.string().optional(),
|
|
28
|
+
}),
|
|
29
|
+
execute: ({ name, content, mimeType }) => createFile(name, content, mimeType),
|
|
30
|
+
}),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const tablePageSchema = z.object({
|
|
34
|
+
path: z.string(),
|
|
35
|
+
sheet: z.string().optional().describe("XLSX sheet name; defaults to the first sheet"),
|
|
36
|
+
offset: z.number().int().min(0).optional().describe("Data row to start at; 0 is the first row after the header"),
|
|
37
|
+
limit: z.number().int().min(1).max(500).optional(),
|
|
38
|
+
});
|
|
39
|
+
//# sourceMappingURL=file-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-tools.js","sourceRoot":"","sources":["../src/file-tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAa,MAAM,IAAI,CAAC;AACrC,OAAO,EACL,sBAAsB,EACtB,UAAU,EACV,WAAW,EACX,YAAY,EACZ,SAAS,GACV,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,4FAA4F;AAC5F,MAAM,UAAU,SAAS;IACvB,OA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EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC;SAC9E,CAAC;KACH,CAAC;AACJ,CAAC;AAED,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,8CAA8C,CAAC;IACrF,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,2DAA2D,CAAC;IAChH,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE;CACnD,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,5 +4,6 @@ import type { AISDKAdapterOptions } from "./adapter";
|
|
|
4
4
|
export { AISDKAdapter } from "./adapter";
|
|
5
5
|
export type { AISDKAdapterOptions } from "./adapter";
|
|
6
6
|
export { astroTelemetry } from "./telemetry";
|
|
7
|
+
export { fileTools } from "./file-tools";
|
|
7
8
|
export declare function serve<TOOLS extends ToolSet = ToolSet, CALL_OPTIONS = never>(agent: Agent<CALL_OPTIONS, TOOLS, any>, options?: AISDKAdapterOptions<CALL_OPTIONS> & ServeOptions): void;
|
|
8
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAEzC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAE5D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAErD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,YAAY,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAEzC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAE5D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAErD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,YAAY,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,wBAAgB,KAAK,CAAC,KAAK,SAAS,OAAO,GAAG,OAAO,EAAE,YAAY,GAAG,KAAK,EACzE,KAAK,EAAE,KAAK,CAAC,YAAY,EAAE,KAAK,EAAE,GAAG,CAAC,EACtC,OAAO,GAAE,mBAAmB,CAAC,YAAY,CAAC,GAAG,YAAiB,GAC7D,IAAI,CAGN"}
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import { serve as serveAdapter } from "@astropods/adapter-core";
|
|
|
2
2
|
import { AISDKAdapter } from "./adapter";
|
|
3
3
|
export { AISDKAdapter } from "./adapter";
|
|
4
4
|
export { astroTelemetry } from "./telemetry";
|
|
5
|
+
export { fileTools } from "./file-tools";
|
|
5
6
|
export function serve(agent, options = {}) {
|
|
6
7
|
const adapter = new AISDKAdapter(agent, options);
|
|
7
8
|
serveAdapter(adapter, options);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEhE,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAGzC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEhE,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAGzC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,MAAM,UAAU,KAAK,CACnB,KAAsC,EACtC,UAA4D,EAAE;IAE9D,MAAM,OAAO,GAAG,IAAI,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACjD,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AACjC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astropods/adapter-ai-sdk",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.6.0",
|
|
5
5
|
"description": "Vercel AI SDK adapter for the Astro messaging service. Wraps an Agent and auto-wires OpenTelemetry tracing.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.js",
|
|
@@ -32,12 +32,13 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@ai-sdk/otel": "^1.0.153",
|
|
35
|
-
"@astropods/adapter-core": "0.
|
|
35
|
+
"@astropods/adapter-core": "0.15.0",
|
|
36
36
|
"@astropods/messaging": "latest",
|
|
37
37
|
"@opentelemetry/api": "^1.9.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"ai": ">=6.0.0 <8.0.0"
|
|
40
|
+
"ai": ">=6.0.0 <8.0.0",
|
|
41
|
+
"zod": "^3.25.76 || ^4.1.8"
|
|
41
42
|
},
|
|
42
43
|
"peerDependenciesMeta": {
|
|
43
44
|
"ai": {
|
|
@@ -50,5 +51,5 @@
|
|
|
50
51
|
"typescript": "^5.3.0",
|
|
51
52
|
"zod": "^4.3.6"
|
|
52
53
|
},
|
|
53
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "cebb6c7ca422ec2336323d7ba5ffc108891db2c1"
|
|
54
55
|
}
|