@terminaluse/vercel-ai-sdk-provider 0.1.1 → 0.3.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 +51 -0
- package/dist/index.d.mts +21 -1
- package/dist/index.mjs +27 -32
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -36,9 +36,60 @@ const result = await streamText({
|
|
|
36
36
|
| Option | Type | Description |
|
|
37
37
|
|--------|------|-------------|
|
|
38
38
|
| `taskId` | `string` | Task ID to send messages to (required) |
|
|
39
|
+
| `event` | `object` | Optional explicit task event override (`content`, `persistMessage`, `idempotencyKey`) |
|
|
39
40
|
|
|
40
41
|
Tasks must be created separately using the [`@terminaluse/sdk`](https://www.npmjs.com/package/@terminaluse/sdk).
|
|
41
42
|
|
|
43
|
+
### Sending data events
|
|
44
|
+
|
|
45
|
+
By default, the provider sends a text event derived from the last prompt message.
|
|
46
|
+
If you need to send a structured task event (for example, AskUserQuestion answers),
|
|
47
|
+
pass `providerOptions.terminaluse.event`:
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
await streamText({
|
|
51
|
+
model: terminaluse.agent('namespace/agent-name'),
|
|
52
|
+
messages: [],
|
|
53
|
+
providerOptions: {
|
|
54
|
+
terminaluse: {
|
|
55
|
+
taskId,
|
|
56
|
+
event: {
|
|
57
|
+
content: {
|
|
58
|
+
type: 'data',
|
|
59
|
+
data: {
|
|
60
|
+
type: 'ask_user_answer',
|
|
61
|
+
answers: { 'Question?': 'Answer' },
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
persistMessage: false,
|
|
65
|
+
idempotencyKey: 'optional-idempotency-key',
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Conversation Continuity
|
|
73
|
+
|
|
74
|
+
To maintain conversation history across multiple interactions, create a task once
|
|
75
|
+
and reuse its ID for all subsequent messages:
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
import { TerminalUseClient } from '@terminaluse/sdk';
|
|
79
|
+
|
|
80
|
+
// 1. Create task once (at conversation start)
|
|
81
|
+
const client = new TerminalUseClient({ token: process.env.TERMINALUSE_API_KEY! });
|
|
82
|
+
const task = await client.tasks.create({ agent_name: 'namespace/my-agent' });
|
|
83
|
+
const taskId = task.id; // Store this for the session
|
|
84
|
+
|
|
85
|
+
// 2. Send messages to the same task
|
|
86
|
+
const result = await streamText({
|
|
87
|
+
model: terminaluse.agent('namespace/my-agent'),
|
|
88
|
+
messages,
|
|
89
|
+
providerOptions: { terminaluse: { taskId } },
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
42
93
|
## Requirements
|
|
43
94
|
|
|
44
95
|
- Node.js 18+
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TerminalUse } from "@terminaluse/sdk";
|
|
1
2
|
import { LanguageModel } from "ai";
|
|
2
3
|
|
|
3
4
|
//#region src/provider.d.ts
|
|
@@ -18,6 +19,25 @@ interface TerminalUseProvider {
|
|
|
18
19
|
interface TerminalUseProviderOptions {
|
|
19
20
|
/** Task ID to send messages to (required) */
|
|
20
21
|
taskId: string;
|
|
22
|
+
/**
|
|
23
|
+
* Optional override for the outbound task event. If omitted, provider sends
|
|
24
|
+
* a text event derived from the latest prompt message (default behavior).
|
|
25
|
+
*/
|
|
26
|
+
event?: TerminalUseProviderTaskEventOptions;
|
|
27
|
+
}
|
|
28
|
+
interface TerminalUseProviderTaskEventOptions {
|
|
29
|
+
/**
|
|
30
|
+
* Explicit event content to send. Supports text and data task events.
|
|
31
|
+
*/
|
|
32
|
+
content: NonNullable<TerminalUse.CreateTaskEventRequest['content']>;
|
|
33
|
+
/**
|
|
34
|
+
* Whether TerminalUse should persist this event as a message.
|
|
35
|
+
*/
|
|
36
|
+
persistMessage?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Optional idempotency key for retry-safe event delivery.
|
|
39
|
+
*/
|
|
40
|
+
idempotencyKey?: string;
|
|
21
41
|
}
|
|
22
42
|
/**
|
|
23
43
|
* Creates a custom AI SDK provider for TerminalUse agents.
|
|
@@ -48,4 +68,4 @@ interface TerminalUseProviderOptions {
|
|
|
48
68
|
*/
|
|
49
69
|
declare function createTerminalUseProvider(config: TerminalUseProviderConfig): TerminalUseProvider;
|
|
50
70
|
//#endregion
|
|
51
|
-
export { type TerminalUseProvider, type TerminalUseProviderConfig, type TerminalUseProviderOptions, createTerminalUseProvider };
|
|
71
|
+
export { type TerminalUseProvider, type TerminalUseProviderConfig, type TerminalUseProviderOptions, type TerminalUseProviderTaskEventOptions, createTerminalUseProvider };
|
package/dist/index.mjs
CHANGED
|
@@ -1,22 +1,8 @@
|
|
|
1
|
+
import { TerminalUseClient } from "@terminaluse/sdk";
|
|
1
2
|
import { UnsupportedFunctionalityError } from "ai";
|
|
2
3
|
import { createEventSourceResponseHandler, getFromApi } from "@ai-sdk/provider-utils";
|
|
3
4
|
import { z } from "zod";
|
|
4
5
|
|
|
5
|
-
//#region src/http.ts
|
|
6
|
-
/**
|
|
7
|
-
* Fetch wrapper with TerminalUse authentication headers.
|
|
8
|
-
*/
|
|
9
|
-
async function terminaluseFetch(config, path, options = {}) {
|
|
10
|
-
const headers = new Headers(options.headers);
|
|
11
|
-
if (config.apiKey) headers.set("Authorization", `Bearer ${config.apiKey}`);
|
|
12
|
-
if (!headers.has("Content-Type") && options.body) headers.set("Content-Type", "application/json");
|
|
13
|
-
return fetch(`${config.baseURL}${path}`, {
|
|
14
|
-
...options,
|
|
15
|
-
headers
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
//#endregion
|
|
20
6
|
//#region src/ndjson-stream.ts
|
|
21
7
|
/**
|
|
22
8
|
* SSE streaming utility for TerminalUse task events.
|
|
@@ -366,6 +352,10 @@ function createTerminalUseProvider(config) {
|
|
|
366
352
|
baseURL: config.baseURL,
|
|
367
353
|
apiKey: config.apiKey
|
|
368
354
|
};
|
|
355
|
+
const client = new TerminalUseClient({
|
|
356
|
+
environment: config.baseURL,
|
|
357
|
+
bearerAuth: { token: config.apiKey }
|
|
358
|
+
});
|
|
369
359
|
return { agent(agentName) {
|
|
370
360
|
return {
|
|
371
361
|
specificationVersion: "v3",
|
|
@@ -383,24 +373,29 @@ function createTerminalUseProvider(config) {
|
|
|
383
373
|
const tuOptions = providerOptions?.terminaluse;
|
|
384
374
|
if (!tuOptions?.taskId) throw new Error("taskId is required. Create a task via /api/tasks first.");
|
|
385
375
|
const { taskId } = tuOptions;
|
|
386
|
-
const
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
if (
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
376
|
+
const explicitEvent = tuOptions.event;
|
|
377
|
+
const defaultEventContent = (() => {
|
|
378
|
+
const userContent = prompt.at(-1)?.content;
|
|
379
|
+
let textContent;
|
|
380
|
+
if (Array.isArray(userContent)) {
|
|
381
|
+
const textPart = userContent.find((c) => c.type === "text");
|
|
382
|
+
if (textPart && textPart.type === "text") textContent = textPart.text;
|
|
383
|
+
} else if (typeof userContent === "string") textContent = userContent;
|
|
384
|
+
return {
|
|
395
385
|
type: "text",
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
386
|
+
text: textContent || ""
|
|
387
|
+
};
|
|
388
|
+
})();
|
|
389
|
+
const requestBody = {
|
|
390
|
+
task_id: taskId,
|
|
391
|
+
content: explicitEvent?.content ?? defaultEventContent,
|
|
392
|
+
...explicitEvent?.idempotencyKey ? { idempotency_key: explicitEvent.idempotencyKey } : {},
|
|
393
|
+
...typeof explicitEvent?.persistMessage === "boolean" ? { persist_message: explicitEvent.persistMessage } : {}
|
|
394
|
+
};
|
|
395
|
+
try {
|
|
396
|
+
await client.tasks.sendEvent(requestBody);
|
|
397
|
+
} catch (error) {
|
|
398
|
+
throw new Error(`Failed to send message: ${error instanceof Error ? error.message : String(error)}`);
|
|
404
399
|
}
|
|
405
400
|
return { stream: createTerminalUseTransformStream(tuConfig, taskId, abortSignal) };
|
|
406
401
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@terminaluse/vercel-ai-sdk-provider",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Vercel AI SDK provider for TerminalUse agents",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -31,11 +31,13 @@
|
|
|
31
31
|
"lint": "biome lint .",
|
|
32
32
|
"format": "biome format --write .",
|
|
33
33
|
"check": "biome check --write .",
|
|
34
|
-
"
|
|
34
|
+
"check:publish-manifest": "node ./scripts/check-publish-manifest.mjs",
|
|
35
|
+
"prepublishOnly": "bun run check:publish-manifest && bun run build"
|
|
35
36
|
},
|
|
36
37
|
"dependencies": {
|
|
37
38
|
"@ai-sdk/provider": "^3.0.0",
|
|
38
39
|
"@ai-sdk/provider-utils": "^4.0.0",
|
|
40
|
+
"@terminaluse/sdk": "^0.7.0",
|
|
39
41
|
"zod": "^3.24.0"
|
|
40
42
|
},
|
|
41
43
|
"peerDependencies": {
|