@loopstack/claude-module 0.21.1 → 0.22.1
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/claude.module.d.ts.map +1 -1
- package/dist/claude.module.js +1 -10
- package/dist/claude.module.js.map +1 -1
- package/dist/documents/claude-message-document.d.ts +3 -1
- package/dist/documents/claude-message-document.d.ts.map +1 -1
- package/dist/documents/claude-message-document.js +6 -18
- package/dist/documents/claude-message-document.js.map +1 -1
- package/dist/documents/claude-message-document.yaml +2 -2
- 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/dist/tools/claude-generate-document.tool.d.ts +3 -6
- package/dist/tools/claude-generate-document.tool.d.ts.map +1 -1
- package/dist/tools/claude-generate-document.tool.js +9 -31
- package/dist/tools/claude-generate-document.tool.js.map +1 -1
- package/dist/tools/claude-generate-object.tool.d.ts +4 -5
- package/dist/tools/claude-generate-object.tool.d.ts.map +1 -1
- package/dist/tools/claude-generate-object.tool.js +7 -17
- package/dist/tools/claude-generate-object.tool.js.map +1 -1
- package/dist/tools/claude-generate-text.tool.d.ts +4 -6
- package/dist/tools/claude-generate-text.tool.d.ts.map +1 -1
- package/dist/tools/claude-generate-text.tool.js +6 -34
- package/dist/tools/claude-generate-text.tool.js.map +1 -1
- package/dist/tools/delegate-tool-calls.tool.d.ts +5 -10
- package/dist/tools/delegate-tool-calls.tool.d.ts.map +1 -1
- package/dist/tools/delegate-tool-calls.tool.js +37 -66
- package/dist/tools/delegate-tool-calls.tool.js.map +1 -1
- package/dist/tools/update-tool-result.tool.d.ts +4 -9
- package/dist/tools/update-tool-result.tool.d.ts.map +1 -1
- package/dist/tools/update-tool-result.tool.js +18 -53
- package/dist/tools/update-tool-result.tool.js.map +1 -1
- package/dist/types/claude.types.d.ts +19 -0
- package/dist/types/claude.types.d.ts.map +1 -1
- package/dist/types/claude.types.js.map +1 -1
- package/package.json +13 -8
- package/src/claude.module.ts +1 -12
- package/src/documents/claude-message-document.ts +6 -12
- package/src/documents/claude-message-document.yaml +2 -2
- package/src/index.ts +1 -0
- package/src/services/claude-tools-helper.service.ts +1 -1
- package/src/tools/claude-generate-document.tool.ts +11 -48
- package/src/tools/claude-generate-object.tool.ts +13 -29
- package/src/tools/claude-generate-text.tool.ts +8 -65
- package/src/tools/delegate-tool-calls.tool.ts +53 -112
- package/src/tools/update-tool-result.tool.ts +21 -61
- package/src/types/claude.types.ts +26 -0
|
@@ -5,22 +5,20 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
8
|
var DelegateToolCalls_1;
|
|
12
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
10
|
exports.DelegateToolCalls = void 0;
|
|
14
11
|
const common_1 = require("@nestjs/common");
|
|
15
12
|
const zod_1 = require("zod");
|
|
16
13
|
const common_2 = require("@loopstack/common");
|
|
17
|
-
const core_1 = require("@loopstack/core");
|
|
18
14
|
const DelegateToolCallsSchema = zod_1.z.object({
|
|
19
15
|
message: zod_1.z.object({
|
|
20
16
|
id: zod_1.z.string().optional(),
|
|
21
17
|
content: zod_1.z.array(zod_1.z.any()),
|
|
22
18
|
}),
|
|
23
|
-
document: zod_1.z
|
|
19
|
+
document: zod_1.z
|
|
20
|
+
.custom((val) => typeof val === 'function' && (0, common_2.getBlockTypeFromMetadata)(val) === 'document')
|
|
21
|
+
.optional(),
|
|
24
22
|
skipResponseMessage: zod_1.z.boolean().optional(),
|
|
25
23
|
callback: zod_1.z
|
|
26
24
|
.object({
|
|
@@ -28,41 +26,36 @@ const DelegateToolCallsSchema = zod_1.z.object({
|
|
|
28
26
|
})
|
|
29
27
|
.optional(),
|
|
30
28
|
});
|
|
31
|
-
let DelegateToolCalls = DelegateToolCalls_1 = class DelegateToolCalls {
|
|
32
|
-
toolCallProcessor;
|
|
33
|
-
eventSubscriberService;
|
|
29
|
+
let DelegateToolCalls = DelegateToolCalls_1 = class DelegateToolCalls extends common_2.BaseTool {
|
|
34
30
|
logger = new common_1.Logger(DelegateToolCalls_1.name);
|
|
35
|
-
|
|
36
|
-
constructor(toolCallProcessor, eventSubscriberService) {
|
|
37
|
-
this.toolCallProcessor = toolCallProcessor;
|
|
38
|
-
this.eventSubscriberService = eventSubscriberService;
|
|
39
|
-
}
|
|
40
|
-
args;
|
|
41
|
-
async execute(args, ctx, parent, metadata) {
|
|
31
|
+
async call(args) {
|
|
42
32
|
const contentBlocks = args.message.content;
|
|
43
33
|
const toolUseBlocks = contentBlocks.filter((b) => b.type === 'tool_use');
|
|
44
34
|
if (toolUseBlocks.length === 0) {
|
|
45
35
|
return {
|
|
46
|
-
data: {
|
|
36
|
+
data: {
|
|
37
|
+
allCompleted: true,
|
|
38
|
+
toolResults: [],
|
|
39
|
+
message: args.message,
|
|
40
|
+
pendingCount: 0,
|
|
41
|
+
},
|
|
47
42
|
};
|
|
48
43
|
}
|
|
49
|
-
const results = await Promise.all(toolUseBlocks.map((block) =>
|
|
44
|
+
const results = await Promise.all(toolUseBlocks.map((block) => {
|
|
45
|
+
const toolCallback = args.callback
|
|
46
|
+
? {
|
|
47
|
+
transition: args.callback.transition,
|
|
48
|
+
metadata: { toolUseId: block.id, toolName: block.name },
|
|
49
|
+
}
|
|
50
|
+
: undefined;
|
|
51
|
+
return this.executeTool(block, toolCallback ? { callback: toolCallback } : undefined);
|
|
52
|
+
}));
|
|
50
53
|
let pendingCount = 0;
|
|
51
54
|
const toolResults = [];
|
|
52
|
-
const toolEffects = [];
|
|
53
55
|
for (let i = 0; i < toolUseBlocks.length; i++) {
|
|
54
56
|
const block = toolUseBlocks[i];
|
|
55
57
|
const result = results[i];
|
|
56
|
-
if (result.
|
|
57
|
-
toolEffects.push(...result.effects);
|
|
58
|
-
}
|
|
59
|
-
const resultData = result.data;
|
|
60
|
-
if (resultData?.mode === 'async') {
|
|
61
|
-
if (!args.callback?.transition) {
|
|
62
|
-
throw new Error(`Tool "${block.name}" returned an async result but no callback.transition was provided. ` +
|
|
63
|
-
`Add a callback configuration to the delegateToolCalls args.`);
|
|
64
|
-
}
|
|
65
|
-
await this.eventSubscriberService.registerSubscriber(ctx.pipelineId, ctx.workflowId, args.callback.transition, resultData.correlationId, resultData.eventName, ctx.userId, ctx.workspaceId, { toolUseId: block.id, toolName: block.name });
|
|
58
|
+
if (result.pending) {
|
|
66
59
|
pendingCount++;
|
|
67
60
|
}
|
|
68
61
|
else {
|
|
@@ -74,14 +67,9 @@ let DelegateToolCalls = DelegateToolCalls_1 = class DelegateToolCalls {
|
|
|
74
67
|
});
|
|
75
68
|
}
|
|
76
69
|
}
|
|
77
|
-
const effects = [];
|
|
78
70
|
if (args.document && !args.skipResponseMessage) {
|
|
79
|
-
|
|
80
|
-
if (docResult.effects) {
|
|
81
|
-
effects.push(...docResult.effects);
|
|
82
|
-
}
|
|
71
|
+
await this.createResponseDocument(args.document, args, toolResults);
|
|
83
72
|
}
|
|
84
|
-
effects.push(...toolEffects);
|
|
85
73
|
return {
|
|
86
74
|
data: {
|
|
87
75
|
allCompleted: pendingCount === 0,
|
|
@@ -89,14 +77,15 @@ let DelegateToolCalls = DelegateToolCalls_1 = class DelegateToolCalls {
|
|
|
89
77
|
message: args.message,
|
|
90
78
|
pendingCount,
|
|
91
79
|
},
|
|
92
|
-
effects,
|
|
93
80
|
};
|
|
94
81
|
}
|
|
95
|
-
async executeTool(block,
|
|
96
|
-
const tool = this.toolCallProcessor.getTool(parent, block.name);
|
|
97
|
-
const parsedArgs = this.toolCallProcessor.parseArgs(tool, block.input, metadata.transition);
|
|
82
|
+
async executeTool(block, options) {
|
|
98
83
|
try {
|
|
99
|
-
|
|
84
|
+
const tool = (0, common_2.getBlockTool)(this.ctx.parent, block.name);
|
|
85
|
+
if (!tool) {
|
|
86
|
+
throw new Error(`Tool with name ${block.name} not found.`);
|
|
87
|
+
}
|
|
88
|
+
return await tool.call(block.input, options);
|
|
100
89
|
}
|
|
101
90
|
catch (error) {
|
|
102
91
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
@@ -107,40 +96,22 @@ let DelegateToolCalls = DelegateToolCalls_1 = class DelegateToolCalls {
|
|
|
107
96
|
};
|
|
108
97
|
}
|
|
109
98
|
}
|
|
110
|
-
async createResponseDocument(args, toolResults
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
content: {
|
|
117
|
-
role: 'assistant',
|
|
118
|
-
content: args.message.content,
|
|
119
|
-
toolResults,
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
}, ctx, parent, metadata);
|
|
99
|
+
async createResponseDocument(document, args, toolResults) {
|
|
100
|
+
await this.repository.save(document, {
|
|
101
|
+
role: 'assistant',
|
|
102
|
+
content: args.message.content,
|
|
103
|
+
toolResults,
|
|
104
|
+
}, { id: args.message.id, validate: 'skip' });
|
|
123
105
|
}
|
|
124
106
|
};
|
|
125
107
|
exports.DelegateToolCalls = DelegateToolCalls;
|
|
126
|
-
__decorate([
|
|
127
|
-
(0, common_2.InjectTool)(),
|
|
128
|
-
__metadata("design:type", core_1.CreateDocument)
|
|
129
|
-
], DelegateToolCalls.prototype, "createDocument", void 0);
|
|
130
|
-
__decorate([
|
|
131
|
-
(0, common_2.Input)({
|
|
132
|
-
schema: DelegateToolCallsSchema,
|
|
133
|
-
}),
|
|
134
|
-
__metadata("design:type", Object)
|
|
135
|
-
], DelegateToolCalls.prototype, "args", void 0);
|
|
136
108
|
exports.DelegateToolCalls = DelegateToolCalls = DelegateToolCalls_1 = __decorate([
|
|
137
109
|
(0, common_1.Injectable)(),
|
|
138
110
|
(0, common_2.Tool)({
|
|
139
|
-
|
|
111
|
+
uiConfig: {
|
|
140
112
|
description: 'Delegate tool calls from an LLM response. Handles both sync tools and async task tools.',
|
|
141
113
|
},
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
core_1.EventSubscriberService])
|
|
114
|
+
schema: DelegateToolCallsSchema,
|
|
115
|
+
})
|
|
145
116
|
], DelegateToolCalls);
|
|
146
117
|
//# sourceMappingURL=delegate-tool-calls.tool.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delegate-tool-calls.tool.js","sourceRoot":"","sources":["../../src/tools/delegate-tool-calls.tool.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"delegate-tool-calls.tool.js","sourceRoot":"","sources":["../../src/tools/delegate-tool-calls.tool.ts"],"names":[],"mappings":";;;;;;;;;;AACA,2CAAoD;AACpD,6BAAwB;AACxB,8CAQ2B;AAG3B,MAAM,uBAAuB,GAAG,OAAC,CAAC,MAAM,CAAC;IACvC,OAAO,EAAE,OAAC,CAAC,MAAM,CAAC;QAChB,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;QACzB,OAAO,EAAE,OAAC,CAAC,KAAK,CAAC,OAAC,CAAC,GAAG,EAAE,CAAC;KAC1B,CAAC;IACF,QAAQ,EAAE,OAAC;SACR,MAAM,CAAgB,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,GAAG,KAAK,UAAU,IAAI,IAAA,iCAAwB,EAAC,GAAa,CAAC,KAAK,UAAU,CAAC;SACnH,QAAQ,EAAE;IACb,mBAAmB,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IAC3C,QAAQ,EAAE,OAAC;SACR,MAAM,CAAC;QACN,UAAU,EAAE,OAAC,CAAC,MAAM,EAAE;KACvB,CAAC;SACD,QAAQ,EAAE;CACd,CAAC,CAAC;AAW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,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAgC,EAAE,OAAO,CAAC,CAAC;QAC1E,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC5E,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,KAAK,CAAC,IAAI,aAAa,YAAY,EAAE,CAAC,CAAC;YAClE,OAAO;gBACL,IAAI,EAAE,YAAY;gBAClB,KAAK,EAAE,YAAY;aACpB,CAAC;QACJ,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,sBAAsB,CAClC,QAAuB,EACvB,IAA2B,EAC3B,WAAsC;QAEtC,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,CACxB,QAAQ,EACR;YACE,IAAI,EAAE,WAAW;YACjB,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO;YAC7B,WAAW;SACZ,EACD,EAAE,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAC1C,CAAC;IACJ,CAAC;CACF,CAAA;AAnGY,8CAAiB;4BAAjB,iBAAiB;IAP7B,IAAA,mBAAU,GAAE;IACZ,IAAA,aAAI,EAAC;QACJ,QAAQ,EAAE;YACR,WAAW,EAAE,yFAAyF;SACvG;QACD,MAAM,EAAE,uBAAuB;KAChC,CAAC;GACW,iBAAiB,CAmG7B"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import {
|
|
3
|
-
import { StateMachineToolCallProcessorService } from '@loopstack/core';
|
|
2
|
+
import { BaseTool, DocumentClass, ToolResult } from '@loopstack/common';
|
|
4
3
|
declare const UpdateToolResultSchema: z.ZodObject<{
|
|
5
4
|
delegateResult: z.ZodObject<{
|
|
6
5
|
allCompleted: z.ZodBoolean;
|
|
@@ -9,16 +8,12 @@ declare const UpdateToolResultSchema: z.ZodObject<{
|
|
|
9
8
|
pendingCount: z.ZodNumber;
|
|
10
9
|
}, z.core.$strip>;
|
|
11
10
|
completedTool: z.ZodAny;
|
|
12
|
-
document: z.ZodOptional<z.
|
|
11
|
+
document: z.ZodOptional<z.ZodCustom<DocumentClass, DocumentClass>>;
|
|
13
12
|
}, z.core.$strip>;
|
|
14
13
|
type UpdateToolResultArgs = z.infer<typeof UpdateToolResultSchema>;
|
|
15
|
-
export declare class UpdateToolResult
|
|
16
|
-
private readonly toolCallProcessor;
|
|
14
|
+
export declare class UpdateToolResult extends BaseTool {
|
|
17
15
|
private readonly logger;
|
|
18
|
-
|
|
19
|
-
constructor(toolCallProcessor: StateMachineToolCallProcessorService);
|
|
20
|
-
args: UpdateToolResultArgs;
|
|
21
|
-
execute(args: UpdateToolResultArgs, ctx: RunContext, parent: WorkflowInterface, metadata: WorkflowMetadataInterface): Promise<ToolResult>;
|
|
16
|
+
call(args: UpdateToolResultArgs): Promise<ToolResult>;
|
|
22
17
|
}
|
|
23
18
|
export {};
|
|
24
19
|
//# sourceMappingURL=update-tool-result.tool.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update-tool-result.tool.d.ts","sourceRoot":"","sources":["../../src/tools/update-tool-result.tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,
|
|
1
|
+
{"version":3,"file":"update-tool-result.tool.d.ts","sourceRoot":"","sources":["../../src/tools/update-tool-result.tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAQ,UAAU,EAA0C,MAAM,mBAAmB,CAAC;AAEtH,QAAA,MAAM,sBAAsB;;;;;;;;;iBAW1B,CAAC;AAEH,KAAK,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAEnE,qBAOa,gBAAiB,SAAQ,QAAQ;IAC5C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqC;IAEtD,IAAI,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,UAAU,CAAC;CAqE5D"}
|
|
@@ -5,16 +5,12 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
8
|
var UpdateToolResult_1;
|
|
12
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
10
|
exports.UpdateToolResult = void 0;
|
|
14
11
|
const common_1 = require("@nestjs/common");
|
|
15
12
|
const zod_1 = require("zod");
|
|
16
13
|
const common_2 = require("@loopstack/common");
|
|
17
|
-
const core_1 = require("@loopstack/core");
|
|
18
14
|
const UpdateToolResultSchema = zod_1.z.object({
|
|
19
15
|
delegateResult: zod_1.z.object({
|
|
20
16
|
allCompleted: zod_1.z.boolean(),
|
|
@@ -23,17 +19,13 @@ const UpdateToolResultSchema = zod_1.z.object({
|
|
|
23
19
|
pendingCount: zod_1.z.number(),
|
|
24
20
|
}),
|
|
25
21
|
completedTool: zod_1.z.any(),
|
|
26
|
-
document: zod_1.z
|
|
22
|
+
document: zod_1.z
|
|
23
|
+
.custom((val) => typeof val === 'function' && (0, common_2.getBlockTypeFromMetadata)(val) === 'document')
|
|
24
|
+
.optional(),
|
|
27
25
|
});
|
|
28
|
-
let UpdateToolResult = UpdateToolResult_1 = class UpdateToolResult {
|
|
29
|
-
toolCallProcessor;
|
|
26
|
+
let UpdateToolResult = UpdateToolResult_1 = class UpdateToolResult extends common_2.BaseTool {
|
|
30
27
|
logger = new common_1.Logger(UpdateToolResult_1.name);
|
|
31
|
-
|
|
32
|
-
constructor(toolCallProcessor) {
|
|
33
|
-
this.toolCallProcessor = toolCallProcessor;
|
|
34
|
-
}
|
|
35
|
-
args;
|
|
36
|
-
async execute(args, ctx, parent, metadata) {
|
|
28
|
+
async call(args) {
|
|
37
29
|
const { delegateResult } = args;
|
|
38
30
|
const completedToolRecord = args.completedTool;
|
|
39
31
|
const subscriberMetadata = completedToolRecord._subscriberMetadata;
|
|
@@ -42,15 +34,13 @@ let UpdateToolResult = UpdateToolResult_1 = class UpdateToolResult {
|
|
|
42
34
|
'Ensure the event subscriber was registered with metadata by delegateToolCalls.');
|
|
43
35
|
}
|
|
44
36
|
const { toolUseId, toolName } = subscriberMetadata;
|
|
45
|
-
const tool = this.
|
|
37
|
+
const tool = (0, common_2.getBlockTool)(this.ctx.parent, toolName);
|
|
38
|
+
if (!tool) {
|
|
39
|
+
throw new Error(`Tool with name ${toolName} not found.`);
|
|
40
|
+
}
|
|
46
41
|
let toolResult;
|
|
47
42
|
try {
|
|
48
|
-
|
|
49
|
-
toolResult = await tool.complete(completedToolRecord, ctx, parent, metadata);
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
toolResult = { data: completedToolRecord.result ?? completedToolRecord };
|
|
53
|
-
}
|
|
43
|
+
toolResult = await tool.complete(completedToolRecord);
|
|
54
44
|
}
|
|
55
45
|
catch (error) {
|
|
56
46
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
@@ -69,26 +59,12 @@ let UpdateToolResult = UpdateToolResult_1 = class UpdateToolResult {
|
|
|
69
59
|
const updatedResults = [...delegateResult.toolResults, completedEntry];
|
|
70
60
|
const pendingCount = delegateResult.pendingCount - 1;
|
|
71
61
|
const allCompleted = pendingCount === 0;
|
|
72
|
-
const allEffects = [];
|
|
73
|
-
if (toolResult.effects) {
|
|
74
|
-
allEffects.push(...toolResult.effects);
|
|
75
|
-
}
|
|
76
62
|
if (args.document) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
content: {
|
|
83
|
-
role: 'assistant',
|
|
84
|
-
content: delegateResult.message.content,
|
|
85
|
-
toolResults: updatedResults,
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
}, ctx, parent, metadata);
|
|
89
|
-
if (docResult.effects) {
|
|
90
|
-
allEffects.push(...docResult.effects);
|
|
91
|
-
}
|
|
63
|
+
await this.repository.save(args.document, {
|
|
64
|
+
role: 'assistant',
|
|
65
|
+
content: delegateResult.message.content,
|
|
66
|
+
toolResults: updatedResults,
|
|
67
|
+
}, { id: delegateResult.message.id, validate: 'skip' });
|
|
92
68
|
}
|
|
93
69
|
return {
|
|
94
70
|
data: {
|
|
@@ -97,28 +73,17 @@ let UpdateToolResult = UpdateToolResult_1 = class UpdateToolResult {
|
|
|
97
73
|
allCompleted,
|
|
98
74
|
pendingCount,
|
|
99
75
|
},
|
|
100
|
-
effects: allEffects.length > 0 ? allEffects : undefined,
|
|
101
76
|
};
|
|
102
77
|
}
|
|
103
78
|
};
|
|
104
79
|
exports.UpdateToolResult = UpdateToolResult;
|
|
105
|
-
__decorate([
|
|
106
|
-
(0, common_2.InjectTool)(),
|
|
107
|
-
__metadata("design:type", core_1.CreateDocument)
|
|
108
|
-
], UpdateToolResult.prototype, "createDocument", void 0);
|
|
109
|
-
__decorate([
|
|
110
|
-
(0, common_2.Input)({
|
|
111
|
-
schema: UpdateToolResultSchema,
|
|
112
|
-
}),
|
|
113
|
-
__metadata("design:type", Object)
|
|
114
|
-
], UpdateToolResult.prototype, "args", void 0);
|
|
115
80
|
exports.UpdateToolResult = UpdateToolResult = UpdateToolResult_1 = __decorate([
|
|
116
81
|
(0, common_1.Injectable)(),
|
|
117
82
|
(0, common_2.Tool)({
|
|
118
|
-
|
|
83
|
+
uiConfig: {
|
|
119
84
|
description: 'Handle async tool completion callback. Updates the response document and tracks completion state.',
|
|
120
85
|
},
|
|
121
|
-
|
|
122
|
-
|
|
86
|
+
schema: UpdateToolResultSchema,
|
|
87
|
+
})
|
|
123
88
|
], UpdateToolResult);
|
|
124
89
|
//# sourceMappingURL=update-tool-result.tool.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update-tool-result.tool.js","sourceRoot":"","sources":["../../src/tools/update-tool-result.tool.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"update-tool-result.tool.js","sourceRoot":"","sources":["../../src/tools/update-tool-result.tool.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAoD;AACpD,6BAAwB;AACxB,8CAAsH;AAEtH,MAAM,sBAAsB,GAAG,OAAC,CAAC,MAAM,CAAC;IACtC,cAAc,EAAE,OAAC,CAAC,MAAM,CAAC;QACvB,YAAY,EAAE,OAAC,CAAC,OAAO,EAAE;QACzB,WAAW,EAAE,OAAC,CAAC,KAAK,CAAC,OAAC,CAAC,GAAG,EAAE,CAAC;QAC7B,OAAO,EAAE,OAAC,CAAC,GAAG,EAAE;QAChB,YAAY,EAAE,OAAC,CAAC,MAAM,EAAE;KACzB,CAAC;IACF,aAAa,EAAE,OAAC,CAAC,GAAG,EAAE;IACtB,QAAQ,EAAE,OAAC;SACR,MAAM,CAAgB,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,GAAG,KAAK,UAAU,IAAI,IAAA,iCAAwB,EAAC,GAAa,CAAC,KAAK,UAAU,CAAC;SACnH,QAAQ,EAAE;CACd,CAAC,CAAC;AAWI,IAAM,gBAAgB,wBAAtB,MAAM,gBAAiB,SAAQ,iBAAQ;IAC3B,MAAM,GAAG,IAAI,eAAM,CAAC,kBAAgB,CAAC,IAAI,CAAC,CAAC;IAE5D,KAAK,CAAC,IAAI,CAAC,IAA0B;QACnC,MAAM,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC;QAChC,MAAM,mBAAm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AAC,CAAC,UAAU,CAAC,KAAK;SAC7B,CAAC;QACF,MAAM,cAAc,GAAG,CAAC,GAAI,cAAc,CAAC,WAAyC,EAAE,cAAc,CAAC,CAAC;QAGtG,MAAM,YAAY,GAAG,cAAc,CAAC,YAAY,GAAG,CAAC,CAAC;QACrD,MAAM,YAAY,GAAG,YAAY,KAAK,CAAC,CAAC;QAGxC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,CACxB,IAAI,CAAC,QAAQ,EACb;gBACE,IAAI,EAAE,WAAW;gBACjB,OAAO,EAAG,cAAc,CAAC,OAAmC,CAAC,OAAO;gBACpE,WAAW,EAAE,cAAc;aAC5B,EACD,EAAE,EAAE,EAAG,cAAc,CAAC,OAAmC,CAAC,EAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,CAC3F,CAAC;QACJ,CAAC;QAED,OAAO;YACL,IAAI,EAAE;gBACJ,GAAG,cAAc;gBACjB,WAAW,EAAE,cAAc;gBAC3B,YAAY;gBACZ,YAAY;aACb;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AAxEY,4CAAgB;2BAAhB,gBAAgB;IAP5B,IAAA,mBAAU,GAAE;IACZ,IAAA,aAAI,EAAC;QACJ,QAAQ,EAAE;YACR,WAAW,EAAE,mGAAmG;SACjH;QACD,MAAM,EAAE,sBAAsB;KAC/B,CAAC;GACW,gBAAgB,CAwE5B"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Anthropic from '@anthropic-ai/sdk';
|
|
2
|
+
import type { ToolCallsMap } from '@loopstack/common';
|
|
2
3
|
export interface ClaudeModelConfig {
|
|
3
4
|
model?: string;
|
|
4
5
|
envApiKey?: string;
|
|
@@ -15,5 +16,23 @@ export interface ClaudeToolDefinition {
|
|
|
15
16
|
description: string;
|
|
16
17
|
input_schema: Anthropic.Tool['input_schema'];
|
|
17
18
|
}
|
|
19
|
+
export interface ClaudeGenerateTextResult extends Anthropic.Message {
|
|
20
|
+
toolCalls?: ToolCallsMap;
|
|
21
|
+
}
|
|
22
|
+
export interface DelegateToolCallsResult {
|
|
23
|
+
allCompleted: boolean;
|
|
24
|
+
toolResults: DelegateToolResultEntry[];
|
|
25
|
+
message: {
|
|
26
|
+
id?: string;
|
|
27
|
+
content: Anthropic.ContentBlock[];
|
|
28
|
+
};
|
|
29
|
+
pendingCount: number;
|
|
30
|
+
}
|
|
31
|
+
export interface DelegateToolResultEntry {
|
|
32
|
+
type: 'tool_result';
|
|
33
|
+
tool_use_id: string;
|
|
34
|
+
content?: string;
|
|
35
|
+
is_error?: boolean;
|
|
36
|
+
}
|
|
18
37
|
export { default as Anthropic } from '@anthropic-ai/sdk';
|
|
19
38
|
//# sourceMappingURL=claude.types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude.types.d.ts","sourceRoot":"","sources":["../../src/types/claude.types.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"claude.types.d.ts","sourceRoot":"","sources":["../../src/types/claude.types.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAC1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAKtD,MAAM,WAAW,iBAAiB;IAEhC,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAKD,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,SAAS,CAAC,YAAY,EAAE,CAAC;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,SAAS,CAAC,IAAI,EAAE,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,SAAS,CAAC,mBAAmB,CAAC,aAAa,CAAC,CAAC;CAC3D;AAKD,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,SAAS,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;CAC9C;AAMD,MAAM,WAAW,wBAAyB,SAAQ,SAAS,CAAC,OAAO;IACjE,SAAS,CAAC,EAAE,YAAY,CAAC;CAC1B;AAKD,MAAM,WAAW,uBAAuB;IACtC,YAAY,EAAE,OAAO,CAAC;IACtB,WAAW,EAAE,uBAAuB,EAAE,CAAC;IACvC,OAAO,EAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,SAAS,CAAC,YAAY,EAAE,CAAA;KAAE,CAAC;IAC5D,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,aAAa,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAGD,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude.types.js","sourceRoot":"","sources":["../../src/types/claude.types.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"claude.types.js","sourceRoot":"","sources":["../../src/types/claude.types.ts"],"names":[],"mappings":";;;;;;AA2DA,yCAAyD;AAAhD,iHAAA,OAAO,OAAa"}
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"loopstack",
|
|
11
11
|
"tool"
|
|
12
12
|
],
|
|
13
|
-
"version": "0.
|
|
13
|
+
"version": "0.22.1",
|
|
14
14
|
"license": "Apache-2.0",
|
|
15
15
|
"author": {
|
|
16
16
|
"name": "Jakob Klippel",
|
|
@@ -31,12 +31,12 @@
|
|
|
31
31
|
"watch": "nest build --watch"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@anthropic-ai/sdk": "^0.
|
|
35
|
-
"@loopstack/common": "^0.
|
|
36
|
-
"@loopstack/core": "^0.
|
|
37
|
-
"@nestjs/common": "^11.1.
|
|
38
|
-
"@nestjs/config": "^4.0.
|
|
39
|
-
"@nestjs/core": "^11.1.
|
|
34
|
+
"@anthropic-ai/sdk": "^0.88.0",
|
|
35
|
+
"@loopstack/common": "^0.25.1",
|
|
36
|
+
"@loopstack/core": "^0.25.1",
|
|
37
|
+
"@nestjs/common": "^11.1.19",
|
|
38
|
+
"@nestjs/config": "^4.0.4",
|
|
39
|
+
"@nestjs/core": "^11.1.19",
|
|
40
40
|
"zod": "^4.3.6"
|
|
41
41
|
},
|
|
42
42
|
"files": [
|
|
@@ -52,7 +52,12 @@
|
|
|
52
52
|
"rootDir": "src",
|
|
53
53
|
"testRegex": ".*\\.spec\\.ts$",
|
|
54
54
|
"transform": {
|
|
55
|
-
"^.+\\.ts$":
|
|
55
|
+
"^.+\\.ts$": [
|
|
56
|
+
"ts-jest",
|
|
57
|
+
{
|
|
58
|
+
"tsconfig": "tsconfig.spec.json"
|
|
59
|
+
}
|
|
60
|
+
]
|
|
56
61
|
},
|
|
57
62
|
"collectCoverageFrom": [
|
|
58
63
|
"**/*.(t|j)s"
|
package/src/claude.module.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Module } from '@nestjs/common';
|
|
2
2
|
import { LoopCoreModule } from '@loopstack/core';
|
|
3
|
-
import { ClaudeMessageDocument } from './documents';
|
|
4
3
|
import { ClaudeClientService, ClaudeMessagesHelperService, ClaudeToolsHelperService } from './services';
|
|
5
4
|
import {
|
|
6
5
|
ClaudeGenerateDocument,
|
|
@@ -24,17 +23,7 @@ import {
|
|
|
24
23
|
ClaudeGenerateDocument,
|
|
25
24
|
DelegateToolCalls,
|
|
26
25
|
UpdateToolResult,
|
|
27
|
-
|
|
28
|
-
// documents
|
|
29
|
-
ClaudeMessageDocument,
|
|
30
|
-
],
|
|
31
|
-
exports: [
|
|
32
|
-
ClaudeGenerateText,
|
|
33
|
-
ClaudeGenerateObject,
|
|
34
|
-
ClaudeGenerateDocument,
|
|
35
|
-
DelegateToolCalls,
|
|
36
|
-
UpdateToolResult,
|
|
37
|
-
ClaudeMessageDocument,
|
|
38
26
|
],
|
|
27
|
+
exports: [ClaudeGenerateText, ClaudeGenerateObject, ClaudeGenerateDocument, DelegateToolCalls, UpdateToolResult],
|
|
39
28
|
})
|
|
40
29
|
export class ClaudeModule {}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Injectable } from '@nestjs/common';
|
|
2
1
|
import { z } from 'zod';
|
|
3
|
-
import { Document
|
|
2
|
+
import { Document } from '@loopstack/common';
|
|
4
3
|
|
|
5
4
|
export const ClaudeMessageDocumentSchema = z.object({
|
|
6
5
|
role: z.enum(['user', 'assistant']),
|
|
@@ -10,17 +9,12 @@ export const ClaudeMessageDocumentSchema = z.object({
|
|
|
10
9
|
|
|
11
10
|
export type ClaudeMessageDocumentContentType = z.infer<typeof ClaudeMessageDocumentSchema>;
|
|
12
11
|
|
|
13
|
-
@Injectable()
|
|
14
12
|
@Document({
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
description: 'Claude Message Document. Stores messages in Anthropic native format.',
|
|
18
|
-
},
|
|
19
|
-
configFile: __dirname + '/claude-message-document.yaml',
|
|
13
|
+
schema: ClaudeMessageDocumentSchema,
|
|
14
|
+
uiConfig: __dirname + '/claude-message-document.yaml',
|
|
20
15
|
})
|
|
21
16
|
export class ClaudeMessageDocument {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
content: z.infer<typeof ClaudeMessageDocumentSchema>;
|
|
17
|
+
role: 'user' | 'assistant';
|
|
18
|
+
content: string | any[];
|
|
19
|
+
toolResults?: any[];
|
|
26
20
|
}
|
package/src/index.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Injectable } from '@nestjs/common';
|
|
|
3
3
|
import { toJSONSchema } from 'zod';
|
|
4
4
|
import { ToolInterface, WorkflowInterface, getBlockArgsSchema, getBlockConfig } from '@loopstack/common';
|
|
5
5
|
import { getBlockTool } from '@loopstack/common';
|
|
6
|
-
import { WorkflowType } from '@loopstack/contracts/
|
|
6
|
+
import { WorkflowType } from '@loopstack/contracts/types';
|
|
7
7
|
|
|
8
8
|
@Injectable()
|
|
9
9
|
export class ClaudeToolsHelperService {
|
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
InjectTool,
|
|
3
|
-
Input,
|
|
4
|
-
RunContext,
|
|
5
|
-
Tool,
|
|
6
|
-
ToolInterface,
|
|
7
|
-
ToolResult,
|
|
8
|
-
WorkflowInterface,
|
|
9
|
-
WorkflowMetadataInterface,
|
|
10
|
-
getBlockTool,
|
|
11
|
-
} from '@loopstack/common';
|
|
12
|
-
import { CreateDocument } from '@loopstack/core';
|
|
1
|
+
import { BaseTool, InjectTool, Tool, ToolResult } from '@loopstack/common';
|
|
13
2
|
import {
|
|
14
3
|
ClaudeGenerateObject,
|
|
15
4
|
ClaudeGenerateObjectArgsType,
|
|
@@ -17,49 +6,23 @@ import {
|
|
|
17
6
|
} from './claude-generate-object.tool';
|
|
18
7
|
|
|
19
8
|
@Tool({
|
|
20
|
-
|
|
9
|
+
uiConfig: {
|
|
21
10
|
description: 'Generates a structured object using the Anthropic Claude API and creates it as a document',
|
|
22
11
|
},
|
|
12
|
+
schema: ClaudeGenerateObjectSchema,
|
|
23
13
|
})
|
|
24
|
-
export class ClaudeGenerateDocument
|
|
14
|
+
export class ClaudeGenerateDocument extends BaseTool {
|
|
25
15
|
@InjectTool() private claudeGenerateObject!: ClaudeGenerateObject;
|
|
26
|
-
@InjectTool() private createDocument!: CreateDocument;
|
|
27
|
-
|
|
28
|
-
@Input({
|
|
29
|
-
schema: ClaudeGenerateObjectSchema,
|
|
30
|
-
})
|
|
31
|
-
args: ClaudeGenerateObjectArgsType;
|
|
32
|
-
|
|
33
|
-
private getRequiredTool(name: string): ToolInterface {
|
|
34
|
-
const tool = getBlockTool<ToolInterface>(this, name);
|
|
35
|
-
if (tool === undefined) {
|
|
36
|
-
throw new Error(`Tool "${name}" is not available`);
|
|
37
|
-
}
|
|
38
|
-
return tool;
|
|
39
|
-
}
|
|
40
16
|
|
|
41
|
-
async
|
|
42
|
-
args
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const generateResult = await this.getRequiredTool('claudeGenerateObject').execute(args, ctx, parent, metadata);
|
|
48
|
-
const documentResult = await this.getRequiredTool('createDocument').execute(
|
|
49
|
-
{
|
|
50
|
-
id: args.response.id,
|
|
51
|
-
document: args.response.document,
|
|
52
|
-
update: {
|
|
53
|
-
content: generateResult.data as unknown,
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
ctx,
|
|
57
|
-
parent,
|
|
58
|
-
metadata,
|
|
59
|
-
);
|
|
17
|
+
async call(args: ClaudeGenerateObjectArgsType): Promise<ToolResult> {
|
|
18
|
+
const generateResult = await this.claudeGenerateObject.call(args);
|
|
19
|
+
const entity = await this.repository.save(args.response.document, generateResult.data as Record<string, unknown>, {
|
|
20
|
+
id: args.response.id,
|
|
21
|
+
validate: 'skip',
|
|
22
|
+
});
|
|
60
23
|
|
|
61
24
|
return {
|
|
62
|
-
|
|
25
|
+
data: entity,
|
|
63
26
|
metadata: generateResult.metadata,
|
|
64
27
|
};
|
|
65
28
|
}
|