@witqq/agent-sdk 0.5.1 → 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 +18 -6
- package/dist/backends/claude.cjs +38 -35
- package/dist/backends/claude.cjs.map +1 -1
- package/dist/backends/claude.d.cts +1 -1
- package/dist/backends/claude.d.ts +1 -1
- package/dist/backends/claude.js +38 -35
- package/dist/backends/claude.js.map +1 -1
- package/dist/backends/copilot.cjs +35 -6
- package/dist/backends/copilot.cjs.map +1 -1
- package/dist/backends/copilot.d.cts +3 -3
- package/dist/backends/copilot.d.ts +3 -3
- package/dist/backends/copilot.js +35 -6
- package/dist/backends/copilot.js.map +1 -1
- package/dist/backends/vercel-ai.cjs +49 -26
- package/dist/backends/vercel-ai.cjs.map +1 -1
- package/dist/backends/vercel-ai.d.cts +65 -23
- package/dist/backends/vercel-ai.d.ts +65 -23
- package/dist/backends/vercel-ai.js +49 -26
- package/dist/backends/vercel-ai.js.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js.map +1 -1
- package/dist/{types-CQEyww7V.d.cts → types-BvwNzZCj.d.cts} +4 -0
- package/dist/{types-CQEyww7V.d.ts → types-BvwNzZCj.d.ts} +4 -0
- package/package.json +1 -1
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import { V as VercelAIBackendOptions, I as IAgentService } from '../types-
|
|
1
|
+
import { V as VercelAIBackendOptions, I as IAgentService } from '../types-BvwNzZCj.js';
|
|
2
2
|
import 'zod';
|
|
3
3
|
|
|
4
4
|
/** @internal Vercel AI SDK tool result */
|
|
5
5
|
interface SDKToolDefinition {
|
|
6
6
|
description: string;
|
|
7
|
-
|
|
8
|
-
execute?: (
|
|
9
|
-
needsApproval?: boolean | ((
|
|
7
|
+
inputSchema: unknown;
|
|
8
|
+
execute?: (input: unknown, options: unknown) => Promise<unknown>;
|
|
9
|
+
needsApproval?: boolean | ((input: unknown, options: unknown) => Promise<boolean>);
|
|
10
10
|
}
|
|
11
|
-
/** @internal Vercel AI SDK generateText result */
|
|
11
|
+
/** @internal Vercel AI SDK v6 generateText result */
|
|
12
12
|
interface SDKGenerateTextResult {
|
|
13
13
|
text: string;
|
|
14
14
|
toolCalls: Array<{
|
|
15
15
|
toolCallId: string;
|
|
16
16
|
toolName: string;
|
|
17
|
-
|
|
17
|
+
input: unknown;
|
|
18
18
|
}>;
|
|
19
19
|
toolResults: Array<{
|
|
20
20
|
toolCallId: string;
|
|
21
21
|
toolName: string;
|
|
22
|
-
|
|
22
|
+
output: unknown;
|
|
23
23
|
}>;
|
|
24
24
|
steps: Array<{
|
|
25
25
|
text: string;
|
|
26
26
|
toolCalls: Array<{
|
|
27
27
|
toolCallId: string;
|
|
28
28
|
toolName: string;
|
|
29
|
-
|
|
29
|
+
input: unknown;
|
|
30
30
|
}>;
|
|
31
31
|
toolResults: Array<{
|
|
32
32
|
toolCallId: string;
|
|
33
33
|
toolName: string;
|
|
34
|
-
|
|
34
|
+
output: unknown;
|
|
35
35
|
}>;
|
|
36
36
|
usage: {
|
|
37
37
|
inputTokens?: number;
|
|
@@ -45,12 +45,12 @@ interface SDKGenerateTextResult {
|
|
|
45
45
|
};
|
|
46
46
|
finishReason: string;
|
|
47
47
|
response: {
|
|
48
|
-
messages:
|
|
48
|
+
messages: unknown[];
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
51
|
/** @internal Vercel AI SDK generateObject result */
|
|
52
52
|
interface SDKGenerateObjectResult {
|
|
53
|
-
object:
|
|
53
|
+
object: unknown;
|
|
54
54
|
usage: {
|
|
55
55
|
inputTokens?: number;
|
|
56
56
|
outputTokens?: number;
|
|
@@ -65,24 +65,66 @@ interface SDKStreamTextResult {
|
|
|
65
65
|
}>;
|
|
66
66
|
text: PromiseLike<string>;
|
|
67
67
|
}
|
|
68
|
-
/** @internal Vercel AI SDK stream part union */
|
|
69
|
-
|
|
68
|
+
/** @internal Vercel AI SDK v6 stream part union */
|
|
69
|
+
type SDKStreamPart = {
|
|
70
|
+
type: "text-delta";
|
|
71
|
+
text: string;
|
|
72
|
+
} | {
|
|
73
|
+
type: "tool-call";
|
|
74
|
+
toolCallId: string;
|
|
75
|
+
toolName: string;
|
|
76
|
+
input: unknown;
|
|
77
|
+
} | {
|
|
78
|
+
type: "tool-result";
|
|
79
|
+
toolCallId: string;
|
|
80
|
+
toolName: string;
|
|
81
|
+
output: unknown;
|
|
82
|
+
} | {
|
|
83
|
+
type: "tool-error";
|
|
84
|
+
toolCallId: string;
|
|
85
|
+
toolName: string;
|
|
86
|
+
error: unknown;
|
|
87
|
+
} | {
|
|
88
|
+
type: "reasoning-start";
|
|
89
|
+
} | {
|
|
90
|
+
type: "reasoning-end";
|
|
91
|
+
} | {
|
|
92
|
+
type: "reasoning-delta";
|
|
93
|
+
text: string;
|
|
94
|
+
} | {
|
|
95
|
+
type: "finish-step";
|
|
96
|
+
usage: {
|
|
97
|
+
inputTokens?: number;
|
|
98
|
+
outputTokens?: number;
|
|
99
|
+
};
|
|
100
|
+
finishReason: string;
|
|
101
|
+
} | {
|
|
102
|
+
type: "finish";
|
|
103
|
+
finishReason: string;
|
|
104
|
+
totalUsage: {
|
|
105
|
+
inputTokens?: number;
|
|
106
|
+
outputTokens?: number;
|
|
107
|
+
};
|
|
108
|
+
} | {
|
|
109
|
+
type: "error";
|
|
110
|
+
error: unknown;
|
|
111
|
+
} | {
|
|
70
112
|
type: string;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
type SDKLanguageModel = any;
|
|
113
|
+
};
|
|
114
|
+
/** @internal Vercel AI SDK LanguageModel — opaque type from SDK */
|
|
115
|
+
type SDKLanguageModel = Record<string, unknown>;
|
|
75
116
|
/** @internal SDK module shape */
|
|
76
117
|
interface SDKModule {
|
|
77
|
-
generateText: (options:
|
|
78
|
-
streamText: (options:
|
|
79
|
-
generateObject: (options:
|
|
80
|
-
tool: (options:
|
|
81
|
-
jsonSchema: (schema:
|
|
118
|
+
generateText: (options: Record<string, unknown>) => Promise<SDKGenerateTextResult>;
|
|
119
|
+
streamText: (options: Record<string, unknown>) => SDKStreamTextResult;
|
|
120
|
+
generateObject: (options: Record<string, unknown>) => Promise<SDKGenerateObjectResult>;
|
|
121
|
+
tool: (options: Record<string, unknown>) => SDKToolDefinition;
|
|
122
|
+
jsonSchema: (schema: unknown) => unknown;
|
|
123
|
+
stepCountIs: (count: number) => unknown;
|
|
82
124
|
}
|
|
83
125
|
/** @internal OpenAI-compatible module shape */
|
|
84
126
|
interface SDKCompatModule {
|
|
85
|
-
createOpenAICompatible: (options:
|
|
127
|
+
createOpenAICompatible: (options: Record<string, unknown>) => {
|
|
86
128
|
chatModel: (modelId: string) => SDKLanguageModel;
|
|
87
129
|
languageModel: (modelId: string) => SDKLanguageModel;
|
|
88
130
|
};
|
|
@@ -375,10 +375,10 @@ function mapToolsToSDK(sdk, tools, config, sessionApprovals, permissionStore, si
|
|
|
375
375
|
const jsonSchema = zodToJsonSchema(ourTool.parameters);
|
|
376
376
|
toolMap[ourTool.name] = sdk.tool({
|
|
377
377
|
description: ourTool.description,
|
|
378
|
-
|
|
378
|
+
inputSchema: sdk.jsonSchema(jsonSchema),
|
|
379
379
|
execute: wrapToolExecute(ourTool, supervisor, sessionApprovals, permissionStore, signal),
|
|
380
380
|
...ourTool.needsApproval && supervisor?.onPermission ? {
|
|
381
|
-
needsApproval: async (
|
|
381
|
+
needsApproval: async (_input) => {
|
|
382
382
|
if (permissionStore && await permissionStore.isApproved(ourTool.name)) return false;
|
|
383
383
|
if (sessionApprovals.has(ourTool.name)) return false;
|
|
384
384
|
return true;
|
|
@@ -390,7 +390,7 @@ function mapToolsToSDK(sdk, tools, config, sessionApprovals, permissionStore, si
|
|
|
390
390
|
const onAskUser = supervisor.onAskUser;
|
|
391
391
|
toolMap["ask_user"] = sdk.tool({
|
|
392
392
|
description: "Ask the user a question and wait for their response",
|
|
393
|
-
|
|
393
|
+
inputSchema: sdk.jsonSchema({
|
|
394
394
|
type: "object",
|
|
395
395
|
properties: {
|
|
396
396
|
question: { type: "string", description: "The question to ask the user" }
|
|
@@ -468,46 +468,60 @@ function messagesToSDK(messages) {
|
|
|
468
468
|
}
|
|
469
469
|
function mapStreamPart(part) {
|
|
470
470
|
switch (part.type) {
|
|
471
|
-
case "text-delta":
|
|
472
|
-
|
|
473
|
-
|
|
471
|
+
case "text-delta": {
|
|
472
|
+
const p = part;
|
|
473
|
+
return { type: "text_delta", text: p.text ?? "" };
|
|
474
|
+
}
|
|
475
|
+
case "tool-call": {
|
|
476
|
+
const p = part;
|
|
474
477
|
return {
|
|
475
478
|
type: "tool_call_start",
|
|
476
|
-
toolCallId: String(
|
|
477
|
-
toolName:
|
|
478
|
-
args:
|
|
479
|
+
toolCallId: String(p.toolCallId ?? ""),
|
|
480
|
+
toolName: p.toolName ?? "unknown",
|
|
481
|
+
args: p.input ?? {}
|
|
479
482
|
};
|
|
480
|
-
|
|
483
|
+
}
|
|
484
|
+
case "tool-result": {
|
|
485
|
+
const p = part;
|
|
481
486
|
return {
|
|
482
487
|
type: "tool_call_end",
|
|
483
|
-
toolCallId: String(
|
|
484
|
-
toolName:
|
|
485
|
-
result:
|
|
488
|
+
toolCallId: String(p.toolCallId ?? ""),
|
|
489
|
+
toolName: p.toolName ?? "unknown",
|
|
490
|
+
result: p.output ?? null
|
|
486
491
|
};
|
|
487
|
-
|
|
492
|
+
}
|
|
493
|
+
case "tool-error": {
|
|
494
|
+
const p = part;
|
|
488
495
|
return {
|
|
489
496
|
type: "error",
|
|
490
|
-
error:
|
|
497
|
+
error: p.error instanceof Error ? p.error.message : String(p.error ?? "Tool execution failed"),
|
|
491
498
|
recoverable: true
|
|
492
499
|
};
|
|
500
|
+
}
|
|
493
501
|
case "reasoning-start":
|
|
494
502
|
return { type: "thinking_start" };
|
|
495
503
|
case "reasoning-end":
|
|
496
504
|
return { type: "thinking_end" };
|
|
497
|
-
case "reasoning-delta":
|
|
498
|
-
|
|
499
|
-
|
|
505
|
+
case "reasoning-delta": {
|
|
506
|
+
const p = part;
|
|
507
|
+
return { type: "thinking_delta", text: p.text ?? "" };
|
|
508
|
+
}
|
|
509
|
+
case "finish-step": {
|
|
510
|
+
const p = part;
|
|
500
511
|
return {
|
|
501
512
|
type: "usage_update",
|
|
502
|
-
promptTokens: Number(
|
|
503
|
-
completionTokens: Number(
|
|
513
|
+
promptTokens: Number(p.usage?.inputTokens ?? 0),
|
|
514
|
+
completionTokens: Number(p.usage?.outputTokens ?? 0)
|
|
504
515
|
};
|
|
505
|
-
|
|
516
|
+
}
|
|
517
|
+
case "error": {
|
|
518
|
+
const p = part;
|
|
506
519
|
return {
|
|
507
520
|
type: "error",
|
|
508
|
-
error:
|
|
521
|
+
error: p.error instanceof Error ? p.error.message : String(p.error ?? "Unknown error"),
|
|
509
522
|
recoverable: false
|
|
510
523
|
};
|
|
524
|
+
}
|
|
511
525
|
default:
|
|
512
526
|
return null;
|
|
513
527
|
}
|
|
@@ -551,7 +565,7 @@ var VercelAIAgent = class extends BaseAgent {
|
|
|
551
565
|
system: this.config.systemPrompt,
|
|
552
566
|
messages: sdkMessages,
|
|
553
567
|
tools: hasTools ? tools : void 0,
|
|
554
|
-
|
|
568
|
+
stopWhen: sdk.stepCountIs(maxTurns),
|
|
555
569
|
abortSignal: signal,
|
|
556
570
|
...this.config.modelParams?.temperature !== void 0 && {
|
|
557
571
|
temperature: this.config.modelParams.temperature
|
|
@@ -561,6 +575,9 @@ var VercelAIAgent = class extends BaseAgent {
|
|
|
561
575
|
},
|
|
562
576
|
...this.config.modelParams?.topP !== void 0 && {
|
|
563
577
|
topP: this.config.modelParams.topP
|
|
578
|
+
},
|
|
579
|
+
...this.config.providerOptions && {
|
|
580
|
+
providerOptions: this.config.providerOptions
|
|
564
581
|
}
|
|
565
582
|
});
|
|
566
583
|
const toolCalls = [];
|
|
@@ -571,8 +588,8 @@ var VercelAIAgent = class extends BaseAgent {
|
|
|
571
588
|
);
|
|
572
589
|
toolCalls.push({
|
|
573
590
|
toolName: tc.toolName,
|
|
574
|
-
args: tc.
|
|
575
|
-
result: matchingResult?.
|
|
591
|
+
args: tc.input ?? {},
|
|
592
|
+
result: matchingResult?.output ?? null,
|
|
576
593
|
approved: true
|
|
577
594
|
});
|
|
578
595
|
}
|
|
@@ -612,6 +629,9 @@ var VercelAIAgent = class extends BaseAgent {
|
|
|
612
629
|
},
|
|
613
630
|
...this.config.modelParams?.maxTokens !== void 0 && {
|
|
614
631
|
maxTokens: this.config.modelParams.maxTokens
|
|
632
|
+
},
|
|
633
|
+
...this.config.providerOptions && {
|
|
634
|
+
providerOptions: this.config.providerOptions
|
|
615
635
|
}
|
|
616
636
|
});
|
|
617
637
|
let structuredOutput;
|
|
@@ -648,7 +668,7 @@ var VercelAIAgent = class extends BaseAgent {
|
|
|
648
668
|
system: this.config.systemPrompt,
|
|
649
669
|
messages: sdkMessages,
|
|
650
670
|
tools: hasTools ? tools : void 0,
|
|
651
|
-
|
|
671
|
+
stopWhen: sdk.stepCountIs(maxTurns),
|
|
652
672
|
abortSignal: signal,
|
|
653
673
|
...this.config.modelParams?.temperature !== void 0 && {
|
|
654
674
|
temperature: this.config.modelParams.temperature
|
|
@@ -658,6 +678,9 @@ var VercelAIAgent = class extends BaseAgent {
|
|
|
658
678
|
},
|
|
659
679
|
...this.config.modelParams?.topP !== void 0 && {
|
|
660
680
|
topP: this.config.modelParams.topP
|
|
681
|
+
},
|
|
682
|
+
...this.config.providerOptions && {
|
|
683
|
+
providerOptions: this.config.providerOptions
|
|
661
684
|
}
|
|
662
685
|
});
|
|
663
686
|
let finalText = "";
|