@dxos/assistant 0.8.2-main.2f9c567 → 0.8.2-main.30e4dbb
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/lib/browser/{chunk-OLO6SVOL.mjs → chunk-YSYP7S4W.mjs} +693 -229
- package/dist/lib/browser/chunk-YSYP7S4W.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +4 -443
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +42 -1
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node/{chunk-CI5Q7FBG.cjs → chunk-FTIDW4BA.cjs} +714 -257
- package/dist/lib/node/chunk-FTIDW4BA.cjs.map +7 -0
- package/dist/lib/node/index.cjs +34 -470
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +49 -9
- package/dist/lib/node/testing/index.cjs.map +4 -4
- package/dist/lib/node-esm/{chunk-Y3SYOFFJ.mjs → chunk-GCJNPQDJ.mjs} +693 -229
- package/dist/lib/node-esm/chunk-GCJNPQDJ.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +4 -443
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +42 -1
- package/dist/lib/node-esm/testing/index.mjs.map +4 -4
- package/dist/types/src/ai-service/parser.d.ts.map +1 -1
- package/dist/types/src/ai-service/stream.d.ts.map +1 -1
- package/dist/types/src/ai-service/testing/test-stream.d.ts.map +1 -1
- package/dist/types/src/ai-service/types.d.ts.map +1 -1
- package/dist/types/src/ai-service/util/sse.d.ts.map +1 -1
- package/dist/types/src/{conversation → experimental/conversation}/conversation.d.ts +2 -18
- package/dist/types/src/experimental/conversation/conversation.d.ts.map +1 -0
- package/dist/types/src/experimental/conversation/conversation.test.d.ts.map +1 -0
- package/dist/types/src/experimental/conversation/index.d.ts.map +1 -0
- package/dist/types/src/experimental/conversation/types.d.ts.map +1 -0
- package/dist/types/src/experimental/cypher/ast.d.ts.map +1 -0
- package/dist/types/src/experimental/cypher/combinators.d.ts.map +1 -0
- package/dist/types/src/experimental/cypher/combinators.test.d.ts.map +1 -0
- package/dist/types/src/experimental/cypher/echo-data-source.d.ts.map +1 -0
- package/dist/types/src/experimental/cypher/execution-plan.d.ts.map +1 -0
- package/dist/types/src/experimental/cypher/execution-plan.test.d.ts.map +1 -0
- package/dist/types/src/experimental/cypher/index.d.ts.map +1 -0
- package/dist/types/src/experimental/cypher/parjs.d.ts.map +1 -0
- package/dist/types/src/experimental/cypher/parser.d.ts.map +1 -0
- package/dist/types/src/experimental/cypher/query-executor.d.ts.map +1 -0
- package/dist/types/src/experimental/cypher/query-executor.test.d.ts.map +1 -0
- package/dist/types/src/experimental/cypher/schema.d.ts.map +1 -0
- package/dist/types/src/experimental/cypher/schema.test.d.ts.map +1 -0
- package/dist/types/src/experimental/index.d.ts +3 -0
- package/dist/types/src/experimental/index.d.ts.map +1 -0
- package/dist/types/src/experimental/ner/ner.test.d.ts +2 -0
- package/dist/types/src/experimental/ner/ner.test.d.ts.map +1 -0
- package/dist/types/src/experimental/research/exa.d.ts +6 -0
- package/dist/types/src/experimental/research/exa.d.ts.map +1 -0
- package/dist/types/src/experimental/research/research.test.d.ts +2 -0
- package/dist/types/src/experimental/research/research.test.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +1 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/session/index.d.ts +1 -0
- package/dist/types/src/session/index.d.ts.map +1 -1
- package/dist/types/src/session/session.d.ts +1 -0
- package/dist/types/src/session/session.d.ts.map +1 -1
- package/dist/types/src/session/tools.d.ts +18 -0
- package/dist/types/src/session/tools.d.ts.map +1 -0
- package/dist/types/src/session/version-pin.d.ts +5 -0
- package/dist/types/src/session/version-pin.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +1 -0
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/logger.d.ts +1 -1
- package/dist/types/src/testing/logger.d.ts.map +1 -1
- package/dist/types/src/testing/ollama.d.ts.map +1 -1
- package/dist/types/src/testing/printer.d.ts +6 -0
- package/dist/types/src/testing/printer.d.ts.map +1 -0
- package/dist/types/src/testing/query-promts.d.ts +1 -1
- package/dist/types/src/testing/query-promts.d.ts.map +1 -1
- package/dist/types/src/testing/test-data.d.ts +1 -1
- package/dist/types/src/testing/test-data.d.ts.map +1 -1
- package/dist/types/src/util/trim.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +19 -14
- package/src/ai-service/ollama-client.ts +1 -1
- package/src/bin/chat.ts +1 -1
- package/src/{conversation → experimental/conversation}/conversation.test.ts +2 -2
- package/src/{conversation → experimental/conversation}/conversation.ts +3 -112
- package/src/{cypher → experimental/cypher}/query-executor.test.ts +1 -1
- package/src/{cypher → experimental/cypher}/schema.test.ts +1 -1
- package/src/{cypher → experimental/cypher}/schema.ts +1 -1
- package/src/experimental/index.ts +6 -0
- package/src/experimental/ner/ner.test.ts +163 -0
- package/src/experimental/research/exa.ts +38 -0
- package/src/experimental/research/instructions.tpl +64 -0
- package/src/experimental/research/research.test.ts +263 -0
- package/src/index.ts +3 -2
- package/src/session/index.ts +1 -0
- package/src/session/session.test.ts +6 -41
- package/src/session/session.ts +11 -1
- package/src/session/tools.ts +117 -0
- package/src/session/version-pin.ts +6 -0
- package/src/testing/index.ts +1 -0
- package/src/testing/logger.ts +1 -1
- package/src/testing/printer.ts +41 -0
- package/src/testing/query-promts.ts +1 -1
- package/src/testing/query.test.ts +1 -2
- package/src/testing/test-data.ts +1 -1
- package/src/typedefs.d.ts +8 -0
- package/dist/lib/browser/chunk-OLO6SVOL.mjs.map +0 -7
- package/dist/lib/node/chunk-CI5Q7FBG.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-Y3SYOFFJ.mjs.map +0 -7
- package/dist/types/src/conversation/conversation.d.ts.map +0 -1
- package/dist/types/src/conversation/conversation.test.d.ts.map +0 -1
- package/dist/types/src/conversation/index.d.ts.map +0 -1
- package/dist/types/src/conversation/types.d.ts.map +0 -1
- package/dist/types/src/cypher/ast.d.ts.map +0 -1
- package/dist/types/src/cypher/combinators.d.ts.map +0 -1
- package/dist/types/src/cypher/combinators.test.d.ts.map +0 -1
- package/dist/types/src/cypher/echo-data-source.d.ts.map +0 -1
- package/dist/types/src/cypher/execution-plan.d.ts.map +0 -1
- package/dist/types/src/cypher/execution-plan.test.d.ts.map +0 -1
- package/dist/types/src/cypher/index.d.ts.map +0 -1
- package/dist/types/src/cypher/parjs.d.ts.map +0 -1
- package/dist/types/src/cypher/parser.d.ts.map +0 -1
- package/dist/types/src/cypher/query-executor.d.ts.map +0 -1
- package/dist/types/src/cypher/query-executor.test.d.ts.map +0 -1
- package/dist/types/src/cypher/schema.d.ts.map +0 -1
- package/dist/types/src/cypher/schema.test.d.ts.map +0 -1
- /package/dist/types/src/{conversation → experimental/conversation}/conversation.test.d.ts +0 -0
- /package/dist/types/src/{conversation → experimental/conversation}/index.d.ts +0 -0
- /package/dist/types/src/{conversation → experimental/conversation}/types.d.ts +0 -0
- /package/dist/types/src/{cypher → experimental/cypher}/ast.d.ts +0 -0
- /package/dist/types/src/{cypher → experimental/cypher}/combinators.d.ts +0 -0
- /package/dist/types/src/{cypher → experimental/cypher}/combinators.test.d.ts +0 -0
- /package/dist/types/src/{cypher → experimental/cypher}/echo-data-source.d.ts +0 -0
- /package/dist/types/src/{cypher → experimental/cypher}/execution-plan.d.ts +0 -0
- /package/dist/types/src/{cypher → experimental/cypher}/execution-plan.test.d.ts +0 -0
- /package/dist/types/src/{cypher → experimental/cypher}/index.d.ts +0 -0
- /package/dist/types/src/{cypher → experimental/cypher}/parjs.d.ts +0 -0
- /package/dist/types/src/{cypher → experimental/cypher}/parser.d.ts +0 -0
- /package/dist/types/src/{cypher → experimental/cypher}/query-executor.d.ts +0 -0
- /package/dist/types/src/{cypher → experimental/cypher}/query-executor.test.d.ts +0 -0
- /package/dist/types/src/{cypher → experimental/cypher}/schema.d.ts +0 -0
- /package/dist/types/src/{cypher → experimental/cypher}/schema.test.d.ts +0 -0
- /package/src/{conversation → experimental/conversation}/index.ts +0 -0
- /package/src/{conversation → experimental/conversation}/types.ts +0 -0
- /package/src/{cypher → experimental/cypher}/ast.ts +0 -0
- /package/src/{cypher → experimental/cypher}/combinators.test.ts +0 -0
- /package/src/{cypher → experimental/cypher}/combinators.ts +0 -0
- /package/src/{cypher → experimental/cypher}/echo-data-source.ts +0 -0
- /package/src/{cypher → experimental/cypher}/execution-plan.test.ts +0 -0
- /package/src/{cypher → experimental/cypher}/execution-plan.ts +0 -0
- /package/src/{cypher → experimental/cypher}/index.ts +0 -0
- /package/src/{cypher → experimental/cypher}/parjs-shims.d.ts +0 -0
- /package/src/{cypher → experimental/cypher}/parjs.ts +0 -0
- /package/src/{cypher → experimental/cypher}/parser.ts +0 -0
- /package/src/{cypher → experimental/cypher}/query-executor.ts +0 -0
|
@@ -26,9 +26,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var
|
|
30
|
-
__export(
|
|
29
|
+
var chunk_FTIDW4BA_exports = {};
|
|
30
|
+
__export(chunk_FTIDW4BA_exports, {
|
|
31
31
|
AIServiceEdgeClient: () => AIServiceEdgeClient,
|
|
32
|
+
AIServiecOverloadedError: () => AIServiecOverloadedError,
|
|
33
|
+
AISession: () => AISession,
|
|
32
34
|
DEFAULT_EDGE_MODEL: () => DEFAULT_EDGE_MODEL,
|
|
33
35
|
DEFAULT_EDGE_MODELS: () => DEFAULT_EDGE_MODELS,
|
|
34
36
|
DEFAULT_OLLAMA_ENDPOINT: () => DEFAULT_OLLAMA_ENDPOINT,
|
|
@@ -44,6 +46,7 @@ __export(chunk_CI5Q7FBG_exports, {
|
|
|
44
46
|
OllamaClient: () => OllamaClient,
|
|
45
47
|
StreamTransform: () => StreamTransform,
|
|
46
48
|
ToolTypes: () => ToolTypes,
|
|
49
|
+
VersionPin: () => VersionPin,
|
|
47
50
|
createArtifactElement: () => createArtifactElement,
|
|
48
51
|
createGenerationStream: () => createGenerationStream,
|
|
49
52
|
emitMessageAsEvents: () => emitMessageAsEvents,
|
|
@@ -60,7 +63,7 @@ __export(chunk_CI5Q7FBG_exports, {
|
|
|
60
63
|
runTools: () => runTools,
|
|
61
64
|
trim: () => trim
|
|
62
65
|
});
|
|
63
|
-
module.exports = __toCommonJS(
|
|
66
|
+
module.exports = __toCommonJS(chunk_FTIDW4BA_exports);
|
|
64
67
|
var import_async = require("@dxos/async");
|
|
65
68
|
var import_log = require("@dxos/log");
|
|
66
69
|
var import_invariant = require("@dxos/invariant");
|
|
@@ -72,28 +75,41 @@ var import_echo_schema = require("@dxos/echo-schema");
|
|
|
72
75
|
var import_invariant2 = require("@dxos/invariant");
|
|
73
76
|
var import_log3 = require("@dxos/log");
|
|
74
77
|
var import_effect2 = require("effect");
|
|
75
|
-
var
|
|
78
|
+
var import_echo_db = require("@dxos/echo-db");
|
|
76
79
|
var import_echo_schema2 = require("@dxos/echo-schema");
|
|
80
|
+
var import_effect3 = require("effect");
|
|
81
|
+
var import_artifact3 = require("@dxos/artifact");
|
|
82
|
+
var import_async2 = require("@dxos/async");
|
|
83
|
+
var import_echo_db2 = require("@dxos/echo-db");
|
|
84
|
+
var import_echo_schema3 = require("@dxos/echo-schema");
|
|
77
85
|
var import_invariant3 = require("@dxos/invariant");
|
|
78
86
|
var import_log4 = require("@dxos/log");
|
|
79
|
-
var
|
|
87
|
+
var import_effect4 = require("effect");
|
|
80
88
|
var import_artifact4 = require("@dxos/artifact");
|
|
81
|
-
var
|
|
82
|
-
var import_echo_schema3 = require("@dxos/echo-schema");
|
|
89
|
+
var import_echo_schema4 = require("@dxos/echo-schema");
|
|
83
90
|
var import_invariant4 = require("@dxos/invariant");
|
|
84
91
|
var import_log5 = require("@dxos/log");
|
|
92
|
+
var import_artifact5 = require("@dxos/artifact");
|
|
93
|
+
var import_async3 = require("@dxos/async");
|
|
94
|
+
var import_echo_schema5 = require("@dxos/echo-schema");
|
|
95
|
+
var import_invariant5 = require("@dxos/invariant");
|
|
96
|
+
var import_log6 = require("@dxos/log");
|
|
85
97
|
var import_util = require("@dxos/util");
|
|
98
|
+
var P = __toESM(require("parsimmon"));
|
|
99
|
+
var import_echo_schema6 = require("@dxos/echo-schema");
|
|
100
|
+
var import_invariant6 = require("@dxos/invariant");
|
|
101
|
+
var import_log7 = require("@dxos/log");
|
|
86
102
|
var import_parjs = require("#parjs");
|
|
87
|
-
var
|
|
103
|
+
var import_log8 = require("@dxos/log");
|
|
88
104
|
var import_util2 = require("@dxos/util");
|
|
89
|
-
var
|
|
90
|
-
var
|
|
105
|
+
var import_invariant7 = require("@dxos/invariant");
|
|
106
|
+
var import_log9 = require("@dxos/log");
|
|
91
107
|
var import_debug = require("@dxos/debug");
|
|
92
|
-
var
|
|
108
|
+
var import_echo_schema7 = require("@dxos/echo-schema");
|
|
93
109
|
var import_debug2 = require("@dxos/debug");
|
|
94
|
-
var
|
|
95
|
-
var
|
|
96
|
-
var
|
|
110
|
+
var import_echo_db3 = require("@dxos/echo-db");
|
|
111
|
+
var import_echo_schema8 = require("@dxos/echo-schema");
|
|
112
|
+
var import_log10 = require("@dxos/log");
|
|
97
113
|
var DEFAULT_EDGE_MODEL = "@anthropic/claude-3-5-sonnet-20241022";
|
|
98
114
|
var DEFAULT_EDGE_MODELS = [
|
|
99
115
|
// AI Gateway.
|
|
@@ -608,178 +624,12 @@ var GenerateResponse = import_effect.Schema.Struct({
|
|
|
608
624
|
*/
|
|
609
625
|
tokenCount: import_effect.Schema.optional(import_effect.Schema.Number)
|
|
610
626
|
});
|
|
611
|
-
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/experimental/assistant/src/
|
|
612
|
-
var runLLM = async (params) => {
|
|
613
|
-
let conversationResult = null;
|
|
614
|
-
const history = params.history ?? [];
|
|
615
|
-
const generate = async () => {
|
|
616
|
-
(0, import_log3.log)("llm generate", {
|
|
617
|
-
tools: params.tools
|
|
618
|
-
}, {
|
|
619
|
-
F: __dxlog_file3,
|
|
620
|
-
L: 44,
|
|
621
|
-
S: void 0,
|
|
622
|
-
C: (f, a) => f(...a)
|
|
623
|
-
});
|
|
624
|
-
const beginTs = Date.now();
|
|
625
|
-
const stream = await params.client.execStream({
|
|
626
|
-
model: params.model,
|
|
627
|
-
history,
|
|
628
|
-
systemPrompt: params.system,
|
|
629
|
-
tools: params.tools
|
|
630
|
-
});
|
|
631
|
-
for await (const event of stream) {
|
|
632
|
-
params.logger?.(event);
|
|
633
|
-
}
|
|
634
|
-
await stream.complete();
|
|
635
|
-
const messages = [];
|
|
636
|
-
const message = messages.at(-1);
|
|
637
|
-
(0, import_invariant2.invariant)(message, void 0, {
|
|
638
|
-
F: __dxlog_file3,
|
|
639
|
-
L: 61,
|
|
640
|
-
S: void 0,
|
|
641
|
-
A: [
|
|
642
|
-
"message",
|
|
643
|
-
""
|
|
644
|
-
]
|
|
645
|
-
});
|
|
646
|
-
(0, import_log3.log)("llm result", {
|
|
647
|
-
time: Date.now() - beginTs,
|
|
648
|
-
message
|
|
649
|
-
}, {
|
|
650
|
-
F: __dxlog_file3,
|
|
651
|
-
L: 63,
|
|
652
|
-
S: void 0,
|
|
653
|
-
C: (f, a) => f(...a)
|
|
654
|
-
});
|
|
655
|
-
(0, import_invariant2.invariant)(message, void 0, {
|
|
656
|
-
F: __dxlog_file3,
|
|
657
|
-
L: 64,
|
|
658
|
-
S: void 0,
|
|
659
|
-
A: [
|
|
660
|
-
"message",
|
|
661
|
-
""
|
|
662
|
-
]
|
|
663
|
-
});
|
|
664
|
-
params.logger?.({
|
|
665
|
-
type: "message",
|
|
666
|
-
message
|
|
667
|
-
});
|
|
668
|
-
history.push(...messages.map((message2) => ({
|
|
669
|
-
...message2,
|
|
670
|
-
content: message2.content.filter((block) => block.type !== "image")
|
|
671
|
-
})));
|
|
672
|
-
const isToolUse2 = message.content.at(-1)?.type === "tool_use";
|
|
673
|
-
if (isToolUse2) {
|
|
674
|
-
const toolCalls = message.content.filter((block) => block.type === "tool_use");
|
|
675
|
-
(0, import_invariant2.invariant)(toolCalls.length === 1, void 0, {
|
|
676
|
-
F: __dxlog_file3,
|
|
677
|
-
L: 75,
|
|
678
|
-
S: void 0,
|
|
679
|
-
A: [
|
|
680
|
-
"toolCalls.length === 1",
|
|
681
|
-
""
|
|
682
|
-
]
|
|
683
|
-
});
|
|
684
|
-
const toolCall = toolCalls[0];
|
|
685
|
-
const tool = params.tools.find((tool2) => tool2.name === toolCall.name);
|
|
686
|
-
if (!tool) {
|
|
687
|
-
throw new Error(`Tool not found: ${toolCall.name}`);
|
|
688
|
-
}
|
|
689
|
-
(0, import_invariant2.invariant)(tool.execute, void 0, {
|
|
690
|
-
F: __dxlog_file3,
|
|
691
|
-
L: 82,
|
|
692
|
-
S: void 0,
|
|
693
|
-
A: [
|
|
694
|
-
"tool.execute",
|
|
695
|
-
""
|
|
696
|
-
]
|
|
697
|
-
});
|
|
698
|
-
const toolResult = await tool.execute(toolCall.input);
|
|
699
|
-
switch (toolResult.kind) {
|
|
700
|
-
case "error": {
|
|
701
|
-
import_log3.log.warn("tool error", {
|
|
702
|
-
message: toolResult.message
|
|
703
|
-
}, {
|
|
704
|
-
F: __dxlog_file3,
|
|
705
|
-
L: 86,
|
|
706
|
-
S: void 0,
|
|
707
|
-
C: (f, a) => f(...a)
|
|
708
|
-
});
|
|
709
|
-
const resultMessage = {
|
|
710
|
-
id: import_echo_schema.ObjectId.random(),
|
|
711
|
-
role: "user",
|
|
712
|
-
content: [
|
|
713
|
-
{
|
|
714
|
-
type: "tool_result",
|
|
715
|
-
toolUseId: toolCall.id,
|
|
716
|
-
content: toolResult.message,
|
|
717
|
-
isError: true
|
|
718
|
-
}
|
|
719
|
-
]
|
|
720
|
-
};
|
|
721
|
-
params.logger?.({
|
|
722
|
-
type: "message",
|
|
723
|
-
message: resultMessage
|
|
724
|
-
});
|
|
725
|
-
history.push(resultMessage);
|
|
726
|
-
return true;
|
|
727
|
-
}
|
|
728
|
-
case "success": {
|
|
729
|
-
(0, import_log3.log)("tool success", {
|
|
730
|
-
result: toolResult.result
|
|
731
|
-
}, {
|
|
732
|
-
F: __dxlog_file3,
|
|
733
|
-
L: 106,
|
|
734
|
-
S: void 0,
|
|
735
|
-
C: (f, a) => f(...a)
|
|
736
|
-
});
|
|
737
|
-
const resultMessage = {
|
|
738
|
-
id: import_echo_schema.ObjectId.random(),
|
|
739
|
-
role: "user",
|
|
740
|
-
content: [
|
|
741
|
-
{
|
|
742
|
-
type: "tool_result",
|
|
743
|
-
toolUseId: toolCall.id,
|
|
744
|
-
content: JSON.stringify(toolResult.result)
|
|
745
|
-
}
|
|
746
|
-
]
|
|
747
|
-
};
|
|
748
|
-
params.logger?.({
|
|
749
|
-
type: "message",
|
|
750
|
-
message: resultMessage
|
|
751
|
-
});
|
|
752
|
-
history.push(resultMessage);
|
|
753
|
-
return true;
|
|
754
|
-
}
|
|
755
|
-
case "break": {
|
|
756
|
-
(0, import_log3.log)("tool break", {
|
|
757
|
-
result: toolResult.result
|
|
758
|
-
}, {
|
|
759
|
-
F: __dxlog_file3,
|
|
760
|
-
L: 125,
|
|
761
|
-
S: void 0,
|
|
762
|
-
C: (f, a) => f(...a)
|
|
763
|
-
});
|
|
764
|
-
conversationResult = toolResult.result;
|
|
765
|
-
return false;
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
}
|
|
769
|
-
return false;
|
|
770
|
-
};
|
|
771
|
-
while (await generate()) {
|
|
772
|
-
}
|
|
773
|
-
return {
|
|
774
|
-
result: conversationResult,
|
|
775
|
-
history
|
|
776
|
-
};
|
|
777
|
-
};
|
|
627
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/experimental/assistant/src/session/tools.ts";
|
|
778
628
|
var isToolUse = (message, { onlyToolNames } = {}) => {
|
|
779
629
|
const block = message.content.at(-1);
|
|
780
630
|
(0, import_invariant2.invariant)(block, void 0, {
|
|
781
631
|
F: __dxlog_file3,
|
|
782
|
-
L:
|
|
632
|
+
L: 12,
|
|
783
633
|
S: void 0,
|
|
784
634
|
A: [
|
|
785
635
|
"block",
|
|
@@ -792,7 +642,7 @@ var runTools = async ({ message, tools, extensions }) => {
|
|
|
792
642
|
const toolCalls = message.content.filter((block) => block.type === "tool_use");
|
|
793
643
|
(0, import_invariant2.invariant)(toolCalls.length === 1, void 0, {
|
|
794
644
|
F: __dxlog_file3,
|
|
795
|
-
L:
|
|
645
|
+
L: 34,
|
|
796
646
|
S: void 0,
|
|
797
647
|
A: [
|
|
798
648
|
"toolCalls.length === 1",
|
|
@@ -822,7 +672,7 @@ var runTools = async ({ message, tools, extensions }) => {
|
|
|
822
672
|
try {
|
|
823
673
|
(0, import_invariant2.invariant)(tool.execute, void 0, {
|
|
824
674
|
F: __dxlog_file3,
|
|
825
|
-
L:
|
|
675
|
+
L: 59,
|
|
826
676
|
S: void 0,
|
|
827
677
|
A: [
|
|
828
678
|
"tool.execute",
|
|
@@ -837,7 +687,7 @@ var runTools = async ({ message, tools, extensions }) => {
|
|
|
837
687
|
error
|
|
838
688
|
}, {
|
|
839
689
|
F: __dxlog_file3,
|
|
840
|
-
L:
|
|
690
|
+
L: 62,
|
|
841
691
|
S: void 0,
|
|
842
692
|
C: (f, a) => f(...a)
|
|
843
693
|
});
|
|
@@ -849,7 +699,7 @@ var runTools = async ({ message, tools, extensions }) => {
|
|
|
849
699
|
message: toolResult.message
|
|
850
700
|
}, {
|
|
851
701
|
F: __dxlog_file3,
|
|
852
|
-
L:
|
|
702
|
+
L: 68,
|
|
853
703
|
S: void 0,
|
|
854
704
|
C: (f, a) => f(...a)
|
|
855
705
|
});
|
|
@@ -874,7 +724,7 @@ var runTools = async ({ message, tools, extensions }) => {
|
|
|
874
724
|
result: toolResult.result
|
|
875
725
|
}, {
|
|
876
726
|
F: __dxlog_file3,
|
|
877
|
-
L:
|
|
727
|
+
L: 89,
|
|
878
728
|
S: void 0,
|
|
879
729
|
C: (f, a) => f(...a)
|
|
880
730
|
});
|
|
@@ -899,7 +749,7 @@ var runTools = async ({ message, tools, extensions }) => {
|
|
|
899
749
|
result: toolResult.result
|
|
900
750
|
}, {
|
|
901
751
|
F: __dxlog_file3,
|
|
902
|
-
L:
|
|
752
|
+
L: 110,
|
|
903
753
|
S: void 0,
|
|
904
754
|
C: (f, a) => f(...a)
|
|
905
755
|
});
|
|
@@ -910,6 +760,31 @@ var runTools = async ({ message, tools, extensions }) => {
|
|
|
910
760
|
}
|
|
911
761
|
}
|
|
912
762
|
};
|
|
763
|
+
var ObjectVersionSchema = import_effect2.Schema.Unknown;
|
|
764
|
+
var VersionPinSchema = import_effect2.Schema.Struct({
|
|
765
|
+
// TODO(dmaretskyi): Use Ref when those support encoding.
|
|
766
|
+
objectId: import_echo_schema2.ObjectId,
|
|
767
|
+
// TODO(dmaretskyi): Could be opaque
|
|
768
|
+
version: ObjectVersionSchema
|
|
769
|
+
});
|
|
770
|
+
var VersionPin = class extends VersionPinSchema {
|
|
771
|
+
static {
|
|
772
|
+
this.DISPOSITION = "version-pin";
|
|
773
|
+
}
|
|
774
|
+
static fromObject(object) {
|
|
775
|
+
return VersionPin.make({
|
|
776
|
+
objectId: object.id,
|
|
777
|
+
version: (0, import_echo_db.getVersion)(object)
|
|
778
|
+
});
|
|
779
|
+
}
|
|
780
|
+
static createBlock(pin) {
|
|
781
|
+
return {
|
|
782
|
+
type: "json",
|
|
783
|
+
disposition: VersionPin.DISPOSITION,
|
|
784
|
+
json: JSON.stringify(pin)
|
|
785
|
+
};
|
|
786
|
+
}
|
|
787
|
+
};
|
|
913
788
|
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/experimental/assistant/src/ai-service/ollama-client.ts";
|
|
914
789
|
var OllamaClient = class {
|
|
915
790
|
/**
|
|
@@ -944,7 +819,7 @@ var OllamaClient = class {
|
|
|
944
819
|
];
|
|
945
820
|
}
|
|
946
821
|
async *_generateStream(request, signal) {
|
|
947
|
-
(0,
|
|
822
|
+
(0, import_invariant4.invariant)(request.prompt === void 0, "Prompt must be in history", {
|
|
948
823
|
F: __dxlog_file4,
|
|
949
824
|
L: 88,
|
|
950
825
|
S: this,
|
|
@@ -1033,7 +908,7 @@ var OllamaClient = class {
|
|
|
1033
908
|
}));
|
|
1034
909
|
}
|
|
1035
910
|
}
|
|
1036
|
-
(0,
|
|
911
|
+
(0, import_log5.log)("generate request", {
|
|
1037
912
|
history: request.history,
|
|
1038
913
|
prompt: request.prompt,
|
|
1039
914
|
ollamaRequest
|
|
@@ -1059,7 +934,7 @@ var OllamaClient = class {
|
|
|
1059
934
|
}
|
|
1060
935
|
const reader = response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new OllamaDecoderStream()).getReader();
|
|
1061
936
|
try {
|
|
1062
|
-
const messageId =
|
|
937
|
+
const messageId = import_echo_schema4.ObjectId.random();
|
|
1063
938
|
yield {
|
|
1064
939
|
type: "message_start",
|
|
1065
940
|
message: {
|
|
@@ -1083,7 +958,7 @@ var OllamaClient = class {
|
|
|
1083
958
|
if (done) {
|
|
1084
959
|
break;
|
|
1085
960
|
}
|
|
1086
|
-
(0,
|
|
961
|
+
(0, import_log5.log)("ollama data", {
|
|
1087
962
|
data
|
|
1088
963
|
}, {
|
|
1089
964
|
F: __dxlog_file4,
|
|
@@ -1103,7 +978,7 @@ var OllamaClient = class {
|
|
|
1103
978
|
}
|
|
1104
979
|
if (data.message?.tool_calls && data.message?.tool_calls?.length > 0) {
|
|
1105
980
|
if (data.message.tool_calls.length > 1) {
|
|
1106
|
-
|
|
981
|
+
import_log5.log.warn("Ollama returned multiple tool calls. Only the first one will be used.", void 0, {
|
|
1107
982
|
F: __dxlog_file4,
|
|
1108
983
|
L: 261,
|
|
1109
984
|
S: this,
|
|
@@ -1119,7 +994,7 @@ var OllamaClient = class {
|
|
|
1119
994
|
index: currentBlockIndex,
|
|
1120
995
|
content: {
|
|
1121
996
|
type: "tool_use",
|
|
1122
|
-
id:
|
|
997
|
+
id: import_echo_schema4.ObjectId.random(),
|
|
1123
998
|
name: data.message.tool_calls[0].function.name,
|
|
1124
999
|
input: sanitizeToolArguments(data.message.tool_calls[0].function.arguments)
|
|
1125
1000
|
}
|
|
@@ -1208,19 +1083,19 @@ var sanitizeToolArguments = (args) => {
|
|
|
1208
1083
|
};
|
|
1209
1084
|
var SAMPLE_IMAGE_URL = "https://images.nightcafe.studio/jobs/BNmcRhHCM1JRKoUtqSei/BNmcRhHCM1JRKoUtqSei--1--5b9rv.jpg";
|
|
1210
1085
|
var WELL_KNOWN_TOOLS = {
|
|
1211
|
-
[ToolTypes.TextToImage]: (0,
|
|
1086
|
+
[ToolTypes.TextToImage]: (0, import_artifact4.defineTool)("system", {
|
|
1212
1087
|
name: "text-to-image",
|
|
1213
1088
|
description: "Generate an image from a text prompt",
|
|
1214
|
-
schema:
|
|
1215
|
-
prompt:
|
|
1089
|
+
schema: import_effect4.Schema.Struct({
|
|
1090
|
+
prompt: import_effect4.Schema.String.annotations({
|
|
1216
1091
|
description: "The text prompt describing the image to generate"
|
|
1217
1092
|
})
|
|
1218
1093
|
}),
|
|
1219
1094
|
execute: async ({ prompt }) => {
|
|
1220
1095
|
const image = await fetch(SAMPLE_IMAGE_URL).then(async (res) => Buffer.from(await res.arrayBuffer()));
|
|
1221
1096
|
const imageBase64 = image.toString("base64");
|
|
1222
|
-
const id =
|
|
1223
|
-
return
|
|
1097
|
+
const id = import_echo_schema4.ObjectId.random();
|
|
1098
|
+
return import_artifact4.ToolResult.Success(`The generation was successful. Image ID: ${id} Prompt: ${prompt}`, [
|
|
1224
1099
|
{
|
|
1225
1100
|
type: "image",
|
|
1226
1101
|
id,
|
|
@@ -1255,12 +1130,12 @@ var OllamaDecoderStream = class extends TransformStream {
|
|
|
1255
1130
|
this._buffer = "";
|
|
1256
1131
|
}
|
|
1257
1132
|
};
|
|
1258
|
-
var ModelDoesNotSupportToolsError = class extends
|
|
1259
|
-
model:
|
|
1133
|
+
var ModelDoesNotSupportToolsError = class extends import_effect4.Schema.TaggedError()("ModelDoesNotSupportToolsError", {
|
|
1134
|
+
model: import_effect4.Schema.String
|
|
1260
1135
|
}) {
|
|
1261
1136
|
};
|
|
1262
|
-
var ModelNotFoundError = class extends
|
|
1263
|
-
model:
|
|
1137
|
+
var ModelNotFoundError = class extends import_effect4.Schema.TaggedError()("ModelNotFoundError", {
|
|
1138
|
+
model: import_effect4.Schema.String
|
|
1264
1139
|
}) {
|
|
1265
1140
|
};
|
|
1266
1141
|
var parseOllamaError = (error) => {
|
|
@@ -1378,10 +1253,10 @@ var StreamTransform = class {
|
|
|
1378
1253
|
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/experimental/assistant/src/ai-service/parser.ts";
|
|
1379
1254
|
var MixedStreamParser = class {
|
|
1380
1255
|
constructor() {
|
|
1381
|
-
this.message = new
|
|
1382
|
-
this.block = new
|
|
1383
|
-
this.update = new
|
|
1384
|
-
this.streamEvent = new
|
|
1256
|
+
this.message = new import_async3.Event();
|
|
1257
|
+
this.block = new import_async3.Event();
|
|
1258
|
+
this.update = new import_async3.Event();
|
|
1259
|
+
this.streamEvent = new import_async3.Event();
|
|
1385
1260
|
}
|
|
1386
1261
|
_emitBlock(contentBlock, streamBlock) {
|
|
1387
1262
|
const messageBlock = streamBlock ? mergeMessageBlock(contentBlock, streamBlock) : contentBlock;
|
|
@@ -1389,7 +1264,7 @@ var MixedStreamParser = class {
|
|
|
1389
1264
|
if (messageBlock.type === "text" && messageBlock.text.length === 0) {
|
|
1390
1265
|
return;
|
|
1391
1266
|
}
|
|
1392
|
-
(0,
|
|
1267
|
+
(0, import_invariant5.invariant)(this._message, void 0, {
|
|
1393
1268
|
F: __dxlog_file5,
|
|
1394
1269
|
L: 49,
|
|
1395
1270
|
S: this,
|
|
@@ -1419,7 +1294,7 @@ var MixedStreamParser = class {
|
|
|
1419
1294
|
const stack = [];
|
|
1420
1295
|
const messagesCollected = [];
|
|
1421
1296
|
for await (const event of stream) {
|
|
1422
|
-
(0,
|
|
1297
|
+
(0, import_log6.log)("streamEvent", {
|
|
1423
1298
|
event
|
|
1424
1299
|
}, {
|
|
1425
1300
|
F: __dxlog_file5,
|
|
@@ -1434,14 +1309,14 @@ var MixedStreamParser = class {
|
|
|
1434
1309
|
//
|
|
1435
1310
|
case "message_start": {
|
|
1436
1311
|
if (this._message) {
|
|
1437
|
-
|
|
1312
|
+
import_log6.log.warn("unexpected message_start", void 0, {
|
|
1438
1313
|
F: __dxlog_file5,
|
|
1439
1314
|
L: 94,
|
|
1440
1315
|
S: this,
|
|
1441
1316
|
C: (f, a) => f(...a)
|
|
1442
1317
|
});
|
|
1443
1318
|
}
|
|
1444
|
-
this._message = (0,
|
|
1319
|
+
this._message = (0, import_echo_schema5.create)(import_artifact5.Message, {
|
|
1445
1320
|
role: event.message.role,
|
|
1446
1321
|
content: [
|
|
1447
1322
|
...event.message.content
|
|
@@ -1452,7 +1327,7 @@ var MixedStreamParser = class {
|
|
|
1452
1327
|
}
|
|
1453
1328
|
case "message_delta": {
|
|
1454
1329
|
if (!this._message) {
|
|
1455
|
-
|
|
1330
|
+
import_log6.log.warn("unexpected message_delta", void 0, {
|
|
1456
1331
|
F: __dxlog_file5,
|
|
1457
1332
|
L: 104,
|
|
1458
1333
|
S: this,
|
|
@@ -1463,7 +1338,7 @@ var MixedStreamParser = class {
|
|
|
1463
1338
|
}
|
|
1464
1339
|
case "message_stop": {
|
|
1465
1340
|
if (!this._message) {
|
|
1466
|
-
|
|
1341
|
+
import_log6.log.warn("unexpected message_stop", void 0, {
|
|
1467
1342
|
F: __dxlog_file5,
|
|
1468
1343
|
L: 112,
|
|
1469
1344
|
S: this,
|
|
@@ -1480,7 +1355,7 @@ var MixedStreamParser = class {
|
|
|
1480
1355
|
//
|
|
1481
1356
|
case "content_block_start": {
|
|
1482
1357
|
if (contentBlock) {
|
|
1483
|
-
|
|
1358
|
+
import_log6.log.warn("unexpected content_block_start", {
|
|
1484
1359
|
content: contentBlock
|
|
1485
1360
|
}, {
|
|
1486
1361
|
F: __dxlog_file5,
|
|
@@ -1494,7 +1369,7 @@ var MixedStreamParser = class {
|
|
|
1494
1369
|
}
|
|
1495
1370
|
case "content_block_delta": {
|
|
1496
1371
|
if (!contentBlock) {
|
|
1497
|
-
|
|
1372
|
+
import_log6.log.warn("unexpected content_block_delta", void 0, {
|
|
1498
1373
|
F: __dxlog_file5,
|
|
1499
1374
|
L: 136,
|
|
1500
1375
|
S: this,
|
|
@@ -1509,7 +1384,7 @@ var MixedStreamParser = class {
|
|
|
1509
1384
|
case "text_delta": {
|
|
1510
1385
|
const chunks = transformer.transform(event.delta.text);
|
|
1511
1386
|
for (const chunk of chunks) {
|
|
1512
|
-
(0,
|
|
1387
|
+
(0, import_log6.log)("text_delta", {
|
|
1513
1388
|
chunk
|
|
1514
1389
|
}, {
|
|
1515
1390
|
F: __dxlog_file5,
|
|
@@ -1528,7 +1403,7 @@ var MixedStreamParser = class {
|
|
|
1528
1403
|
} else if (chunk.closing) {
|
|
1529
1404
|
if (stack.length > 0) {
|
|
1530
1405
|
const top = stack.pop();
|
|
1531
|
-
(0,
|
|
1406
|
+
(0, import_invariant5.invariant)(top && top.type === "tag", void 0, {
|
|
1532
1407
|
F: __dxlog_file5,
|
|
1533
1408
|
L: 160,
|
|
1534
1409
|
S: this,
|
|
@@ -1537,7 +1412,7 @@ var MixedStreamParser = class {
|
|
|
1537
1412
|
""
|
|
1538
1413
|
]
|
|
1539
1414
|
});
|
|
1540
|
-
(0,
|
|
1415
|
+
(0, import_log6.log)("pop", {
|
|
1541
1416
|
top
|
|
1542
1417
|
}, {
|
|
1543
1418
|
F: __dxlog_file5,
|
|
@@ -1560,7 +1435,7 @@ var MixedStreamParser = class {
|
|
|
1560
1435
|
streamBlock.content.push(chunk);
|
|
1561
1436
|
} else {
|
|
1562
1437
|
const last = streamBlock.content.at(-1);
|
|
1563
|
-
(0,
|
|
1438
|
+
(0, import_invariant5.invariant)(last, void 0, {
|
|
1564
1439
|
F: __dxlog_file5,
|
|
1565
1440
|
L: 178,
|
|
1566
1441
|
S: this,
|
|
@@ -1614,7 +1489,7 @@ var MixedStreamParser = class {
|
|
|
1614
1489
|
//
|
|
1615
1490
|
case "input_json_delta": {
|
|
1616
1491
|
if (!contentBlock) {
|
|
1617
|
-
|
|
1492
|
+
import_log6.log.warn("unexpected input_json_delta", {
|
|
1618
1493
|
contentBlock
|
|
1619
1494
|
}, {
|
|
1620
1495
|
F: __dxlog_file5,
|
|
@@ -1639,7 +1514,7 @@ var MixedStreamParser = class {
|
|
|
1639
1514
|
}
|
|
1640
1515
|
case "content_block_stop": {
|
|
1641
1516
|
if (!contentBlock) {
|
|
1642
|
-
|
|
1517
|
+
import_log6.log.warn("unexpected content_block_stop", void 0, {
|
|
1643
1518
|
F: __dxlog_file5,
|
|
1644
1519
|
L: 245,
|
|
1645
1520
|
S: this,
|
|
@@ -1661,7 +1536,7 @@ var MixedStreamParser = class {
|
|
|
1661
1536
|
}
|
|
1662
1537
|
};
|
|
1663
1538
|
var mergeMessageBlock = (contentBlock, streamBlock) => {
|
|
1664
|
-
(0,
|
|
1539
|
+
(0, import_log6.log)("mergeMessageBlock", {
|
|
1665
1540
|
contentBlock,
|
|
1666
1541
|
streamBlock
|
|
1667
1542
|
}, {
|
|
@@ -1776,6 +1651,585 @@ var mergeMessageBlock = (contentBlock, streamBlock) => {
|
|
|
1776
1651
|
}
|
|
1777
1652
|
}
|
|
1778
1653
|
};
|
|
1654
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
1655
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1656
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1657
|
+
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;
|
|
1658
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1659
|
+
}
|
|
1660
|
+
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/experimental/assistant/src/session/session.ts";
|
|
1661
|
+
var AISession = class _AISession {
|
|
1662
|
+
constructor(_options) {
|
|
1663
|
+
this._options = _options;
|
|
1664
|
+
this._parser = new MixedStreamParser();
|
|
1665
|
+
this._pending = [];
|
|
1666
|
+
this._history = [];
|
|
1667
|
+
this.message = this._parser.message;
|
|
1668
|
+
this.block = this._parser.block;
|
|
1669
|
+
this.update = this._parser.update;
|
|
1670
|
+
this.streamEvent = this._parser.streamEvent;
|
|
1671
|
+
this.userMessage = new import_async2.Event();
|
|
1672
|
+
this._parser.message.on((message) => {
|
|
1673
|
+
this._pending.push(message);
|
|
1674
|
+
});
|
|
1675
|
+
}
|
|
1676
|
+
async run(options) {
|
|
1677
|
+
const systemTools = [];
|
|
1678
|
+
switch (this._options.operationModel) {
|
|
1679
|
+
case "planning":
|
|
1680
|
+
systemTools.push(this._createQueryArtifactsTool(options.artifacts), this._createPlanningTool(options));
|
|
1681
|
+
break;
|
|
1682
|
+
case "importing":
|
|
1683
|
+
systemTools.push(this._createQueryArtifactsTool(options.artifacts), this._createRequireTool(options.artifacts, (artifactDefinitionIds) => {
|
|
1684
|
+
for (const artifactDefinitionId of artifactDefinitionIds) {
|
|
1685
|
+
requiredArtifactIds.add(artifactDefinitionId);
|
|
1686
|
+
}
|
|
1687
|
+
}));
|
|
1688
|
+
break;
|
|
1689
|
+
case "configured":
|
|
1690
|
+
break;
|
|
1691
|
+
default:
|
|
1692
|
+
throw new TypeError(`Invalid operation model: ${this._options.operationModel}`);
|
|
1693
|
+
}
|
|
1694
|
+
this._history = [
|
|
1695
|
+
...options.history
|
|
1696
|
+
];
|
|
1697
|
+
this._pending = [
|
|
1698
|
+
await this._formatUserPrompt(options.artifactDiffResolver, options.prompt, options.history)
|
|
1699
|
+
];
|
|
1700
|
+
this.userMessage.emit(this._pending.at(-1));
|
|
1701
|
+
this._stream = void 0;
|
|
1702
|
+
let error;
|
|
1703
|
+
const requiredArtifactIds = new Set(options.requiredArtifactIds ?? []);
|
|
1704
|
+
try {
|
|
1705
|
+
let more = false;
|
|
1706
|
+
do {
|
|
1707
|
+
const tools = [
|
|
1708
|
+
...systemTools,
|
|
1709
|
+
...options.tools,
|
|
1710
|
+
...options.artifacts.filter((artifact) => requiredArtifactIds.has(artifact.id)).flatMap((artifact) => artifact.tools)
|
|
1711
|
+
];
|
|
1712
|
+
(0, import_log4.log)("request", {
|
|
1713
|
+
pending: this._pending.length,
|
|
1714
|
+
history: this._history.length,
|
|
1715
|
+
tools: tools.map((tool) => tool.name)
|
|
1716
|
+
}, {
|
|
1717
|
+
F: __dxlog_file6,
|
|
1718
|
+
L: 181,
|
|
1719
|
+
S: this,
|
|
1720
|
+
C: (f, a) => f(...a)
|
|
1721
|
+
});
|
|
1722
|
+
this._stream = await options.client.execStream({
|
|
1723
|
+
...options.generationOptions ?? {},
|
|
1724
|
+
// TODO(burdon): Rename messages or separate history/message.
|
|
1725
|
+
history: [
|
|
1726
|
+
...this._history,
|
|
1727
|
+
...this._pending
|
|
1728
|
+
],
|
|
1729
|
+
tools,
|
|
1730
|
+
systemPrompt: options.systemPrompt ?? createBaseInstructions({
|
|
1731
|
+
availableArtifacts: Array.from(requiredArtifactIds),
|
|
1732
|
+
operationModel: this._options.operationModel
|
|
1733
|
+
})
|
|
1734
|
+
});
|
|
1735
|
+
await this._parser.parse(this._stream);
|
|
1736
|
+
await this._stream.complete();
|
|
1737
|
+
(0, import_log4.log)("response", {
|
|
1738
|
+
pending: this._pending
|
|
1739
|
+
}, {
|
|
1740
|
+
F: __dxlog_file6,
|
|
1741
|
+
L: 206,
|
|
1742
|
+
S: this,
|
|
1743
|
+
C: (f, a) => f(...a)
|
|
1744
|
+
});
|
|
1745
|
+
more = false;
|
|
1746
|
+
const message = this._pending.at(-1);
|
|
1747
|
+
(0, import_invariant3.invariant)(message, void 0, {
|
|
1748
|
+
F: __dxlog_file6,
|
|
1749
|
+
L: 211,
|
|
1750
|
+
S: this,
|
|
1751
|
+
A: [
|
|
1752
|
+
"message",
|
|
1753
|
+
""
|
|
1754
|
+
]
|
|
1755
|
+
});
|
|
1756
|
+
if (isToolUse(message)) {
|
|
1757
|
+
(0, import_log4.log)("tool request...", void 0, {
|
|
1758
|
+
F: __dxlog_file6,
|
|
1759
|
+
L: 213,
|
|
1760
|
+
S: this,
|
|
1761
|
+
C: (f, a) => f(...a)
|
|
1762
|
+
});
|
|
1763
|
+
const response = await runTools({
|
|
1764
|
+
message: this._pending.at(-1),
|
|
1765
|
+
tools,
|
|
1766
|
+
extensions: options.extensions ?? {}
|
|
1767
|
+
});
|
|
1768
|
+
(0, import_log4.log)("tool response", {
|
|
1769
|
+
response
|
|
1770
|
+
}, {
|
|
1771
|
+
F: __dxlog_file6,
|
|
1772
|
+
L: 220,
|
|
1773
|
+
S: this,
|
|
1774
|
+
C: (f, a) => f(...a)
|
|
1775
|
+
});
|
|
1776
|
+
switch (response.type) {
|
|
1777
|
+
case "continue": {
|
|
1778
|
+
this._pending = [
|
|
1779
|
+
...this._pending,
|
|
1780
|
+
response.message
|
|
1781
|
+
];
|
|
1782
|
+
this.userMessage.emit(response.message);
|
|
1783
|
+
more = true;
|
|
1784
|
+
break;
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
} while (more);
|
|
1789
|
+
} catch (err) {
|
|
1790
|
+
import_log4.log.catch(err, void 0, {
|
|
1791
|
+
F: __dxlog_file6,
|
|
1792
|
+
L: 232,
|
|
1793
|
+
S: this,
|
|
1794
|
+
C: (f, a) => f(...a)
|
|
1795
|
+
});
|
|
1796
|
+
if (err instanceof Error && err.message.includes("Overloaded")) {
|
|
1797
|
+
error = new AIServiecOverloadedError("AI service overloaded", {
|
|
1798
|
+
cause: err
|
|
1799
|
+
});
|
|
1800
|
+
} else {
|
|
1801
|
+
error = new Error("AI service error", {
|
|
1802
|
+
cause: err
|
|
1803
|
+
});
|
|
1804
|
+
}
|
|
1805
|
+
} finally {
|
|
1806
|
+
this._stream = void 0;
|
|
1807
|
+
}
|
|
1808
|
+
if (error) {
|
|
1809
|
+
throw error;
|
|
1810
|
+
}
|
|
1811
|
+
return this._pending;
|
|
1812
|
+
}
|
|
1813
|
+
async runStructured(schema, options) {
|
|
1814
|
+
const parser = (0, import_artifact3.structuredOutputParser)(schema);
|
|
1815
|
+
const result = await this.run({
|
|
1816
|
+
...options,
|
|
1817
|
+
tools: [
|
|
1818
|
+
...options.tools,
|
|
1819
|
+
parser.tool
|
|
1820
|
+
]
|
|
1821
|
+
});
|
|
1822
|
+
return parser.getResult(result);
|
|
1823
|
+
}
|
|
1824
|
+
async _formatUserPrompt(artifactDiffResolver, prompt, history) {
|
|
1825
|
+
const prelude = [];
|
|
1826
|
+
if (artifactDiffResolver) {
|
|
1827
|
+
const versions = gatherObjectVersions(history);
|
|
1828
|
+
const artifactDiff = await artifactDiffResolver(Array.from(versions.entries()).map(([id, version]) => ({
|
|
1829
|
+
id,
|
|
1830
|
+
lastVersion: version
|
|
1831
|
+
})));
|
|
1832
|
+
import_log4.log.info("vision", {
|
|
1833
|
+
artifactDiff,
|
|
1834
|
+
versions
|
|
1835
|
+
}, {
|
|
1836
|
+
F: __dxlog_file6,
|
|
1837
|
+
L: 272,
|
|
1838
|
+
S: this,
|
|
1839
|
+
C: (f, a) => f(...a)
|
|
1840
|
+
});
|
|
1841
|
+
for (const [id, { version }] of [
|
|
1842
|
+
...artifactDiff.entries()
|
|
1843
|
+
]) {
|
|
1844
|
+
if (import_echo_db2.ObjectVersion.equals(version, versions.get(id))) {
|
|
1845
|
+
artifactDiff.delete(id);
|
|
1846
|
+
continue;
|
|
1847
|
+
}
|
|
1848
|
+
prelude.push(VersionPin.createBlock(VersionPin.make({
|
|
1849
|
+
objectId: id,
|
|
1850
|
+
version
|
|
1851
|
+
})));
|
|
1852
|
+
}
|
|
1853
|
+
if (artifactDiff.size > 0) {
|
|
1854
|
+
prelude.push(createArtifactUpdateBlock(artifactDiff));
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
return (0, import_echo_schema3.create)(import_artifact3.Message, {
|
|
1858
|
+
role: "user",
|
|
1859
|
+
content: [
|
|
1860
|
+
...prelude,
|
|
1861
|
+
{
|
|
1862
|
+
type: "text",
|
|
1863
|
+
text: prompt
|
|
1864
|
+
}
|
|
1865
|
+
]
|
|
1866
|
+
});
|
|
1867
|
+
}
|
|
1868
|
+
_createQueryArtifactsTool(artifacts) {
|
|
1869
|
+
return (0, import_artifact3.defineTool)("system", {
|
|
1870
|
+
name: "query_artifact_definitions",
|
|
1871
|
+
description: "Query the available artifact definitions",
|
|
1872
|
+
schema: import_effect3.Schema.Struct({}),
|
|
1873
|
+
execute: async () => {
|
|
1874
|
+
return import_artifact3.ToolResult.Success({
|
|
1875
|
+
artifactDefinitions: artifacts.map((artifact) => ({
|
|
1876
|
+
id: artifact.id,
|
|
1877
|
+
name: artifact.name,
|
|
1878
|
+
description: artifact.description
|
|
1879
|
+
}))
|
|
1880
|
+
});
|
|
1881
|
+
}
|
|
1882
|
+
});
|
|
1883
|
+
}
|
|
1884
|
+
_createRequireTool(artifacts, onRequire) {
|
|
1885
|
+
return (0, import_artifact3.defineTool)("system", {
|
|
1886
|
+
name: "require_artifact_definitions",
|
|
1887
|
+
description: "Require the use of specific artifact definitions. This will allow the model to interact with artifact definitions and use their tools.",
|
|
1888
|
+
schema: import_effect3.Schema.Struct({
|
|
1889
|
+
artifactDefinitionIds: import_effect3.Schema.Array(import_effect3.Schema.String).annotations({
|
|
1890
|
+
description: "The ids of the artifact definitions to require",
|
|
1891
|
+
examples: [
|
|
1892
|
+
[
|
|
1893
|
+
"artifact:dxos.org/example/Test"
|
|
1894
|
+
]
|
|
1895
|
+
]
|
|
1896
|
+
})
|
|
1897
|
+
}),
|
|
1898
|
+
execute: async ({ artifactDefinitionIds }) => {
|
|
1899
|
+
const missingArtifactDefinitionIds = artifactDefinitionIds.filter((artifactId) => !artifacts.some((artifact) => artifact.id === artifactId));
|
|
1900
|
+
if (missingArtifactDefinitionIds.length > 0) {
|
|
1901
|
+
return import_artifact3.ToolResult.Error(`One or more artifact definition ids are invalid: ${missingArtifactDefinitionIds.join(", ")}`);
|
|
1902
|
+
}
|
|
1903
|
+
onRequire(artifactDefinitionIds);
|
|
1904
|
+
return import_artifact3.ToolResult.Success({});
|
|
1905
|
+
}
|
|
1906
|
+
});
|
|
1907
|
+
}
|
|
1908
|
+
_createPlanningTool(options) {
|
|
1909
|
+
return (0, import_artifact3.defineTool)("system", {
|
|
1910
|
+
name: "create_plan",
|
|
1911
|
+
description: "Create a plan. Make sure that each step is independent and can be executed solely on the data returned by the previous step. The steps only share the data that is specified in the plan.",
|
|
1912
|
+
schema: import_effect3.Schema.Struct({
|
|
1913
|
+
goal: import_effect3.Schema.String.annotations({
|
|
1914
|
+
description: "The goal that the plan will achieve."
|
|
1915
|
+
}),
|
|
1916
|
+
steps: import_effect3.Schema.Array(import_effect3.Schema.Struct({
|
|
1917
|
+
action: import_effect3.Schema.String.annotations({
|
|
1918
|
+
description: "Complete, detailed action to perform."
|
|
1919
|
+
}),
|
|
1920
|
+
input: import_effect3.Schema.String.annotations({
|
|
1921
|
+
description: "The required input data for this step. First step must not require any data."
|
|
1922
|
+
}),
|
|
1923
|
+
output: import_effect3.Schema.String.annotations({
|
|
1924
|
+
description: "The output data from this step. This is passed to the next step as input."
|
|
1925
|
+
}),
|
|
1926
|
+
requiredArtifactIds: import_effect3.Schema.Array(import_effect3.Schema.String).annotations({
|
|
1927
|
+
description: "The ids of the artifacts required to perform this step.",
|
|
1928
|
+
examples: [
|
|
1929
|
+
[
|
|
1930
|
+
"artifact:dxos.org/example/Test"
|
|
1931
|
+
]
|
|
1932
|
+
]
|
|
1933
|
+
})
|
|
1934
|
+
})).annotations({
|
|
1935
|
+
description: "Steps"
|
|
1936
|
+
})
|
|
1937
|
+
}),
|
|
1938
|
+
execute: async ({ goal, steps }) => {
|
|
1939
|
+
const missingArtifactIds = steps.flatMap((step) => step.requiredArtifactIds).filter((artifactId) => !options.artifacts.some((artifact) => artifact.id === artifactId));
|
|
1940
|
+
if (missingArtifactIds.length > 0) {
|
|
1941
|
+
return import_artifact3.ToolResult.Error(`One or more artifact ids are invalid: ${missingArtifactIds.join(", ")}`);
|
|
1942
|
+
}
|
|
1943
|
+
const stepResults = [];
|
|
1944
|
+
for (const step of steps) {
|
|
1945
|
+
(0, import_log4.log)("executing step", {
|
|
1946
|
+
action: step.action
|
|
1947
|
+
}, {
|
|
1948
|
+
F: __dxlog_file6,
|
|
1949
|
+
L: 379,
|
|
1950
|
+
S: this,
|
|
1951
|
+
C: (f, a) => f(...a)
|
|
1952
|
+
});
|
|
1953
|
+
const session = new _AISession({
|
|
1954
|
+
operationModel: "importing"
|
|
1955
|
+
});
|
|
1956
|
+
session.message.on((ev) => this.message.emit(ev));
|
|
1957
|
+
session.block.on((ev) => this.block.emit(ev));
|
|
1958
|
+
session.update.on((ev) => this.update.emit(ev));
|
|
1959
|
+
session.streamEvent.on((ev) => this.streamEvent.emit(ev));
|
|
1960
|
+
session.userMessage.on((ev) => this.userMessage.emit(ev));
|
|
1961
|
+
const messages = await session.run({
|
|
1962
|
+
client: options.client,
|
|
1963
|
+
artifacts: options.artifacts,
|
|
1964
|
+
tools: options.tools,
|
|
1965
|
+
history: options.history,
|
|
1966
|
+
extensions: options.extensions,
|
|
1967
|
+
generationOptions: options.generationOptions,
|
|
1968
|
+
requiredArtifactIds: step.requiredArtifactIds.slice(),
|
|
1969
|
+
artifactDiffResolver: options.artifactDiffResolver,
|
|
1970
|
+
prompt: `
|
|
1971
|
+
You are an agent that executes the subtask in a plan.
|
|
1972
|
+
|
|
1973
|
+
While you know the plan's goal only focus on your subtask
|
|
1974
|
+
Use the data from the previous step to complete your task.
|
|
1975
|
+
Return all of the data from "output" in your last message.
|
|
1976
|
+
|
|
1977
|
+
Current step (that you need to complete):
|
|
1978
|
+
${JSON.stringify({
|
|
1979
|
+
goal,
|
|
1980
|
+
input: step.input,
|
|
1981
|
+
output: step.output,
|
|
1982
|
+
yourTask: step.action
|
|
1983
|
+
}, null, 2)}
|
|
1984
|
+
|
|
1985
|
+
Previous step results:
|
|
1986
|
+
${JSON.stringify(stepResults.at(-1))}.
|
|
1987
|
+
`
|
|
1988
|
+
});
|
|
1989
|
+
const result = messages.at(-1);
|
|
1990
|
+
stepResults.push(result);
|
|
1991
|
+
}
|
|
1992
|
+
return import_artifact3.ToolResult.Success({
|
|
1993
|
+
stepResults
|
|
1994
|
+
});
|
|
1995
|
+
}
|
|
1996
|
+
});
|
|
1997
|
+
}
|
|
1998
|
+
abort() {
|
|
1999
|
+
this._stream?.abort();
|
|
2000
|
+
}
|
|
2001
|
+
};
|
|
2002
|
+
_ts_decorate([
|
|
2003
|
+
import_async2.synchronized
|
|
2004
|
+
], AISession.prototype, "run", null);
|
|
2005
|
+
var createBaseInstructions = ({ availableArtifacts, operationModel }) => `
|
|
2006
|
+
You are a friendly, advanced AI assistant capable of creating and managing artifacts from available data and tools.
|
|
2007
|
+
Your task is to process user commands and questions and decide how best to respond.
|
|
2008
|
+
In some cases, you will need to create or reference data objects called artifacts.
|
|
2009
|
+
|
|
2010
|
+
Follow these guidelines carefully:
|
|
2011
|
+
|
|
2012
|
+
Decision-making:
|
|
2013
|
+
|
|
2014
|
+
- Analyze the structure and type of the content in the user's message.
|
|
2015
|
+
|
|
2016
|
+
|
|
2017
|
+
${operationModel === "planning" ? `
|
|
2018
|
+
- Can you complete the task using the available artifacts?
|
|
2019
|
+
- If you can't complete the task using the available artifacts, query the list of available artifacts using the appropriate tool.
|
|
2020
|
+
- Identify which artifacts are relevant to the user's request.
|
|
2021
|
+
- Break down the user's request into a step-by-step plan that you will use to execute the user's request, the plan items should include artifacts which will be used to perform the actions.
|
|
2022
|
+
` : ""}
|
|
2023
|
+
${operationModel === "importing" ? `
|
|
2024
|
+
- Can you complete the task using the available artifacts?
|
|
2025
|
+
- If you can't complete the task using the available artifacts, query the list of available artifacts using the appropriate tool.
|
|
2026
|
+
- Identify which artifacts are relevant to the user's request.
|
|
2027
|
+
- Are the required artifacts already available?
|
|
2028
|
+
- If not, select which artifact(s) will be the most relevant and require them using the require_artifacts tool.
|
|
2029
|
+
- The require'd artifact tools will be available for use after require.
|
|
2030
|
+
` : ""}
|
|
2031
|
+
${operationModel === "configured" ? `
|
|
2032
|
+
- Select the most relevant artifact(s) to complete the task.
|
|
2033
|
+
- Call the appropriate tool to use the artifact(s).
|
|
2034
|
+
` : ""}
|
|
2035
|
+
|
|
2036
|
+
${availableArtifacts.length > 0 ? `Artifacts already in context: ${availableArtifacts.join("\n")}` : ""}
|
|
2037
|
+
`;
|
|
2038
|
+
var AIServiecOverloadedError = class extends import_effect3.Schema.TaggedError()("AIServiecOverloadedError", {}) {
|
|
2039
|
+
};
|
|
2040
|
+
var gatherObjectVersions = (messages) => {
|
|
2041
|
+
const artifactIds = /* @__PURE__ */ new Map();
|
|
2042
|
+
for (const message of messages) {
|
|
2043
|
+
for (const block of message.content) {
|
|
2044
|
+
if (block.type === "json" && block.disposition === VersionPin.DISPOSITION) {
|
|
2045
|
+
const pin = VersionPin.pipe(import_effect3.Schema.decodeOption)(JSON.parse(block.json)).pipe(import_effect3.Option.getOrUndefined);
|
|
2046
|
+
if (!pin) {
|
|
2047
|
+
continue;
|
|
2048
|
+
}
|
|
2049
|
+
artifactIds.set(pin.objectId, pin.version);
|
|
2050
|
+
}
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
return artifactIds;
|
|
2054
|
+
};
|
|
2055
|
+
var createArtifactUpdateBlock = (artifactDiff) => {
|
|
2056
|
+
return {
|
|
2057
|
+
type: "text",
|
|
2058
|
+
disposition: "artifact-update",
|
|
2059
|
+
text: `
|
|
2060
|
+
The following artifacts have been updated since the last message:
|
|
2061
|
+
${Array.from(artifactDiff.entries()).map(([id, { diff }]) => `<changed-artifact id="${id}">${diff ? `
|
|
2062
|
+
${diff}` : ""}</changed-artifact>`).join("\n")}
|
|
2063
|
+
`
|
|
2064
|
+
};
|
|
2065
|
+
};
|
|
2066
|
+
var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/experimental/assistant/src/experimental/conversation/conversation.ts";
|
|
2067
|
+
var runLLM = async (params) => {
|
|
2068
|
+
let conversationResult = null;
|
|
2069
|
+
const history = params.history ?? [];
|
|
2070
|
+
const generate = async () => {
|
|
2071
|
+
(0, import_log7.log)("llm generate", {
|
|
2072
|
+
tools: params.tools
|
|
2073
|
+
}, {
|
|
2074
|
+
F: __dxlog_file7,
|
|
2075
|
+
L: 44,
|
|
2076
|
+
S: void 0,
|
|
2077
|
+
C: (f, a) => f(...a)
|
|
2078
|
+
});
|
|
2079
|
+
const beginTs = Date.now();
|
|
2080
|
+
const stream = await params.client.execStream({
|
|
2081
|
+
model: params.model,
|
|
2082
|
+
history,
|
|
2083
|
+
systemPrompt: params.system,
|
|
2084
|
+
tools: params.tools
|
|
2085
|
+
});
|
|
2086
|
+
for await (const event of stream) {
|
|
2087
|
+
params.logger?.(event);
|
|
2088
|
+
}
|
|
2089
|
+
await stream.complete();
|
|
2090
|
+
const messages = [];
|
|
2091
|
+
const message = messages.at(-1);
|
|
2092
|
+
(0, import_invariant6.invariant)(message, void 0, {
|
|
2093
|
+
F: __dxlog_file7,
|
|
2094
|
+
L: 61,
|
|
2095
|
+
S: void 0,
|
|
2096
|
+
A: [
|
|
2097
|
+
"message",
|
|
2098
|
+
""
|
|
2099
|
+
]
|
|
2100
|
+
});
|
|
2101
|
+
(0, import_log7.log)("llm result", {
|
|
2102
|
+
time: Date.now() - beginTs,
|
|
2103
|
+
message
|
|
2104
|
+
}, {
|
|
2105
|
+
F: __dxlog_file7,
|
|
2106
|
+
L: 63,
|
|
2107
|
+
S: void 0,
|
|
2108
|
+
C: (f, a) => f(...a)
|
|
2109
|
+
});
|
|
2110
|
+
(0, import_invariant6.invariant)(message, void 0, {
|
|
2111
|
+
F: __dxlog_file7,
|
|
2112
|
+
L: 64,
|
|
2113
|
+
S: void 0,
|
|
2114
|
+
A: [
|
|
2115
|
+
"message",
|
|
2116
|
+
""
|
|
2117
|
+
]
|
|
2118
|
+
});
|
|
2119
|
+
params.logger?.({
|
|
2120
|
+
type: "message",
|
|
2121
|
+
message
|
|
2122
|
+
});
|
|
2123
|
+
history.push(...messages.map((message2) => ({
|
|
2124
|
+
...message2,
|
|
2125
|
+
content: message2.content.filter((block) => block.type !== "image")
|
|
2126
|
+
})));
|
|
2127
|
+
const isToolUse2 = message.content.at(-1)?.type === "tool_use";
|
|
2128
|
+
if (isToolUse2) {
|
|
2129
|
+
const toolCalls = message.content.filter((block) => block.type === "tool_use");
|
|
2130
|
+
(0, import_invariant6.invariant)(toolCalls.length === 1, void 0, {
|
|
2131
|
+
F: __dxlog_file7,
|
|
2132
|
+
L: 75,
|
|
2133
|
+
S: void 0,
|
|
2134
|
+
A: [
|
|
2135
|
+
"toolCalls.length === 1",
|
|
2136
|
+
""
|
|
2137
|
+
]
|
|
2138
|
+
});
|
|
2139
|
+
const toolCall = toolCalls[0];
|
|
2140
|
+
const tool = params.tools.find((tool2) => tool2.name === toolCall.name);
|
|
2141
|
+
if (!tool) {
|
|
2142
|
+
throw new Error(`Tool not found: ${toolCall.name}`);
|
|
2143
|
+
}
|
|
2144
|
+
(0, import_invariant6.invariant)(tool.execute, void 0, {
|
|
2145
|
+
F: __dxlog_file7,
|
|
2146
|
+
L: 82,
|
|
2147
|
+
S: void 0,
|
|
2148
|
+
A: [
|
|
2149
|
+
"tool.execute",
|
|
2150
|
+
""
|
|
2151
|
+
]
|
|
2152
|
+
});
|
|
2153
|
+
const toolResult = await tool.execute(toolCall.input);
|
|
2154
|
+
switch (toolResult.kind) {
|
|
2155
|
+
case "error": {
|
|
2156
|
+
import_log7.log.warn("tool error", {
|
|
2157
|
+
message: toolResult.message
|
|
2158
|
+
}, {
|
|
2159
|
+
F: __dxlog_file7,
|
|
2160
|
+
L: 86,
|
|
2161
|
+
S: void 0,
|
|
2162
|
+
C: (f, a) => f(...a)
|
|
2163
|
+
});
|
|
2164
|
+
const resultMessage = {
|
|
2165
|
+
id: import_echo_schema6.ObjectId.random(),
|
|
2166
|
+
role: "user",
|
|
2167
|
+
content: [
|
|
2168
|
+
{
|
|
2169
|
+
type: "tool_result",
|
|
2170
|
+
toolUseId: toolCall.id,
|
|
2171
|
+
content: toolResult.message,
|
|
2172
|
+
isError: true
|
|
2173
|
+
}
|
|
2174
|
+
]
|
|
2175
|
+
};
|
|
2176
|
+
params.logger?.({
|
|
2177
|
+
type: "message",
|
|
2178
|
+
message: resultMessage
|
|
2179
|
+
});
|
|
2180
|
+
history.push(resultMessage);
|
|
2181
|
+
return true;
|
|
2182
|
+
}
|
|
2183
|
+
case "success": {
|
|
2184
|
+
(0, import_log7.log)("tool success", {
|
|
2185
|
+
result: toolResult.result
|
|
2186
|
+
}, {
|
|
2187
|
+
F: __dxlog_file7,
|
|
2188
|
+
L: 106,
|
|
2189
|
+
S: void 0,
|
|
2190
|
+
C: (f, a) => f(...a)
|
|
2191
|
+
});
|
|
2192
|
+
const resultMessage = {
|
|
2193
|
+
id: import_echo_schema6.ObjectId.random(),
|
|
2194
|
+
role: "user",
|
|
2195
|
+
content: [
|
|
2196
|
+
{
|
|
2197
|
+
type: "tool_result",
|
|
2198
|
+
toolUseId: toolCall.id,
|
|
2199
|
+
content: JSON.stringify(toolResult.result)
|
|
2200
|
+
}
|
|
2201
|
+
]
|
|
2202
|
+
};
|
|
2203
|
+
params.logger?.({
|
|
2204
|
+
type: "message",
|
|
2205
|
+
message: resultMessage
|
|
2206
|
+
});
|
|
2207
|
+
history.push(resultMessage);
|
|
2208
|
+
return true;
|
|
2209
|
+
}
|
|
2210
|
+
case "break": {
|
|
2211
|
+
(0, import_log7.log)("tool break", {
|
|
2212
|
+
result: toolResult.result
|
|
2213
|
+
}, {
|
|
2214
|
+
F: __dxlog_file7,
|
|
2215
|
+
L: 125,
|
|
2216
|
+
S: void 0,
|
|
2217
|
+
C: (f, a) => f(...a)
|
|
2218
|
+
});
|
|
2219
|
+
conversationResult = toolResult.result;
|
|
2220
|
+
return false;
|
|
2221
|
+
}
|
|
2222
|
+
}
|
|
2223
|
+
}
|
|
2224
|
+
return false;
|
|
2225
|
+
};
|
|
2226
|
+
while (await generate()) {
|
|
2227
|
+
}
|
|
2228
|
+
return {
|
|
2229
|
+
result: conversationResult,
|
|
2230
|
+
history
|
|
2231
|
+
};
|
|
2232
|
+
};
|
|
1779
2233
|
var ws = import_parjs.parjs.whitespace();
|
|
1780
2234
|
var nothing = import_parjs.parjs.string("").pipe(import_parjs.parjsCombinators.map(() => null));
|
|
1781
2235
|
var optional = (parser) => parser.pipe(import_parjs.parjsCombinators.recover(() => ({
|
|
@@ -1858,7 +2312,7 @@ var parseCypherQuery = (query) => {
|
|
|
1858
2312
|
throw new Error(`Failed to parse query: ${parseResult}`);
|
|
1859
2313
|
}
|
|
1860
2314
|
};
|
|
1861
|
-
var
|
|
2315
|
+
var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/experimental/assistant/src/experimental/cypher/execution-plan.ts";
|
|
1862
2316
|
var createExecutionPlan = (query) => {
|
|
1863
2317
|
return new ExecutionPlanBuilder().build(query);
|
|
1864
2318
|
};
|
|
@@ -1870,10 +2324,10 @@ var ExecutionPlanBuilder = class {
|
|
|
1870
2324
|
return `anon_${this.counter++}`;
|
|
1871
2325
|
}
|
|
1872
2326
|
build(query) {
|
|
1873
|
-
(0,
|
|
2327
|
+
(0, import_log9.log)("Creating execution plan for query", {
|
|
1874
2328
|
query
|
|
1875
2329
|
}, {
|
|
1876
|
-
F:
|
|
2330
|
+
F: __dxlog_file8,
|
|
1877
2331
|
L: 76,
|
|
1878
2332
|
S: this,
|
|
1879
2333
|
C: (f, a) => f(...a)
|
|
@@ -1890,8 +2344,8 @@ var ExecutionPlanBuilder = class {
|
|
|
1890
2344
|
};
|
|
1891
2345
|
}
|
|
1892
2346
|
createStepsForMatchClause(match) {
|
|
1893
|
-
(0,
|
|
1894
|
-
F:
|
|
2347
|
+
(0, import_invariant7.invariant)(match.pattern.segments.length > 0, void 0, {
|
|
2348
|
+
F: __dxlog_file8,
|
|
1895
2349
|
L: 90,
|
|
1896
2350
|
S: this,
|
|
1897
2351
|
A: [
|
|
@@ -1900,8 +2354,8 @@ var ExecutionPlanBuilder = class {
|
|
|
1900
2354
|
]
|
|
1901
2355
|
});
|
|
1902
2356
|
const firstSegment = match.pattern.segments[0];
|
|
1903
|
-
(0,
|
|
1904
|
-
F:
|
|
2357
|
+
(0, import_invariant7.invariant)(firstSegment.astKind === "NodePattern", void 0, {
|
|
2358
|
+
F: __dxlog_file8,
|
|
1905
2359
|
L: 92,
|
|
1906
2360
|
S: this,
|
|
1907
2361
|
A: [
|
|
@@ -1928,8 +2382,8 @@ var ExecutionPlanBuilder = class {
|
|
|
1928
2382
|
}
|
|
1929
2383
|
for (let i = 1; i < match.pattern.segments.length; i++) {
|
|
1930
2384
|
const relationshipSegment = match.pattern.segments[i++];
|
|
1931
|
-
(0,
|
|
1932
|
-
F:
|
|
2385
|
+
(0, import_invariant7.invariant)(relationshipSegment.astKind === "RelationshipPattern", void 0, {
|
|
2386
|
+
F: __dxlog_file8,
|
|
1933
2387
|
L: 115,
|
|
1934
2388
|
S: this,
|
|
1935
2389
|
A: [
|
|
@@ -1938,8 +2392,8 @@ var ExecutionPlanBuilder = class {
|
|
|
1938
2392
|
]
|
|
1939
2393
|
});
|
|
1940
2394
|
const nodeSegment = match.pattern.segments[i];
|
|
1941
|
-
(0,
|
|
1942
|
-
F:
|
|
2395
|
+
(0, import_invariant7.invariant)(nodeSegment.astKind === "NodePattern", void 0, {
|
|
2396
|
+
F: __dxlog_file8,
|
|
1943
2397
|
L: 117,
|
|
1944
2398
|
S: this,
|
|
1945
2399
|
A: [
|
|
@@ -2020,15 +2474,15 @@ var getDirection = (left, right) => {
|
|
|
2020
2474
|
}
|
|
2021
2475
|
throw new Error(`Invalid direction: ()${left}[]${right}()`);
|
|
2022
2476
|
};
|
|
2023
|
-
var
|
|
2477
|
+
var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/experimental/assistant/src/experimental/cypher/query-executor.ts";
|
|
2024
2478
|
var executeQueryPlan = async (dataSource, plan) => {
|
|
2025
2479
|
let buffer = [];
|
|
2026
2480
|
const results = [];
|
|
2027
2481
|
for (const step of plan.steps) {
|
|
2028
|
-
(0,
|
|
2482
|
+
(0, import_log8.log)("begin step", {
|
|
2029
2483
|
step
|
|
2030
2484
|
}, {
|
|
2031
|
-
F:
|
|
2485
|
+
F: __dxlog_file9,
|
|
2032
2486
|
L: 41,
|
|
2033
2487
|
S: void 0,
|
|
2034
2488
|
C: (f, a) => f(...a)
|
|
@@ -2114,11 +2568,11 @@ var executeQueryPlan = async (dataSource, plan) => {
|
|
|
2114
2568
|
break;
|
|
2115
2569
|
}
|
|
2116
2570
|
}
|
|
2117
|
-
(0,
|
|
2571
|
+
(0, import_log8.log)("finish step", {
|
|
2118
2572
|
buffer: buffer.map((tuple) => (0, import_util2.mapValues)(tuple, (x) => x.id)),
|
|
2119
2573
|
results
|
|
2120
2574
|
}, {
|
|
2121
|
-
F:
|
|
2575
|
+
F: __dxlog_file9,
|
|
2122
2576
|
L: 118,
|
|
2123
2577
|
S: void 0,
|
|
2124
2578
|
C: (f, a) => f(...a)
|
|
@@ -2201,14 +2655,14 @@ var formatInferredRelationshipLabel = (typename, property2) => {
|
|
|
2201
2655
|
const nodeLabel = formatNodeLabel(typename);
|
|
2202
2656
|
return `${nodeLabel}_${property2}`.toUpperCase();
|
|
2203
2657
|
};
|
|
2204
|
-
var isReference = (schema) => schema.$id ===
|
|
2205
|
-
function
|
|
2658
|
+
var isReference = (schema) => schema.$id === import_echo_schema7.JSON_SCHEMA_ECHO_REF_ID || schema.type === "array" && !Array.isArray(schema.items) && typeof schema.items === "object" && "$id" in schema.items && schema.items.$id === import_echo_schema7.JSON_SCHEMA_ECHO_REF_ID;
|
|
2659
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
2206
2660
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2207
2661
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2208
2662
|
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;
|
|
2209
2663
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2210
2664
|
}
|
|
2211
|
-
var
|
|
2665
|
+
var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/experimental/assistant/src/experimental/cypher/echo-data-source.ts";
|
|
2212
2666
|
var EchoDataSource = class {
|
|
2213
2667
|
constructor(_db) {
|
|
2214
2668
|
this._db = _db;
|
|
@@ -2218,16 +2672,16 @@ var EchoDataSource = class {
|
|
|
2218
2672
|
const { objects: objects2 } = await this._db.query().run();
|
|
2219
2673
|
return objects2.map(this._objectToNode);
|
|
2220
2674
|
}
|
|
2221
|
-
const schema = (await this._getAllSchema()).find((s) => (0,
|
|
2675
|
+
const schema = (await this._getAllSchema()).find((s) => (0, import_echo_schema8.getSchemaTypename)(s)?.endsWith(label2));
|
|
2222
2676
|
if (!schema) {
|
|
2223
2677
|
return [];
|
|
2224
2678
|
}
|
|
2225
|
-
const { objects } = await this._db.query(
|
|
2679
|
+
const { objects } = await this._db.query(import_echo_db3.Filter.schema(schema)).run();
|
|
2226
2680
|
return objects.map(this._objectToNode);
|
|
2227
2681
|
}
|
|
2228
2682
|
async getRelationships({ label: label2 }) {
|
|
2229
|
-
const syntheticRefRelationships = (await this._getAllSchema()).filter((schema) => (0,
|
|
2230
|
-
const jsonSchema = (0,
|
|
2683
|
+
const syntheticRefRelationships = (await this._getAllSchema()).filter((schema) => (0, import_echo_schema8.getSchemaTypename)(schema) !== import_echo_schema8.StoredSchema.typename).flatMap((schema) => {
|
|
2684
|
+
const jsonSchema = (0, import_echo_schema8.toJsonSchema)(schema);
|
|
2231
2685
|
const relationships = Object.entries(jsonSchema.properties).filter(([key, prop]) => isReference(prop));
|
|
2232
2686
|
return relationships.map(([key, value]) => {
|
|
2233
2687
|
const relationshipLabel = formatInferredRelationshipLabel(jsonSchema.typename ?? (0, import_debug2.raise)(new Error("Schema must have typename")), key);
|
|
@@ -2242,22 +2696,22 @@ var EchoDataSource = class {
|
|
|
2242
2696
|
if (!relationship) {
|
|
2243
2697
|
return [];
|
|
2244
2698
|
}
|
|
2245
|
-
const { objects } = await this._db.query(
|
|
2699
|
+
const { objects } = await this._db.query(import_echo_db3.Filter.schema(relationship.schema)).run();
|
|
2246
2700
|
return (await Promise.all(objects.map((object) => this._projectRefRelationship(object, relationship.property)))).flat();
|
|
2247
2701
|
}
|
|
2248
2702
|
async _getAllSchema() {
|
|
2249
2703
|
return [
|
|
2250
2704
|
...await this._db.schemaRegistry.query().run(),
|
|
2251
2705
|
// TODO(dmaretskyi): Remove once we can serialize recursive schema.
|
|
2252
|
-
...this._db.graph.schemaRegistry.schemas.filter((s) => (0,
|
|
2253
|
-
].filter((schema) => (0,
|
|
2706
|
+
...this._db.graph.schemaRegistry.schemas.filter((s) => (0, import_echo_schema8.getSchemaTypename)(s)?.startsWith("example.org"))
|
|
2707
|
+
].filter((schema) => (0, import_echo_schema8.getSchemaTypename)(schema) !== import_echo_schema8.StoredSchema.typename);
|
|
2254
2708
|
}
|
|
2255
2709
|
_objectToNode(object) {
|
|
2256
2710
|
const { id, ...properties2 } = object;
|
|
2257
2711
|
return {
|
|
2258
2712
|
id,
|
|
2259
2713
|
kind: "node",
|
|
2260
|
-
label: formatNodeLabel((0,
|
|
2714
|
+
label: formatNodeLabel((0, import_echo_schema8.getSchemaTypename)((0, import_echo_schema8.getSchema)(object))),
|
|
2261
2715
|
properties: properties2
|
|
2262
2716
|
};
|
|
2263
2717
|
}
|
|
@@ -2273,7 +2727,7 @@ var EchoDataSource = class {
|
|
|
2273
2727
|
return {
|
|
2274
2728
|
id: `${object.id}-${prop}-${target.id}`,
|
|
2275
2729
|
kind: "relationship",
|
|
2276
|
-
label: formatInferredRelationshipLabel((0,
|
|
2730
|
+
label: formatInferredRelationshipLabel((0, import_echo_schema8.getSchemaTypename)((0, import_echo_schema8.getSchema)(object)), prop),
|
|
2277
2731
|
properties: {},
|
|
2278
2732
|
source: this._objectToNode(object),
|
|
2279
2733
|
target: this._objectToNode(target)
|
|
@@ -2281,17 +2735,17 @@ var EchoDataSource = class {
|
|
|
2281
2735
|
}));
|
|
2282
2736
|
}
|
|
2283
2737
|
};
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
F:
|
|
2738
|
+
_ts_decorate2([
|
|
2739
|
+
import_log10.log.method(void 0, void 0, {
|
|
2740
|
+
F: __dxlog_file10,
|
|
2287
2741
|
L: 18,
|
|
2288
2742
|
S: void 0,
|
|
2289
2743
|
C: (f, a) => f(...a)
|
|
2290
2744
|
})
|
|
2291
2745
|
], EchoDataSource.prototype, "getNodes", null);
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
F:
|
|
2746
|
+
_ts_decorate2([
|
|
2747
|
+
import_log10.log.method(void 0, void 0, {
|
|
2748
|
+
F: __dxlog_file10,
|
|
2295
2749
|
L: 35,
|
|
2296
2750
|
S: void 0,
|
|
2297
2751
|
C: (f, a) => f(...a)
|
|
@@ -2300,6 +2754,8 @@ _ts_decorate([
|
|
|
2300
2754
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2301
2755
|
0 && (module.exports = {
|
|
2302
2756
|
AIServiceEdgeClient,
|
|
2757
|
+
AIServiecOverloadedError,
|
|
2758
|
+
AISession,
|
|
2303
2759
|
DEFAULT_EDGE_MODEL,
|
|
2304
2760
|
DEFAULT_EDGE_MODELS,
|
|
2305
2761
|
DEFAULT_OLLAMA_ENDPOINT,
|
|
@@ -2315,6 +2771,7 @@ _ts_decorate([
|
|
|
2315
2771
|
OllamaClient,
|
|
2316
2772
|
StreamTransform,
|
|
2317
2773
|
ToolTypes,
|
|
2774
|
+
VersionPin,
|
|
2318
2775
|
createArtifactElement,
|
|
2319
2776
|
createGenerationStream,
|
|
2320
2777
|
emitMessageAsEvents,
|
|
@@ -2331,4 +2788,4 @@ _ts_decorate([
|
|
|
2331
2788
|
runTools,
|
|
2332
2789
|
trim
|
|
2333
2790
|
});
|
|
2334
|
-
//# sourceMappingURL=chunk-
|
|
2791
|
+
//# sourceMappingURL=chunk-FTIDW4BA.cjs.map
|