@loopstack/ai-module 0.20.7 → 0.20.8
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/dist/ai.module.js +2 -2
- package/dist/ai.module.js.map +1 -1
- package/dist/tools/ai-generate-document.tool.js +2 -2
- package/dist/tools/ai-generate-document.tool.js.map +1 -1
- package/dist/tools/ai-generate-text.tool.d.ts +1 -0
- package/dist/tools/ai-generate-text.tool.d.ts.map +1 -1
- package/dist/tools/ai-generate-text.tool.js +20 -2
- package/dist/tools/ai-generate-text.tool.js.map +1 -1
- package/dist/tools/delegate-tool-call.tool.d.ts.map +1 -1
- package/dist/tools/delegate-tool-call.tool.js +13 -0
- package/dist/tools/delegate-tool-call.tool.js.map +1 -1
- package/package.json +3 -3
- package/src/ai.module.ts +2 -2
- package/src/tools/ai-generate-document.tool.ts +1 -1
- package/src/tools/ai-generate-text.tool.ts +26 -2
- package/src/tools/delegate-tool-call.tool.ts +18 -1
package/dist/ai.module.js
CHANGED
|
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.AiModule = void 0;
|
|
10
10
|
const common_1 = require("@nestjs/common");
|
|
11
11
|
const core_1 = require("@nestjs/core");
|
|
12
|
-
const
|
|
12
|
+
const core_2 = require("@loopstack/core");
|
|
13
13
|
const documents_1 = require("./documents");
|
|
14
14
|
const anthropic_provider_1 = require("./providers/anthropic.provider");
|
|
15
15
|
const openai_provider_1 = require("./providers/openai.provider");
|
|
@@ -23,7 +23,7 @@ let AiModule = class AiModule {
|
|
|
23
23
|
exports.AiModule = AiModule;
|
|
24
24
|
exports.AiModule = AiModule = __decorate([
|
|
25
25
|
(0, common_1.Module)({
|
|
26
|
-
imports: [
|
|
26
|
+
imports: [core_2.LoopCoreModule, core_1.DiscoveryModule],
|
|
27
27
|
providers: [
|
|
28
28
|
services_1.AiMessagesHelperService,
|
|
29
29
|
services_2.AiProviderModelHelperService,
|
package/dist/ai.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai.module.js","sourceRoot":"","sources":["../src/ai.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,uCAA+C;AAC/C,
|
|
1
|
+
{"version":3,"file":"ai.module.js","sourceRoot":"","sources":["../src/ai.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,uCAA+C;AAC/C,0CAAiD;AACjD,2CAAgD;AAChD,uEAA0E;AAC1E,iEAAoE;AACpE,yCAAqD;AACrD,yCAA0D;AAC1D,yCAAkD;AAClD,0FAAoF;AACpF,mCAAiG;AA0B1F,IAAM,QAAQ,GAAd,MAAM,QAAQ;CAAG,CAAA;AAAX,4BAAQ;mBAAR,QAAQ;IAxBpB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,qBAAc,EAAE,sBAAe,CAAC;QAC1C,SAAS,EAAE;YAET,kCAAuB;YACvB,uCAA4B;YAC5B,+BAAoB;YACpB,wDAAyB;YAGzB,uCAAqB;YACrB,6CAAwB;YAGxB,0BAAkB;YAClB,wBAAgB;YAChB,sBAAc;YACd,wBAAgB;YAGhB,6BAAiB;SAClB;QACD,OAAO,EAAE,CAAC,0BAAkB,EAAE,wBAAgB,EAAE,sBAAc,EAAE,wBAAgB,EAAE,6BAAiB,CAAC;KACrG,CAAC;GACW,QAAQ,CAAG"}
|
|
@@ -11,7 +11,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.AiGenerateDocument = void 0;
|
|
13
13
|
const common_1 = require("@loopstack/common");
|
|
14
|
-
const
|
|
14
|
+
const core_1 = require("@loopstack/core");
|
|
15
15
|
const ai_generate_object_tool_1 = require("./ai-generate-object.tool");
|
|
16
16
|
let AiGenerateDocument = class AiGenerateDocument {
|
|
17
17
|
aiGenerateObject;
|
|
@@ -46,7 +46,7 @@ __decorate([
|
|
|
46
46
|
], AiGenerateDocument.prototype, "aiGenerateObject", void 0);
|
|
47
47
|
__decorate([
|
|
48
48
|
(0, common_1.InjectTool)(),
|
|
49
|
-
__metadata("design:type",
|
|
49
|
+
__metadata("design:type", core_1.CreateDocument)
|
|
50
50
|
], AiGenerateDocument.prototype, "createDocument", void 0);
|
|
51
51
|
__decorate([
|
|
52
52
|
(0, common_1.Input)({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-generate-document.tool.js","sourceRoot":"","sources":["../../src/tools/ai-generate-document.tool.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8CAU2B;AAC3B,
|
|
1
|
+
{"version":3,"file":"ai-generate-document.tool.js","sourceRoot":"","sources":["../../src/tools/ai-generate-document.tool.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8CAU2B;AAC3B,0CAAiD;AACjD,uEAA+G;AAOxG,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IACP,gBAAgB,CAAoB;IACpC,cAAc,CAAkB;IAKtD,IAAI,CAA2B;IAEvB,eAAe,CAAC,IAAY;QAClC,MAAM,IAAI,GAAG,IAAA,qBAAY,EAAgB,IAAI,EAAE,IAAI,CAAC,CAAC;QACrD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,SAAS,IAAI,oBAAoB,CAAC,CAAC;QACrD,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,OAAO,CACX,IAA8B,EAC9B,GAAe,EACf,MAAyB,EACzB,QAAmC;QAEnC,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;QAC3G,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,gBAAgB,CAAC,CAAC,OAAO,CACzE;YACE,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC,EAAE;YACpB,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,QAAQ;YAChC,MAAM,EAAE;gBACN,OAAO,EAAE,cAAc,CAAC,IAAe;aACxC;SACF,EACD,GAAG,EACH,MAAM,EACN,QAAQ,CACT,CAAC;QAEF,OAAO;YACL,GAAG,cAAc;YACjB,QAAQ,EAAE,cAAc,CAAC,QAAQ;SAClC,CAAC;IACJ,CAAC;CACF,CAAA;AA1CY,gDAAkB;AACP;IAArB,IAAA,mBAAU,GAAE;8BAA4B,0CAAgB;4DAAC;AACpC;IAArB,IAAA,mBAAU,GAAE;8BAA0B,qBAAc;0DAAC;AAKtD;IAHC,IAAA,cAAK,EAAC;QACL,MAAM,EAAE,gDAAsB;KAC/B,CAAC;;gDAC6B;6BAPpB,kBAAkB;IAL9B,IAAA,aAAI,EAAC;QACJ,MAAM,EAAE;YACN,WAAW,EAAE,sEAAsE;SACpF;KACF,CAAC;GACW,kBAAkB,CA0C9B"}
|
|
@@ -27,6 +27,7 @@ export declare class AiGenerateText implements ToolInterface<AiGenerateTextArgsT
|
|
|
27
27
|
private readonly aiProviderModelHelperService;
|
|
28
28
|
args: AiGenerateTextArgsType;
|
|
29
29
|
execute(args: AiGenerateTextArgsType, ctx: RunContext, parent: WorkflowInterface, runtime: WorkflowMetadataInterface): Promise<ToolResult>;
|
|
30
|
+
private extractToolCalls;
|
|
30
31
|
private handleGenerateText;
|
|
31
32
|
}
|
|
32
33
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-generate-text.tool.d.ts","sourceRoot":"","sources":["../../src/tools/ai-generate-text.tool.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAEL,UAAU,
|
|
1
|
+
{"version":3,"file":"ai-generate-text.tool.d.ts","sourceRoot":"","sources":["../../src/tools/ai-generate-text.tool.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAEL,UAAU,EAIV,aAAa,EACb,UAAU,EACV,iBAAiB,EACjB,yBAAyB,EAC1B,MAAM,mBAAmB,CAAC;AAM3B,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;kBAEtB,CAAC;AAEZ,KAAK,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAEnE,qBAKa,cAAe,YAAW,aAAa,CAAC,sBAAsB,CAAC;IAE1E,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAA0B;IAElE,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAuB;IAE5D,OAAO,CAAC,QAAQ,CAAC,4BAA4B,CAA+B;IAK5E,IAAI,EAAE,sBAAsB,CAAC;IAEvB,OAAO,CACX,IAAI,EAAE,sBAAsB,EAC5B,GAAG,EAAE,UAAU,EACf,MAAM,EAAE,iBAAiB,EACzB,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,UAAU,CAAC;IA0CtB,OAAO,CAAC,gBAAgB;YAmBV,kBAAkB;CA0DjC"}
|
|
@@ -48,12 +48,30 @@ let AiGenerateText = class AiGenerateText {
|
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
50
|
const { uiMessage, usage } = await this.handleGenerateText(model, options);
|
|
51
|
-
|
|
51
|
+
const toolCalls = this.extractToolCalls(uiMessage);
|
|
52
52
|
return {
|
|
53
|
-
data:
|
|
53
|
+
data: {
|
|
54
|
+
...uiMessage,
|
|
55
|
+
...(toolCalls ? { toolCalls } : {}),
|
|
56
|
+
},
|
|
54
57
|
metadata: { usage },
|
|
55
58
|
};
|
|
56
59
|
}
|
|
60
|
+
extractToolCalls(message) {
|
|
61
|
+
const toolCalls = {};
|
|
62
|
+
for (const part of message.parts) {
|
|
63
|
+
if (!('type' in part) || typeof part.type !== 'string' || !part.type.startsWith('tool-')) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const toolName = part.type.replace(/^tool-/, '');
|
|
67
|
+
toolCalls[toolName] = {
|
|
68
|
+
id: part.toolCallId ?? '',
|
|
69
|
+
name: toolName,
|
|
70
|
+
input: part.input,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return Object.keys(toolCalls).length > 0 ? toolCalls : null;
|
|
74
|
+
}
|
|
57
75
|
async handleGenerateText(model, options) {
|
|
58
76
|
const startTime = performance.now();
|
|
59
77
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-generate-text.tool.js","sourceRoot":"","sources":["../../src/tools/ai-generate-text.tool.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,2CAAwC;AACxC,2BAAkH;AAClH,6BAAwB;AACxB,
|
|
1
|
+
{"version":3,"file":"ai-generate-text.tool.js","sourceRoot":"","sources":["../../src/tools/ai-generate-text.tool.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,2CAAwC;AACxC,2BAAkH;AAClH,6BAAwB;AACxB,8CAU2B;AAC3B,0FAAmF;AACnF,0CAAsD;AACtD,0CAA2D;AAC3D,0CAAmD;AAEtC,QAAA,oBAAoB,GAAG,uDAAwB,CAAC,MAAM,CAAC;IAClE,KAAK,EAAE,OAAC,CAAC,KAAK,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;CACtC,CAAC,CAAC,MAAM,EAAE,CAAC;AASL,IAAM,cAAc,GAApB,MAAM,cAAc;IAER,uBAAuB,CAA0B;IAEjD,oBAAoB,CAAuB;IAE3C,4BAA4B,CAA+B;IAK5E,IAAI,CAAyB;IAE7B,KAAK,CAAC,OAAO,CACX,IAA4B,EAC5B,GAAe,EACf,MAAyB,EACzB,OAAkC;QAElC,MAAM,KAAK,GAAG,IAAI,CAAC,4BAA4B,CAAC,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAE3E,MAAM,OAAO,GAIT;YACF,QAAQ,EAAE,EAAE;SACb,CAAC;Q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E;YACN,WAAW,EAAE,4BAA4B;SAC1C;KACF,CAAC;GACW,cAAc,CAyI1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delegate-tool-call.tool.d.ts","sourceRoot":"","sources":["../../src/tools/delegate-tool-call.tool.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAEL,UAAU,
|
|
1
|
+
{"version":3,"file":"delegate-tool-call.tool.d.ts","sourceRoot":"","sources":["../../src/tools/delegate-tool-call.tool.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAEL,UAAU,EAIV,aAAa,EACb,UAAU,EACV,iBAAiB,EACjB,yBAAyB,EAE1B,MAAM,mBAAmB,CAAC;AAE3B,QAAA,MAAM,2BAA2B;;;;;;;;;;;iBAa/B,CAAC;AAEH,KAAK,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAE7E,qBAKa,gBAAiB,YAAW,aAAa,CAAC,yBAAyB,CAAC;IAC/E,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqC;IAK5D,IAAI,EAAE,yBAAyB,CAAC;IAE1B,OAAO,CACX,IAAI,EAAE,yBAAyB,EAC/B,GAAG,EAAE,UAAU,EACf,MAAM,EAAE,iBAAiB,EACzB,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,UAAU,CAAC;YAkFR,qBAAqB;CAuBpC"}
|
|
@@ -32,6 +32,7 @@ let DelegateToolCall = DelegateToolCall_1 = class DelegateToolCall {
|
|
|
32
32
|
async execute(args, ctx, parent, runtime) {
|
|
33
33
|
const parts = args.message.parts;
|
|
34
34
|
const resultParts = [];
|
|
35
|
+
const toolCalls = {};
|
|
35
36
|
for (const part of parts) {
|
|
36
37
|
if (!part.type.startsWith('tool-')) {
|
|
37
38
|
continue;
|
|
@@ -56,6 +57,12 @@ let DelegateToolCall = DelegateToolCall_1 = class DelegateToolCall {
|
|
|
56
57
|
input: part.input,
|
|
57
58
|
state: 'output-available',
|
|
58
59
|
});
|
|
60
|
+
toolCalls[toolName] = {
|
|
61
|
+
id: part.toolCallId,
|
|
62
|
+
name: toolName,
|
|
63
|
+
input: part.input,
|
|
64
|
+
output: result.data,
|
|
65
|
+
};
|
|
59
66
|
}
|
|
60
67
|
catch (error) {
|
|
61
68
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
@@ -67,12 +74,18 @@ let DelegateToolCall = DelegateToolCall_1 = class DelegateToolCall {
|
|
|
67
74
|
state: 'output-error',
|
|
68
75
|
errorText: errorMessage,
|
|
69
76
|
});
|
|
77
|
+
toolCalls[toolName] = {
|
|
78
|
+
id: part.toolCallId,
|
|
79
|
+
name: toolName,
|
|
80
|
+
input: part.input,
|
|
81
|
+
};
|
|
70
82
|
}
|
|
71
83
|
}
|
|
72
84
|
const resultMessage = {
|
|
73
85
|
id: args.message.id,
|
|
74
86
|
role: 'assistant',
|
|
75
87
|
parts: resultParts,
|
|
88
|
+
...(Object.keys(toolCalls).length > 0 ? { toolCalls } : {}),
|
|
76
89
|
};
|
|
77
90
|
if (args.document && !args.skipResponseMessage) {
|
|
78
91
|
const docResult = await this.createResponseMessage(args, resultMessage, ctx, parent, runtime);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delegate-tool-call.tool.js","sourceRoot":"","sources":["../../src/tools/delegate-tool-call.tool.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAwC;AAExC,6BAAwB;AACxB,
|
|
1
|
+
{"version":3,"file":"delegate-tool-call.tool.js","sourceRoot":"","sources":["../../src/tools/delegate-tool-call.tool.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAwC;AAExC,6BAAwB;AACxB,8CAW2B;AAE3B,MAAM,2BAA2B,GAAG,OAAC,CAAC,MAAM,CAAC;IAC3C,OAAO,EAAE,OAAC,CAAC,MAAM,CA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AE,OAAO,EAAE,aAAa,EAAE;SACnC,EACD,GAAG,EACH,MAAM,EACN,OAAO,CACR,CAAC;IACJ,CAAC;CACF,CAAA;AAtHY,4CAAgB;AAM3B;IAHC,IAAA,cAAK,EAAC;QACL,MAAM,EAAE,2BAA2B;KACpC,CAAC;;8CAC8B;2BANrB,gBAAgB;IAL5B,IAAA,aAAI,EAAC;QACJ,MAAM,EAAE;YACN,WAAW,EAAE,uBAAuB;SACrC;KACF,CAAC;GACW,gBAAgB,CAsH5B"}
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"openai",
|
|
11
11
|
"tool"
|
|
12
12
|
],
|
|
13
|
-
"version": "0.20.
|
|
13
|
+
"version": "0.20.8",
|
|
14
14
|
"license": "Apache-2.0",
|
|
15
15
|
"author": {
|
|
16
16
|
"name": "Jakob Klippel",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"@ai-sdk/anthropic": "^3.0.45",
|
|
35
35
|
"@ai-sdk/openai": "^3.0.30",
|
|
36
36
|
"@ai-sdk/provider-utils": "^4.0.15",
|
|
37
|
-
"@loopstack/common": "^0.
|
|
38
|
-
"@loopstack/core
|
|
37
|
+
"@loopstack/common": "^0.24.0",
|
|
38
|
+
"@loopstack/core": "^0.24.0",
|
|
39
39
|
"@nestjs/common": "^11.1.14",
|
|
40
40
|
"@nestjs/config": "^4.0.3",
|
|
41
41
|
"@nestjs/core": "^11.1.14",
|
package/src/ai.module.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Module } from '@nestjs/common';
|
|
2
2
|
import { DiscoveryModule } from '@nestjs/core';
|
|
3
|
-
import {
|
|
3
|
+
import { LoopCoreModule } from '@loopstack/core';
|
|
4
4
|
import { AiMessageDocument } from './documents';
|
|
5
5
|
import { AnthropicProviderService } from './providers/anthropic.provider';
|
|
6
6
|
import { OpenAiProviderService } from './providers/openai.provider';
|
|
@@ -11,7 +11,7 @@ import { AiProviderRegistryService } from './services/ai-provider-registry.servi
|
|
|
11
11
|
import { AiGenerateDocument, AiGenerateObject, AiGenerateText, DelegateToolCall } from './tools';
|
|
12
12
|
|
|
13
13
|
@Module({
|
|
14
|
-
imports: [
|
|
14
|
+
imports: [LoopCoreModule, DiscoveryModule],
|
|
15
15
|
providers: [
|
|
16
16
|
// services
|
|
17
17
|
AiMessagesHelperService,
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
WorkflowMetadataInterface,
|
|
10
10
|
getBlockTool,
|
|
11
11
|
} from '@loopstack/common';
|
|
12
|
-
import { CreateDocument } from '@loopstack/core
|
|
12
|
+
import { CreateDocument } from '@loopstack/core';
|
|
13
13
|
import { AiGenerateObject, AiGenerateObjectArgsType, AiGenerateObjectSchema } from './ai-generate-object.tool';
|
|
14
14
|
|
|
15
15
|
@Tool({
|
|
@@ -6,6 +6,8 @@ import {
|
|
|
6
6
|
Input,
|
|
7
7
|
RunContext,
|
|
8
8
|
Tool,
|
|
9
|
+
ToolCallEntry,
|
|
10
|
+
ToolCallsMap,
|
|
9
11
|
ToolInterface,
|
|
10
12
|
ToolResult,
|
|
11
13
|
WorkflowInterface,
|
|
@@ -76,14 +78,36 @@ export class AiGenerateText implements ToolInterface<AiGenerateTextArgsType> {
|
|
|
76
78
|
|
|
77
79
|
const { uiMessage, usage } = await this.handleGenerateText(model, options);
|
|
78
80
|
|
|
79
|
-
|
|
81
|
+
const toolCalls = this.extractToolCalls(uiMessage);
|
|
80
82
|
|
|
81
83
|
return {
|
|
82
|
-
data:
|
|
84
|
+
data: {
|
|
85
|
+
...uiMessage,
|
|
86
|
+
...(toolCalls ? { toolCalls } : {}),
|
|
87
|
+
},
|
|
83
88
|
metadata: { usage },
|
|
84
89
|
};
|
|
85
90
|
}
|
|
86
91
|
|
|
92
|
+
private extractToolCalls(message: UIMessage): ToolCallsMap | null {
|
|
93
|
+
const toolCalls: ToolCallsMap = {};
|
|
94
|
+
|
|
95
|
+
for (const part of message.parts) {
|
|
96
|
+
if (!('type' in part) || typeof part.type !== 'string' || !part.type.startsWith('tool-')) {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const toolName = part.type.replace(/^tool-/, '');
|
|
101
|
+
toolCalls[toolName] = {
|
|
102
|
+
id: (part as { toolCallId?: string }).toolCallId ?? '',
|
|
103
|
+
name: toolName,
|
|
104
|
+
input: (part as { input?: unknown }).input,
|
|
105
|
+
} satisfies ToolCallEntry;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return Object.keys(toolCalls).length > 0 ? toolCalls : null;
|
|
109
|
+
}
|
|
110
|
+
|
|
87
111
|
private async handleGenerateText(
|
|
88
112
|
model: LanguageModel,
|
|
89
113
|
options: {
|
|
@@ -5,6 +5,8 @@ import {
|
|
|
5
5
|
Input,
|
|
6
6
|
RunContext,
|
|
7
7
|
Tool,
|
|
8
|
+
ToolCallEntry,
|
|
9
|
+
ToolCallsMap,
|
|
8
10
|
ToolInterface,
|
|
9
11
|
ToolResult,
|
|
10
12
|
WorkflowInterface,
|
|
@@ -50,6 +52,7 @@ export class DelegateToolCall implements ToolInterface<DelegateToolCallsToolArgs
|
|
|
50
52
|
): Promise<ToolResult> {
|
|
51
53
|
const parts = args.message.parts;
|
|
52
54
|
const resultParts: ToolUIPart[] = [];
|
|
55
|
+
const toolCalls: ToolCallsMap = {};
|
|
53
56
|
|
|
54
57
|
for (const part of parts) {
|
|
55
58
|
if (!part.type.startsWith('tool-')) {
|
|
@@ -80,6 +83,13 @@ export class DelegateToolCall implements ToolInterface<DelegateToolCallsToolArgs
|
|
|
80
83
|
input: part.input as Record<string, unknown>,
|
|
81
84
|
state: 'output-available',
|
|
82
85
|
} satisfies ToolUIPart);
|
|
86
|
+
|
|
87
|
+
toolCalls[toolName] = {
|
|
88
|
+
id: part.toolCallId,
|
|
89
|
+
name: toolName,
|
|
90
|
+
input: part.input,
|
|
91
|
+
output: result.data,
|
|
92
|
+
} satisfies ToolCallEntry;
|
|
83
93
|
} catch (error) {
|
|
84
94
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
85
95
|
this.logger.error(`Tool "${toolName}" failed: ${errorMessage}`);
|
|
@@ -91,13 +101,20 @@ export class DelegateToolCall implements ToolInterface<DelegateToolCallsToolArgs
|
|
|
91
101
|
state: 'output-error',
|
|
92
102
|
errorText: errorMessage,
|
|
93
103
|
} as ToolUIPart);
|
|
104
|
+
|
|
105
|
+
toolCalls[toolName] = {
|
|
106
|
+
id: part.toolCallId,
|
|
107
|
+
name: toolName,
|
|
108
|
+
input: part.input,
|
|
109
|
+
} satisfies ToolCallEntry;
|
|
94
110
|
}
|
|
95
111
|
}
|
|
96
112
|
|
|
97
|
-
const resultMessage: UIMessage = {
|
|
113
|
+
const resultMessage: UIMessage & { toolCalls?: ToolCallsMap } = {
|
|
98
114
|
id: args.message.id,
|
|
99
115
|
role: 'assistant',
|
|
100
116
|
parts: resultParts,
|
|
117
|
+
...(Object.keys(toolCalls).length > 0 ? { toolCalls } : {}),
|
|
101
118
|
};
|
|
102
119
|
|
|
103
120
|
if (args.document && !args.skipResponseMessage) {
|