@dxos/assistant 0.8.2-main.f11618f → 0.8.2-main.fbd8ed0
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-DEIGOD4U.mjs → chunk-B4HAWUFW.mjs} +710 -246
- package/dist/lib/browser/chunk-B4HAWUFW.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 +117 -80
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node/{chunk-7VH7NMIM.cjs → chunk-NOB7CIIC.cjs} +716 -259
- package/dist/lib/node/chunk-NOB7CIIC.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 +104 -69
- package/dist/lib/node/testing/index.cjs.map +4 -4
- package/dist/lib/node-esm/{chunk-7JI4MDGL.mjs → chunk-SAWYU3V5.mjs} +710 -246
- package/dist/lib/node-esm/chunk-SAWYU3V5.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 +117 -80
- 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 +133 -133
- 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/{conversation → experimental/conversation}/types.d.ts +9 -9
- 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 +4 -3
- 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 +4 -4
- package/dist/types/src/testing/query-promts.d.ts.map +1 -1
- package/dist/types/src/testing/test-data.d.ts +5 -5
- package/dist/types/src/testing/test-data.d.ts.map +1 -1
- package/dist/types/src/testing/test-schema.d.ts +25 -23
- package/dist/types/src/testing/test-schema.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 +20 -14
- package/src/ai-service/client.test.ts +5 -5
- package/src/ai-service/ollama-client.ts +8 -8
- package/src/ai-service/types.ts +14 -14
- package/src/bin/chat.ts +1 -1
- package/src/{conversation → experimental/conversation}/conversation.test.ts +5 -5
- package/src/{conversation → experimental/conversation}/conversation.ts +3 -112
- package/src/{conversation → experimental/conversation}/types.ts +10 -10
- package/src/{cypher → experimental/cypher}/echo-data-source.ts +11 -10
- 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 +28 -57
- package/src/session/session.ts +26 -16
- package/src/session/tools.ts +117 -0
- package/src/session/version-pin.ts +6 -0
- package/src/testing/artifacts.test.ts +22 -22
- 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 +6 -6
- package/src/testing/query.test.ts +1 -2
- package/src/testing/test-data.ts +58 -51
- package/src/testing/test-schema.ts +27 -28
- package/src/typedefs.d.ts +8 -0
- package/dist/lib/browser/chunk-DEIGOD4U.mjs.map +0 -7
- package/dist/lib/node/chunk-7VH7NMIM.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-7JI4MDGL.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/{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/{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}/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
|
@@ -495,223 +495,57 @@ function* emitMessageAsEvents(message) {
|
|
|
495
495
|
}
|
|
496
496
|
|
|
497
497
|
// packages/experimental/assistant/src/ai-service/types.ts
|
|
498
|
-
import { Schema
|
|
498
|
+
import { Schema } from "effect";
|
|
499
499
|
import { Tool, Message } from "@dxos/artifact";
|
|
500
500
|
var createArtifactElement = (id) => `<artifact id=${id} />`;
|
|
501
|
-
var LLMModel =
|
|
501
|
+
var LLMModel = Schema.Literal(...DEFAULT_EDGE_MODELS, ...DEFAULT_OLLAMA_MODELS);
|
|
502
502
|
var ToolTypes = Object.freeze({
|
|
503
503
|
// TODO(dmaretskyi): Not implemented yet.
|
|
504
504
|
// DatabaseQuery: 'database_query',
|
|
505
505
|
TextToImage: "text_to_image"
|
|
506
506
|
});
|
|
507
|
-
var GenerateRequest =
|
|
507
|
+
var GenerateRequest = Schema.Struct({
|
|
508
508
|
/**
|
|
509
509
|
* Preferred model or system default.
|
|
510
510
|
*/
|
|
511
|
-
model:
|
|
511
|
+
model: Schema.optional(LLMModel),
|
|
512
512
|
/**
|
|
513
513
|
* Tools available for the LLM.
|
|
514
514
|
*/
|
|
515
|
-
tools:
|
|
515
|
+
tools: Schema.optional(Schema.Array(Tool).pipe(Schema.mutable)),
|
|
516
516
|
/**
|
|
517
517
|
* System instructions to the LLM.
|
|
518
518
|
*/
|
|
519
|
-
systemPrompt:
|
|
519
|
+
systemPrompt: Schema.optional(Schema.String),
|
|
520
520
|
/**
|
|
521
521
|
* History of messages to include in the context window.
|
|
522
522
|
*/
|
|
523
523
|
// TODO(burdon): Rename messages.
|
|
524
|
-
history:
|
|
524
|
+
history: Schema.optional(Schema.Array(Message)),
|
|
525
525
|
/**
|
|
526
526
|
* Current request.
|
|
527
527
|
*/
|
|
528
|
-
prompt:
|
|
528
|
+
prompt: Schema.optional(Message)
|
|
529
529
|
});
|
|
530
|
-
var GenerateResponse =
|
|
531
|
-
messages:
|
|
530
|
+
var GenerateResponse = Schema.Struct({
|
|
531
|
+
messages: Schema.Array(Message),
|
|
532
532
|
/**
|
|
533
533
|
* Number of tokens used in the response.
|
|
534
534
|
*/
|
|
535
|
-
tokenCount:
|
|
535
|
+
tokenCount: Schema.optional(Schema.Number)
|
|
536
536
|
});
|
|
537
537
|
|
|
538
|
-
// packages/experimental/assistant/src/
|
|
539
|
-
import {
|
|
540
|
-
import { create
|
|
538
|
+
// packages/experimental/assistant/src/session/tools.ts
|
|
539
|
+
import { Message as Message2, ToolResult } from "@dxos/artifact";
|
|
540
|
+
import { create } from "@dxos/echo-schema";
|
|
541
541
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
542
542
|
import { log as log3 } from "@dxos/log";
|
|
543
|
-
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/experimental/assistant/src/
|
|
544
|
-
var runLLM = async (params) => {
|
|
545
|
-
let conversationResult = null;
|
|
546
|
-
const history = params.history ?? [];
|
|
547
|
-
const generate = async () => {
|
|
548
|
-
log3("llm generate", {
|
|
549
|
-
tools: params.tools
|
|
550
|
-
}, {
|
|
551
|
-
F: __dxlog_file3,
|
|
552
|
-
L: 44,
|
|
553
|
-
S: void 0,
|
|
554
|
-
C: (f, a) => f(...a)
|
|
555
|
-
});
|
|
556
|
-
const beginTs = Date.now();
|
|
557
|
-
const stream = await params.client.execStream({
|
|
558
|
-
model: params.model,
|
|
559
|
-
history,
|
|
560
|
-
systemPrompt: params.system,
|
|
561
|
-
tools: params.tools
|
|
562
|
-
});
|
|
563
|
-
for await (const event of stream) {
|
|
564
|
-
params.logger?.(event);
|
|
565
|
-
}
|
|
566
|
-
await stream.complete();
|
|
567
|
-
const messages = [];
|
|
568
|
-
const message = messages.at(-1);
|
|
569
|
-
invariant2(message, void 0, {
|
|
570
|
-
F: __dxlog_file3,
|
|
571
|
-
L: 61,
|
|
572
|
-
S: void 0,
|
|
573
|
-
A: [
|
|
574
|
-
"message",
|
|
575
|
-
""
|
|
576
|
-
]
|
|
577
|
-
});
|
|
578
|
-
log3("llm result", {
|
|
579
|
-
time: Date.now() - beginTs,
|
|
580
|
-
message
|
|
581
|
-
}, {
|
|
582
|
-
F: __dxlog_file3,
|
|
583
|
-
L: 63,
|
|
584
|
-
S: void 0,
|
|
585
|
-
C: (f, a) => f(...a)
|
|
586
|
-
});
|
|
587
|
-
invariant2(message, void 0, {
|
|
588
|
-
F: __dxlog_file3,
|
|
589
|
-
L: 64,
|
|
590
|
-
S: void 0,
|
|
591
|
-
A: [
|
|
592
|
-
"message",
|
|
593
|
-
""
|
|
594
|
-
]
|
|
595
|
-
});
|
|
596
|
-
params.logger?.({
|
|
597
|
-
type: "message",
|
|
598
|
-
message
|
|
599
|
-
});
|
|
600
|
-
history.push(...messages.map((message2) => ({
|
|
601
|
-
...message2,
|
|
602
|
-
content: message2.content.filter((block) => block.type !== "image")
|
|
603
|
-
})));
|
|
604
|
-
const isToolUse2 = message.content.at(-1)?.type === "tool_use";
|
|
605
|
-
if (isToolUse2) {
|
|
606
|
-
const toolCalls = message.content.filter((block) => block.type === "tool_use");
|
|
607
|
-
invariant2(toolCalls.length === 1, void 0, {
|
|
608
|
-
F: __dxlog_file3,
|
|
609
|
-
L: 75,
|
|
610
|
-
S: void 0,
|
|
611
|
-
A: [
|
|
612
|
-
"toolCalls.length === 1",
|
|
613
|
-
""
|
|
614
|
-
]
|
|
615
|
-
});
|
|
616
|
-
const toolCall = toolCalls[0];
|
|
617
|
-
const tool = params.tools.find((tool2) => tool2.name === toolCall.name);
|
|
618
|
-
if (!tool) {
|
|
619
|
-
throw new Error(`Tool not found: ${toolCall.name}`);
|
|
620
|
-
}
|
|
621
|
-
invariant2(tool.execute, void 0, {
|
|
622
|
-
F: __dxlog_file3,
|
|
623
|
-
L: 82,
|
|
624
|
-
S: void 0,
|
|
625
|
-
A: [
|
|
626
|
-
"tool.execute",
|
|
627
|
-
""
|
|
628
|
-
]
|
|
629
|
-
});
|
|
630
|
-
const toolResult = await tool.execute(toolCall.input);
|
|
631
|
-
switch (toolResult.kind) {
|
|
632
|
-
case "error": {
|
|
633
|
-
log3.warn("tool error", {
|
|
634
|
-
message: toolResult.message
|
|
635
|
-
}, {
|
|
636
|
-
F: __dxlog_file3,
|
|
637
|
-
L: 86,
|
|
638
|
-
S: void 0,
|
|
639
|
-
C: (f, a) => f(...a)
|
|
640
|
-
});
|
|
641
|
-
const resultMessage = {
|
|
642
|
-
id: ObjectId.random(),
|
|
643
|
-
role: "user",
|
|
644
|
-
content: [
|
|
645
|
-
{
|
|
646
|
-
type: "tool_result",
|
|
647
|
-
toolUseId: toolCall.id,
|
|
648
|
-
content: toolResult.message,
|
|
649
|
-
isError: true
|
|
650
|
-
}
|
|
651
|
-
]
|
|
652
|
-
};
|
|
653
|
-
params.logger?.({
|
|
654
|
-
type: "message",
|
|
655
|
-
message: resultMessage
|
|
656
|
-
});
|
|
657
|
-
history.push(resultMessage);
|
|
658
|
-
return true;
|
|
659
|
-
}
|
|
660
|
-
case "success": {
|
|
661
|
-
log3("tool success", {
|
|
662
|
-
result: toolResult.result
|
|
663
|
-
}, {
|
|
664
|
-
F: __dxlog_file3,
|
|
665
|
-
L: 106,
|
|
666
|
-
S: void 0,
|
|
667
|
-
C: (f, a) => f(...a)
|
|
668
|
-
});
|
|
669
|
-
const resultMessage = {
|
|
670
|
-
id: ObjectId.random(),
|
|
671
|
-
role: "user",
|
|
672
|
-
content: [
|
|
673
|
-
{
|
|
674
|
-
type: "tool_result",
|
|
675
|
-
toolUseId: toolCall.id,
|
|
676
|
-
content: JSON.stringify(toolResult.result)
|
|
677
|
-
}
|
|
678
|
-
]
|
|
679
|
-
};
|
|
680
|
-
params.logger?.({
|
|
681
|
-
type: "message",
|
|
682
|
-
message: resultMessage
|
|
683
|
-
});
|
|
684
|
-
history.push(resultMessage);
|
|
685
|
-
return true;
|
|
686
|
-
}
|
|
687
|
-
case "break": {
|
|
688
|
-
log3("tool break", {
|
|
689
|
-
result: toolResult.result
|
|
690
|
-
}, {
|
|
691
|
-
F: __dxlog_file3,
|
|
692
|
-
L: 125,
|
|
693
|
-
S: void 0,
|
|
694
|
-
C: (f, a) => f(...a)
|
|
695
|
-
});
|
|
696
|
-
conversationResult = toolResult.result;
|
|
697
|
-
return false;
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
return false;
|
|
702
|
-
};
|
|
703
|
-
while (await generate()) {
|
|
704
|
-
}
|
|
705
|
-
return {
|
|
706
|
-
result: conversationResult,
|
|
707
|
-
history
|
|
708
|
-
};
|
|
709
|
-
};
|
|
543
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/experimental/assistant/src/session/tools.ts";
|
|
710
544
|
var isToolUse = (message, { onlyToolNames } = {}) => {
|
|
711
545
|
const block = message.content.at(-1);
|
|
712
546
|
invariant2(block, void 0, {
|
|
713
547
|
F: __dxlog_file3,
|
|
714
|
-
L:
|
|
548
|
+
L: 12,
|
|
715
549
|
S: void 0,
|
|
716
550
|
A: [
|
|
717
551
|
"block",
|
|
@@ -724,7 +558,7 @@ var runTools = async ({ message, tools, extensions }) => {
|
|
|
724
558
|
const toolCalls = message.content.filter((block) => block.type === "tool_use");
|
|
725
559
|
invariant2(toolCalls.length === 1, void 0, {
|
|
726
560
|
F: __dxlog_file3,
|
|
727
|
-
L:
|
|
561
|
+
L: 34,
|
|
728
562
|
S: void 0,
|
|
729
563
|
A: [
|
|
730
564
|
"toolCalls.length === 1",
|
|
@@ -754,7 +588,7 @@ var runTools = async ({ message, tools, extensions }) => {
|
|
|
754
588
|
try {
|
|
755
589
|
invariant2(tool.execute, void 0, {
|
|
756
590
|
F: __dxlog_file3,
|
|
757
|
-
L:
|
|
591
|
+
L: 59,
|
|
758
592
|
S: void 0,
|
|
759
593
|
A: [
|
|
760
594
|
"tool.execute",
|
|
@@ -769,7 +603,7 @@ var runTools = async ({ message, tools, extensions }) => {
|
|
|
769
603
|
error
|
|
770
604
|
}, {
|
|
771
605
|
F: __dxlog_file3,
|
|
772
|
-
L:
|
|
606
|
+
L: 62,
|
|
773
607
|
S: void 0,
|
|
774
608
|
C: (f, a) => f(...a)
|
|
775
609
|
});
|
|
@@ -781,7 +615,7 @@ var runTools = async ({ message, tools, extensions }) => {
|
|
|
781
615
|
message: toolResult.message
|
|
782
616
|
}, {
|
|
783
617
|
F: __dxlog_file3,
|
|
784
|
-
L:
|
|
618
|
+
L: 68,
|
|
785
619
|
S: void 0,
|
|
786
620
|
C: (f, a) => f(...a)
|
|
787
621
|
});
|
|
@@ -806,7 +640,7 @@ var runTools = async ({ message, tools, extensions }) => {
|
|
|
806
640
|
result: toolResult.result
|
|
807
641
|
}, {
|
|
808
642
|
F: __dxlog_file3,
|
|
809
|
-
L:
|
|
643
|
+
L: 89,
|
|
810
644
|
S: void 0,
|
|
811
645
|
C: (f, a) => f(...a)
|
|
812
646
|
});
|
|
@@ -831,7 +665,7 @@ var runTools = async ({ message, tools, extensions }) => {
|
|
|
831
665
|
result: toolResult.result
|
|
832
666
|
}, {
|
|
833
667
|
F: __dxlog_file3,
|
|
834
|
-
L:
|
|
668
|
+
L: 110,
|
|
835
669
|
S: void 0,
|
|
836
670
|
C: (f, a) => f(...a)
|
|
837
671
|
});
|
|
@@ -843,8 +677,47 @@ var runTools = async ({ message, tools, extensions }) => {
|
|
|
843
677
|
}
|
|
844
678
|
};
|
|
845
679
|
|
|
680
|
+
// packages/experimental/assistant/src/session/version-pin.ts
|
|
681
|
+
import { Schema as Schema2 } from "effect";
|
|
682
|
+
import { getVersion } from "@dxos/echo-db";
|
|
683
|
+
import { ObjectId } from "@dxos/echo-schema";
|
|
684
|
+
var ObjectVersionSchema = Schema2.Unknown;
|
|
685
|
+
var VersionPinSchema = Schema2.Struct({
|
|
686
|
+
// TODO(dmaretskyi): Use Ref when those support encoding.
|
|
687
|
+
objectId: ObjectId,
|
|
688
|
+
// TODO(dmaretskyi): Could be opaque
|
|
689
|
+
version: ObjectVersionSchema
|
|
690
|
+
});
|
|
691
|
+
var VersionPin = class extends VersionPinSchema {
|
|
692
|
+
static {
|
|
693
|
+
this.DISPOSITION = "version-pin";
|
|
694
|
+
}
|
|
695
|
+
static fromObject(object) {
|
|
696
|
+
return VersionPin.make({
|
|
697
|
+
objectId: object.id,
|
|
698
|
+
version: getVersion(object)
|
|
699
|
+
});
|
|
700
|
+
}
|
|
701
|
+
static createBlock(pin) {
|
|
702
|
+
return {
|
|
703
|
+
type: "json",
|
|
704
|
+
disposition: VersionPin.DISPOSITION,
|
|
705
|
+
json: JSON.stringify(pin)
|
|
706
|
+
};
|
|
707
|
+
}
|
|
708
|
+
};
|
|
709
|
+
|
|
710
|
+
// packages/experimental/assistant/src/session/session.ts
|
|
711
|
+
import { Option, Schema as Schema4 } from "effect";
|
|
712
|
+
import { defineTool as defineTool2, Message as Message4, structuredOutputParser, ToolResult as ToolResult3 } from "@dxos/artifact";
|
|
713
|
+
import { Event as Event2, synchronized } from "@dxos/async";
|
|
714
|
+
import { ObjectVersion } from "@dxos/echo-db";
|
|
715
|
+
import { create as create3 } from "@dxos/echo-schema";
|
|
716
|
+
import { invariant as invariant5 } from "@dxos/invariant";
|
|
717
|
+
import { log as log6 } from "@dxos/log";
|
|
718
|
+
|
|
846
719
|
// packages/experimental/assistant/src/ai-service/ollama-client.ts
|
|
847
|
-
import { Schema as
|
|
720
|
+
import { Schema as Schema3 } from "effect";
|
|
848
721
|
import { defineTool, ToolResult as ToolResult2 } from "@dxos/artifact";
|
|
849
722
|
import { ObjectId as ObjectId2 } from "@dxos/echo-schema";
|
|
850
723
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
@@ -1150,8 +1023,8 @@ var WELL_KNOWN_TOOLS = {
|
|
|
1150
1023
|
[ToolTypes.TextToImage]: defineTool("system", {
|
|
1151
1024
|
name: "text-to-image",
|
|
1152
1025
|
description: "Generate an image from a text prompt",
|
|
1153
|
-
schema:
|
|
1154
|
-
prompt:
|
|
1026
|
+
schema: Schema3.Struct({
|
|
1027
|
+
prompt: Schema3.String.annotations({
|
|
1155
1028
|
description: "The text prompt describing the image to generate"
|
|
1156
1029
|
})
|
|
1157
1030
|
}),
|
|
@@ -1194,12 +1067,12 @@ var OllamaDecoderStream = class extends TransformStream {
|
|
|
1194
1067
|
this._buffer = "";
|
|
1195
1068
|
}
|
|
1196
1069
|
};
|
|
1197
|
-
var ModelDoesNotSupportToolsError = class extends
|
|
1198
|
-
model:
|
|
1070
|
+
var ModelDoesNotSupportToolsError = class extends Schema3.TaggedError()("ModelDoesNotSupportToolsError", {
|
|
1071
|
+
model: Schema3.String
|
|
1199
1072
|
}) {
|
|
1200
1073
|
};
|
|
1201
|
-
var ModelNotFoundError = class extends
|
|
1202
|
-
model:
|
|
1074
|
+
var ModelNotFoundError = class extends Schema3.TaggedError()("ModelNotFoundError", {
|
|
1075
|
+
model: Schema3.String
|
|
1203
1076
|
}) {
|
|
1204
1077
|
};
|
|
1205
1078
|
var parseOllamaError = (error) => {
|
|
@@ -1229,6 +1102,14 @@ var parseErrorResponse2 = async (response) => {
|
|
|
1229
1102
|
throw new Error(`Ollama API error: ${response.status} ${response.statusText} ${await response.text()}`);
|
|
1230
1103
|
};
|
|
1231
1104
|
|
|
1105
|
+
// packages/experimental/assistant/src/ai-service/parser.ts
|
|
1106
|
+
import { Message as Message3 } from "@dxos/artifact";
|
|
1107
|
+
import { Event } from "@dxos/async";
|
|
1108
|
+
import { create as create2 } from "@dxos/echo-schema";
|
|
1109
|
+
import { invariant as invariant4 } from "@dxos/invariant";
|
|
1110
|
+
import { log as log5 } from "@dxos/log";
|
|
1111
|
+
import { isNotFalsy, safeParseJson } from "@dxos/util";
|
|
1112
|
+
|
|
1232
1113
|
// packages/experimental/assistant/src/ai-service/transform.ts
|
|
1233
1114
|
import * as P from "parsimmon";
|
|
1234
1115
|
var textChunk = P.regexp(/[^<]+/).map((content) => ({
|
|
@@ -1319,12 +1200,6 @@ var StreamTransform = class {
|
|
|
1319
1200
|
};
|
|
1320
1201
|
|
|
1321
1202
|
// packages/experimental/assistant/src/ai-service/parser.ts
|
|
1322
|
-
import { Message as Message3 } from "@dxos/artifact";
|
|
1323
|
-
import { Event } from "@dxos/async";
|
|
1324
|
-
import { create as create2 } from "@dxos/echo-schema";
|
|
1325
|
-
import { invariant as invariant4 } from "@dxos/invariant";
|
|
1326
|
-
import { log as log5 } from "@dxos/log";
|
|
1327
|
-
import { isNotFalsy, safeParseJson } from "@dxos/util";
|
|
1328
1203
|
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/experimental/assistant/src/ai-service/parser.ts";
|
|
1329
1204
|
var MixedStreamParser = class {
|
|
1330
1205
|
constructor() {
|
|
@@ -1736,10 +1611,596 @@ var mergeMessageBlock = (contentBlock, streamBlock) => {
|
|
|
1736
1611
|
}
|
|
1737
1612
|
};
|
|
1738
1613
|
|
|
1739
|
-
// packages/experimental/assistant/src/
|
|
1614
|
+
// packages/experimental/assistant/src/session/session.ts
|
|
1615
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
1616
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1617
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1618
|
+
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;
|
|
1619
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1620
|
+
}
|
|
1621
|
+
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/experimental/assistant/src/session/session.ts";
|
|
1622
|
+
var AISession = class _AISession {
|
|
1623
|
+
constructor(_options) {
|
|
1624
|
+
this._options = _options;
|
|
1625
|
+
this._parser = new MixedStreamParser();
|
|
1626
|
+
this._pending = [];
|
|
1627
|
+
this._history = [];
|
|
1628
|
+
this.message = this._parser.message;
|
|
1629
|
+
this.block = this._parser.block;
|
|
1630
|
+
this.update = this._parser.update;
|
|
1631
|
+
this.streamEvent = this._parser.streamEvent;
|
|
1632
|
+
this.userMessage = new Event2();
|
|
1633
|
+
this._parser.message.on((message) => {
|
|
1634
|
+
this._pending.push(message);
|
|
1635
|
+
});
|
|
1636
|
+
}
|
|
1637
|
+
async run(options) {
|
|
1638
|
+
const systemTools = [];
|
|
1639
|
+
switch (this._options.operationModel) {
|
|
1640
|
+
case "planning":
|
|
1641
|
+
systemTools.push(this._createQueryArtifactsTool(options.artifacts), this._createPlanningTool(options));
|
|
1642
|
+
break;
|
|
1643
|
+
case "importing":
|
|
1644
|
+
systemTools.push(this._createQueryArtifactsTool(options.artifacts), this._createRequireTool(options.artifacts, (artifactDefinitionIds) => {
|
|
1645
|
+
for (const artifactDefinitionId of artifactDefinitionIds) {
|
|
1646
|
+
requiredArtifactIds.add(artifactDefinitionId);
|
|
1647
|
+
}
|
|
1648
|
+
}));
|
|
1649
|
+
break;
|
|
1650
|
+
case "configured":
|
|
1651
|
+
break;
|
|
1652
|
+
default:
|
|
1653
|
+
throw new TypeError(`Invalid operation model: ${this._options.operationModel}`);
|
|
1654
|
+
}
|
|
1655
|
+
this._history = [
|
|
1656
|
+
...options.history
|
|
1657
|
+
];
|
|
1658
|
+
this._pending = [
|
|
1659
|
+
await this._formatUserPrompt(options.artifactDiffResolver, options.prompt, options.history)
|
|
1660
|
+
];
|
|
1661
|
+
this.userMessage.emit(this._pending.at(-1));
|
|
1662
|
+
this._stream = void 0;
|
|
1663
|
+
let error;
|
|
1664
|
+
const requiredArtifactIds = new Set(options.requiredArtifactIds ?? []);
|
|
1665
|
+
try {
|
|
1666
|
+
let more = false;
|
|
1667
|
+
do {
|
|
1668
|
+
const tools = [
|
|
1669
|
+
...systemTools,
|
|
1670
|
+
...options.tools,
|
|
1671
|
+
...options.artifacts.filter((artifact) => requiredArtifactIds.has(artifact.id)).flatMap((artifact) => artifact.tools)
|
|
1672
|
+
];
|
|
1673
|
+
log6("request", {
|
|
1674
|
+
pending: this._pending.length,
|
|
1675
|
+
history: this._history.length,
|
|
1676
|
+
tools: tools.map((tool) => tool.name)
|
|
1677
|
+
}, {
|
|
1678
|
+
F: __dxlog_file6,
|
|
1679
|
+
L: 181,
|
|
1680
|
+
S: this,
|
|
1681
|
+
C: (f, a) => f(...a)
|
|
1682
|
+
});
|
|
1683
|
+
this._stream = await options.client.execStream({
|
|
1684
|
+
...options.generationOptions ?? {},
|
|
1685
|
+
// TODO(burdon): Rename messages or separate history/message.
|
|
1686
|
+
history: [
|
|
1687
|
+
...this._history,
|
|
1688
|
+
...this._pending
|
|
1689
|
+
],
|
|
1690
|
+
tools,
|
|
1691
|
+
systemPrompt: options.systemPrompt ?? createBaseInstructions({
|
|
1692
|
+
availableArtifacts: Array.from(requiredArtifactIds),
|
|
1693
|
+
operationModel: this._options.operationModel
|
|
1694
|
+
})
|
|
1695
|
+
});
|
|
1696
|
+
await this._parser.parse(this._stream);
|
|
1697
|
+
await this._stream.complete();
|
|
1698
|
+
log6("response", {
|
|
1699
|
+
pending: this._pending
|
|
1700
|
+
}, {
|
|
1701
|
+
F: __dxlog_file6,
|
|
1702
|
+
L: 206,
|
|
1703
|
+
S: this,
|
|
1704
|
+
C: (f, a) => f(...a)
|
|
1705
|
+
});
|
|
1706
|
+
more = false;
|
|
1707
|
+
const message = this._pending.at(-1);
|
|
1708
|
+
invariant5(message, void 0, {
|
|
1709
|
+
F: __dxlog_file6,
|
|
1710
|
+
L: 211,
|
|
1711
|
+
S: this,
|
|
1712
|
+
A: [
|
|
1713
|
+
"message",
|
|
1714
|
+
""
|
|
1715
|
+
]
|
|
1716
|
+
});
|
|
1717
|
+
if (isToolUse(message)) {
|
|
1718
|
+
log6("tool request...", void 0, {
|
|
1719
|
+
F: __dxlog_file6,
|
|
1720
|
+
L: 213,
|
|
1721
|
+
S: this,
|
|
1722
|
+
C: (f, a) => f(...a)
|
|
1723
|
+
});
|
|
1724
|
+
const response = await runTools({
|
|
1725
|
+
message: this._pending.at(-1),
|
|
1726
|
+
tools,
|
|
1727
|
+
extensions: options.extensions ?? {}
|
|
1728
|
+
});
|
|
1729
|
+
log6("tool response", {
|
|
1730
|
+
response
|
|
1731
|
+
}, {
|
|
1732
|
+
F: __dxlog_file6,
|
|
1733
|
+
L: 220,
|
|
1734
|
+
S: this,
|
|
1735
|
+
C: (f, a) => f(...a)
|
|
1736
|
+
});
|
|
1737
|
+
switch (response.type) {
|
|
1738
|
+
case "continue": {
|
|
1739
|
+
this._pending = [
|
|
1740
|
+
...this._pending,
|
|
1741
|
+
response.message
|
|
1742
|
+
];
|
|
1743
|
+
this.userMessage.emit(response.message);
|
|
1744
|
+
more = true;
|
|
1745
|
+
break;
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
} while (more);
|
|
1750
|
+
} catch (err) {
|
|
1751
|
+
log6.catch(err, void 0, {
|
|
1752
|
+
F: __dxlog_file6,
|
|
1753
|
+
L: 232,
|
|
1754
|
+
S: this,
|
|
1755
|
+
C: (f, a) => f(...a)
|
|
1756
|
+
});
|
|
1757
|
+
if (err instanceof Error && err.message.includes("Overloaded")) {
|
|
1758
|
+
error = new AIServiecOverloadedError("AI service overloaded", {
|
|
1759
|
+
cause: err
|
|
1760
|
+
});
|
|
1761
|
+
} else {
|
|
1762
|
+
error = new Error("AI service error", {
|
|
1763
|
+
cause: err
|
|
1764
|
+
});
|
|
1765
|
+
}
|
|
1766
|
+
} finally {
|
|
1767
|
+
this._stream = void 0;
|
|
1768
|
+
}
|
|
1769
|
+
if (error) {
|
|
1770
|
+
throw error;
|
|
1771
|
+
}
|
|
1772
|
+
return this._pending;
|
|
1773
|
+
}
|
|
1774
|
+
async runStructured(schema, options) {
|
|
1775
|
+
const parser = structuredOutputParser(schema);
|
|
1776
|
+
const result = await this.run({
|
|
1777
|
+
...options,
|
|
1778
|
+
tools: [
|
|
1779
|
+
...options.tools,
|
|
1780
|
+
parser.tool
|
|
1781
|
+
]
|
|
1782
|
+
});
|
|
1783
|
+
return parser.getResult(result);
|
|
1784
|
+
}
|
|
1785
|
+
async _formatUserPrompt(artifactDiffResolver, prompt, history) {
|
|
1786
|
+
const prelude = [];
|
|
1787
|
+
if (artifactDiffResolver) {
|
|
1788
|
+
const versions = gatherObjectVersions(history);
|
|
1789
|
+
const artifactDiff = await artifactDiffResolver(Array.from(versions.entries()).map(([id, version]) => ({
|
|
1790
|
+
id,
|
|
1791
|
+
lastVersion: version
|
|
1792
|
+
})));
|
|
1793
|
+
log6.info("vision", {
|
|
1794
|
+
artifactDiff,
|
|
1795
|
+
versions
|
|
1796
|
+
}, {
|
|
1797
|
+
F: __dxlog_file6,
|
|
1798
|
+
L: 272,
|
|
1799
|
+
S: this,
|
|
1800
|
+
C: (f, a) => f(...a)
|
|
1801
|
+
});
|
|
1802
|
+
for (const [id, { version }] of [
|
|
1803
|
+
...artifactDiff.entries()
|
|
1804
|
+
]) {
|
|
1805
|
+
if (ObjectVersion.equals(version, versions.get(id))) {
|
|
1806
|
+
artifactDiff.delete(id);
|
|
1807
|
+
continue;
|
|
1808
|
+
}
|
|
1809
|
+
prelude.push(VersionPin.createBlock(VersionPin.make({
|
|
1810
|
+
objectId: id,
|
|
1811
|
+
version
|
|
1812
|
+
})));
|
|
1813
|
+
}
|
|
1814
|
+
if (artifactDiff.size > 0) {
|
|
1815
|
+
prelude.push(createArtifactUpdateBlock(artifactDiff));
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
return create3(Message4, {
|
|
1819
|
+
role: "user",
|
|
1820
|
+
content: [
|
|
1821
|
+
...prelude,
|
|
1822
|
+
{
|
|
1823
|
+
type: "text",
|
|
1824
|
+
text: prompt
|
|
1825
|
+
}
|
|
1826
|
+
]
|
|
1827
|
+
});
|
|
1828
|
+
}
|
|
1829
|
+
_createQueryArtifactsTool(artifacts) {
|
|
1830
|
+
return defineTool2("system", {
|
|
1831
|
+
name: "query_artifact_definitions",
|
|
1832
|
+
description: "Query the available artifact definitions",
|
|
1833
|
+
schema: Schema4.Struct({}),
|
|
1834
|
+
execute: async () => {
|
|
1835
|
+
return ToolResult3.Success({
|
|
1836
|
+
artifactDefinitions: artifacts.map((artifact) => ({
|
|
1837
|
+
id: artifact.id,
|
|
1838
|
+
name: artifact.name,
|
|
1839
|
+
description: artifact.description
|
|
1840
|
+
}))
|
|
1841
|
+
});
|
|
1842
|
+
}
|
|
1843
|
+
});
|
|
1844
|
+
}
|
|
1845
|
+
_createRequireTool(artifacts, onRequire) {
|
|
1846
|
+
return defineTool2("system", {
|
|
1847
|
+
name: "require_artifact_definitions",
|
|
1848
|
+
description: "Require the use of specific artifact definitions. This will allow the model to interact with artifact definitions and use their tools.",
|
|
1849
|
+
schema: Schema4.Struct({
|
|
1850
|
+
artifactDefinitionIds: Schema4.Array(Schema4.String).annotations({
|
|
1851
|
+
description: "The ids of the artifact definitions to require",
|
|
1852
|
+
examples: [
|
|
1853
|
+
[
|
|
1854
|
+
"artifact:dxos.org/example/Test"
|
|
1855
|
+
]
|
|
1856
|
+
]
|
|
1857
|
+
})
|
|
1858
|
+
}),
|
|
1859
|
+
execute: async ({ artifactDefinitionIds }) => {
|
|
1860
|
+
const missingArtifactDefinitionIds = artifactDefinitionIds.filter((artifactId) => !artifacts.some((artifact) => artifact.id === artifactId));
|
|
1861
|
+
if (missingArtifactDefinitionIds.length > 0) {
|
|
1862
|
+
return ToolResult3.Error(`One or more artifact definition ids are invalid: ${missingArtifactDefinitionIds.join(", ")}`);
|
|
1863
|
+
}
|
|
1864
|
+
onRequire(artifactDefinitionIds);
|
|
1865
|
+
return ToolResult3.Success({});
|
|
1866
|
+
}
|
|
1867
|
+
});
|
|
1868
|
+
}
|
|
1869
|
+
_createPlanningTool(options) {
|
|
1870
|
+
return defineTool2("system", {
|
|
1871
|
+
name: "create_plan",
|
|
1872
|
+
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.",
|
|
1873
|
+
schema: Schema4.Struct({
|
|
1874
|
+
goal: Schema4.String.annotations({
|
|
1875
|
+
description: "The goal that the plan will achieve."
|
|
1876
|
+
}),
|
|
1877
|
+
steps: Schema4.Array(Schema4.Struct({
|
|
1878
|
+
action: Schema4.String.annotations({
|
|
1879
|
+
description: "Complete, detailed action to perform."
|
|
1880
|
+
}),
|
|
1881
|
+
input: Schema4.String.annotations({
|
|
1882
|
+
description: "The required input data for this step. First step must not require any data."
|
|
1883
|
+
}),
|
|
1884
|
+
output: Schema4.String.annotations({
|
|
1885
|
+
description: "The output data from this step. This is passed to the next step as input."
|
|
1886
|
+
}),
|
|
1887
|
+
requiredArtifactIds: Schema4.Array(Schema4.String).annotations({
|
|
1888
|
+
description: "The ids of the artifacts required to perform this step.",
|
|
1889
|
+
examples: [
|
|
1890
|
+
[
|
|
1891
|
+
"artifact:dxos.org/example/Test"
|
|
1892
|
+
]
|
|
1893
|
+
]
|
|
1894
|
+
})
|
|
1895
|
+
})).annotations({
|
|
1896
|
+
description: "Steps"
|
|
1897
|
+
})
|
|
1898
|
+
}),
|
|
1899
|
+
execute: async ({ goal, steps }) => {
|
|
1900
|
+
const missingArtifactIds = steps.flatMap((step) => step.requiredArtifactIds).filter((artifactId) => !options.artifacts.some((artifact) => artifact.id === artifactId));
|
|
1901
|
+
if (missingArtifactIds.length > 0) {
|
|
1902
|
+
return ToolResult3.Error(`One or more artifact ids are invalid: ${missingArtifactIds.join(", ")}`);
|
|
1903
|
+
}
|
|
1904
|
+
const stepResults = [];
|
|
1905
|
+
for (const step of steps) {
|
|
1906
|
+
log6("executing step", {
|
|
1907
|
+
action: step.action
|
|
1908
|
+
}, {
|
|
1909
|
+
F: __dxlog_file6,
|
|
1910
|
+
L: 379,
|
|
1911
|
+
S: this,
|
|
1912
|
+
C: (f, a) => f(...a)
|
|
1913
|
+
});
|
|
1914
|
+
const session = new _AISession({
|
|
1915
|
+
operationModel: "importing"
|
|
1916
|
+
});
|
|
1917
|
+
session.message.on((ev) => this.message.emit(ev));
|
|
1918
|
+
session.block.on((ev) => this.block.emit(ev));
|
|
1919
|
+
session.update.on((ev) => this.update.emit(ev));
|
|
1920
|
+
session.streamEvent.on((ev) => this.streamEvent.emit(ev));
|
|
1921
|
+
session.userMessage.on((ev) => this.userMessage.emit(ev));
|
|
1922
|
+
const messages = await session.run({
|
|
1923
|
+
client: options.client,
|
|
1924
|
+
artifacts: options.artifacts,
|
|
1925
|
+
tools: options.tools,
|
|
1926
|
+
history: options.history,
|
|
1927
|
+
extensions: options.extensions,
|
|
1928
|
+
generationOptions: options.generationOptions,
|
|
1929
|
+
requiredArtifactIds: step.requiredArtifactIds.slice(),
|
|
1930
|
+
artifactDiffResolver: options.artifactDiffResolver,
|
|
1931
|
+
prompt: `
|
|
1932
|
+
You are an agent that executes the subtask in a plan.
|
|
1933
|
+
|
|
1934
|
+
While you know the plan's goal only focus on your subtask
|
|
1935
|
+
Use the data from the previous step to complete your task.
|
|
1936
|
+
Return all of the data from "output" in your last message.
|
|
1937
|
+
|
|
1938
|
+
Current step (that you need to complete):
|
|
1939
|
+
${JSON.stringify({
|
|
1940
|
+
goal,
|
|
1941
|
+
input: step.input,
|
|
1942
|
+
output: step.output,
|
|
1943
|
+
yourTask: step.action
|
|
1944
|
+
}, null, 2)}
|
|
1945
|
+
|
|
1946
|
+
Previous step results:
|
|
1947
|
+
${JSON.stringify(stepResults.at(-1))}.
|
|
1948
|
+
`
|
|
1949
|
+
});
|
|
1950
|
+
const result = messages.at(-1);
|
|
1951
|
+
stepResults.push(result);
|
|
1952
|
+
}
|
|
1953
|
+
return ToolResult3.Success({
|
|
1954
|
+
stepResults
|
|
1955
|
+
});
|
|
1956
|
+
}
|
|
1957
|
+
});
|
|
1958
|
+
}
|
|
1959
|
+
abort() {
|
|
1960
|
+
this._stream?.abort();
|
|
1961
|
+
}
|
|
1962
|
+
};
|
|
1963
|
+
_ts_decorate([
|
|
1964
|
+
synchronized
|
|
1965
|
+
], AISession.prototype, "run", null);
|
|
1966
|
+
var createBaseInstructions = ({ availableArtifacts, operationModel }) => `
|
|
1967
|
+
You are a friendly, advanced AI assistant capable of creating and managing artifacts from available data and tools.
|
|
1968
|
+
Your task is to process user commands and questions and decide how best to respond.
|
|
1969
|
+
In some cases, you will need to create or reference data objects called artifacts.
|
|
1970
|
+
|
|
1971
|
+
Follow these guidelines carefully:
|
|
1972
|
+
|
|
1973
|
+
Decision-making:
|
|
1974
|
+
|
|
1975
|
+
- Analyze the structure and type of the content in the user's message.
|
|
1976
|
+
|
|
1977
|
+
|
|
1978
|
+
${operationModel === "planning" ? `
|
|
1979
|
+
- Can you complete the task using the available artifacts?
|
|
1980
|
+
- If you can't complete the task using the available artifacts, query the list of available artifacts using the appropriate tool.
|
|
1981
|
+
- Identify which artifacts are relevant to the user's request.
|
|
1982
|
+
- 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.
|
|
1983
|
+
` : ""}
|
|
1984
|
+
${operationModel === "importing" ? `
|
|
1985
|
+
- Can you complete the task using the available artifacts?
|
|
1986
|
+
- If you can't complete the task using the available artifacts, query the list of available artifacts using the appropriate tool.
|
|
1987
|
+
- Identify which artifacts are relevant to the user's request.
|
|
1988
|
+
- Are the required artifacts already available?
|
|
1989
|
+
- If not, select which artifact(s) will be the most relevant and require them using the require_artifacts tool.
|
|
1990
|
+
- The require'd artifact tools will be available for use after require.
|
|
1991
|
+
` : ""}
|
|
1992
|
+
${operationModel === "configured" ? `
|
|
1993
|
+
- Select the most relevant artifact(s) to complete the task.
|
|
1994
|
+
- Call the appropriate tool to use the artifact(s).
|
|
1995
|
+
` : ""}
|
|
1996
|
+
|
|
1997
|
+
${availableArtifacts.length > 0 ? `Artifacts already in context: ${availableArtifacts.join("\n")}` : ""}
|
|
1998
|
+
`;
|
|
1999
|
+
var AIServiecOverloadedError = class extends Schema4.TaggedError()("AIServiecOverloadedError", {}) {
|
|
2000
|
+
};
|
|
2001
|
+
var gatherObjectVersions = (messages) => {
|
|
2002
|
+
const artifactIds = /* @__PURE__ */ new Map();
|
|
2003
|
+
for (const message of messages) {
|
|
2004
|
+
for (const block of message.content) {
|
|
2005
|
+
if (block.type === "json" && block.disposition === VersionPin.DISPOSITION) {
|
|
2006
|
+
const pin = VersionPin.pipe(Schema4.decodeOption)(JSON.parse(block.json)).pipe(Option.getOrUndefined);
|
|
2007
|
+
if (!pin) {
|
|
2008
|
+
continue;
|
|
2009
|
+
}
|
|
2010
|
+
artifactIds.set(pin.objectId, pin.version);
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
2014
|
+
return artifactIds;
|
|
2015
|
+
};
|
|
2016
|
+
var createArtifactUpdateBlock = (artifactDiff) => {
|
|
2017
|
+
return {
|
|
2018
|
+
type: "text",
|
|
2019
|
+
disposition: "artifact-update",
|
|
2020
|
+
text: `
|
|
2021
|
+
The following artifacts have been updated since the last message:
|
|
2022
|
+
${Array.from(artifactDiff.entries()).map(([id, { diff }]) => `<changed-artifact id="${id}">${diff ? `
|
|
2023
|
+
${diff}` : ""}</changed-artifact>`).join("\n")}
|
|
2024
|
+
`
|
|
2025
|
+
};
|
|
2026
|
+
};
|
|
2027
|
+
|
|
2028
|
+
// packages/experimental/assistant/src/experimental/conversation/conversation.ts
|
|
2029
|
+
import { ObjectId as ObjectId3 } from "@dxos/echo-schema";
|
|
2030
|
+
import { invariant as invariant6 } from "@dxos/invariant";
|
|
2031
|
+
import { log as log7 } from "@dxos/log";
|
|
2032
|
+
var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/experimental/assistant/src/experimental/conversation/conversation.ts";
|
|
2033
|
+
var runLLM = async (params) => {
|
|
2034
|
+
let conversationResult = null;
|
|
2035
|
+
const history = params.history ?? [];
|
|
2036
|
+
const generate = async () => {
|
|
2037
|
+
log7("llm generate", {
|
|
2038
|
+
tools: params.tools
|
|
2039
|
+
}, {
|
|
2040
|
+
F: __dxlog_file7,
|
|
2041
|
+
L: 44,
|
|
2042
|
+
S: void 0,
|
|
2043
|
+
C: (f, a) => f(...a)
|
|
2044
|
+
});
|
|
2045
|
+
const beginTs = Date.now();
|
|
2046
|
+
const stream = await params.client.execStream({
|
|
2047
|
+
model: params.model,
|
|
2048
|
+
history,
|
|
2049
|
+
systemPrompt: params.system,
|
|
2050
|
+
tools: params.tools
|
|
2051
|
+
});
|
|
2052
|
+
for await (const event of stream) {
|
|
2053
|
+
params.logger?.(event);
|
|
2054
|
+
}
|
|
2055
|
+
await stream.complete();
|
|
2056
|
+
const messages = [];
|
|
2057
|
+
const message = messages.at(-1);
|
|
2058
|
+
invariant6(message, void 0, {
|
|
2059
|
+
F: __dxlog_file7,
|
|
2060
|
+
L: 61,
|
|
2061
|
+
S: void 0,
|
|
2062
|
+
A: [
|
|
2063
|
+
"message",
|
|
2064
|
+
""
|
|
2065
|
+
]
|
|
2066
|
+
});
|
|
2067
|
+
log7("llm result", {
|
|
2068
|
+
time: Date.now() - beginTs,
|
|
2069
|
+
message
|
|
2070
|
+
}, {
|
|
2071
|
+
F: __dxlog_file7,
|
|
2072
|
+
L: 63,
|
|
2073
|
+
S: void 0,
|
|
2074
|
+
C: (f, a) => f(...a)
|
|
2075
|
+
});
|
|
2076
|
+
invariant6(message, void 0, {
|
|
2077
|
+
F: __dxlog_file7,
|
|
2078
|
+
L: 64,
|
|
2079
|
+
S: void 0,
|
|
2080
|
+
A: [
|
|
2081
|
+
"message",
|
|
2082
|
+
""
|
|
2083
|
+
]
|
|
2084
|
+
});
|
|
2085
|
+
params.logger?.({
|
|
2086
|
+
type: "message",
|
|
2087
|
+
message
|
|
2088
|
+
});
|
|
2089
|
+
history.push(...messages.map((message2) => ({
|
|
2090
|
+
...message2,
|
|
2091
|
+
content: message2.content.filter((block) => block.type !== "image")
|
|
2092
|
+
})));
|
|
2093
|
+
const isToolUse2 = message.content.at(-1)?.type === "tool_use";
|
|
2094
|
+
if (isToolUse2) {
|
|
2095
|
+
const toolCalls = message.content.filter((block) => block.type === "tool_use");
|
|
2096
|
+
invariant6(toolCalls.length === 1, void 0, {
|
|
2097
|
+
F: __dxlog_file7,
|
|
2098
|
+
L: 75,
|
|
2099
|
+
S: void 0,
|
|
2100
|
+
A: [
|
|
2101
|
+
"toolCalls.length === 1",
|
|
2102
|
+
""
|
|
2103
|
+
]
|
|
2104
|
+
});
|
|
2105
|
+
const toolCall = toolCalls[0];
|
|
2106
|
+
const tool = params.tools.find((tool2) => tool2.name === toolCall.name);
|
|
2107
|
+
if (!tool) {
|
|
2108
|
+
throw new Error(`Tool not found: ${toolCall.name}`);
|
|
2109
|
+
}
|
|
2110
|
+
invariant6(tool.execute, void 0, {
|
|
2111
|
+
F: __dxlog_file7,
|
|
2112
|
+
L: 82,
|
|
2113
|
+
S: void 0,
|
|
2114
|
+
A: [
|
|
2115
|
+
"tool.execute",
|
|
2116
|
+
""
|
|
2117
|
+
]
|
|
2118
|
+
});
|
|
2119
|
+
const toolResult = await tool.execute(toolCall.input);
|
|
2120
|
+
switch (toolResult.kind) {
|
|
2121
|
+
case "error": {
|
|
2122
|
+
log7.warn("tool error", {
|
|
2123
|
+
message: toolResult.message
|
|
2124
|
+
}, {
|
|
2125
|
+
F: __dxlog_file7,
|
|
2126
|
+
L: 86,
|
|
2127
|
+
S: void 0,
|
|
2128
|
+
C: (f, a) => f(...a)
|
|
2129
|
+
});
|
|
2130
|
+
const resultMessage = {
|
|
2131
|
+
id: ObjectId3.random(),
|
|
2132
|
+
role: "user",
|
|
2133
|
+
content: [
|
|
2134
|
+
{
|
|
2135
|
+
type: "tool_result",
|
|
2136
|
+
toolUseId: toolCall.id,
|
|
2137
|
+
content: toolResult.message,
|
|
2138
|
+
isError: true
|
|
2139
|
+
}
|
|
2140
|
+
]
|
|
2141
|
+
};
|
|
2142
|
+
params.logger?.({
|
|
2143
|
+
type: "message",
|
|
2144
|
+
message: resultMessage
|
|
2145
|
+
});
|
|
2146
|
+
history.push(resultMessage);
|
|
2147
|
+
return true;
|
|
2148
|
+
}
|
|
2149
|
+
case "success": {
|
|
2150
|
+
log7("tool success", {
|
|
2151
|
+
result: toolResult.result
|
|
2152
|
+
}, {
|
|
2153
|
+
F: __dxlog_file7,
|
|
2154
|
+
L: 106,
|
|
2155
|
+
S: void 0,
|
|
2156
|
+
C: (f, a) => f(...a)
|
|
2157
|
+
});
|
|
2158
|
+
const resultMessage = {
|
|
2159
|
+
id: ObjectId3.random(),
|
|
2160
|
+
role: "user",
|
|
2161
|
+
content: [
|
|
2162
|
+
{
|
|
2163
|
+
type: "tool_result",
|
|
2164
|
+
toolUseId: toolCall.id,
|
|
2165
|
+
content: JSON.stringify(toolResult.result)
|
|
2166
|
+
}
|
|
2167
|
+
]
|
|
2168
|
+
};
|
|
2169
|
+
params.logger?.({
|
|
2170
|
+
type: "message",
|
|
2171
|
+
message: resultMessage
|
|
2172
|
+
});
|
|
2173
|
+
history.push(resultMessage);
|
|
2174
|
+
return true;
|
|
2175
|
+
}
|
|
2176
|
+
case "break": {
|
|
2177
|
+
log7("tool break", {
|
|
2178
|
+
result: toolResult.result
|
|
2179
|
+
}, {
|
|
2180
|
+
F: __dxlog_file7,
|
|
2181
|
+
L: 125,
|
|
2182
|
+
S: void 0,
|
|
2183
|
+
C: (f, a) => f(...a)
|
|
2184
|
+
});
|
|
2185
|
+
conversationResult = toolResult.result;
|
|
2186
|
+
return false;
|
|
2187
|
+
}
|
|
2188
|
+
}
|
|
2189
|
+
}
|
|
2190
|
+
return false;
|
|
2191
|
+
};
|
|
2192
|
+
while (await generate()) {
|
|
2193
|
+
}
|
|
2194
|
+
return {
|
|
2195
|
+
result: conversationResult,
|
|
2196
|
+
history
|
|
2197
|
+
};
|
|
2198
|
+
};
|
|
2199
|
+
|
|
2200
|
+
// packages/experimental/assistant/src/experimental/cypher/parjs.ts
|
|
1740
2201
|
import { parjsCombinators, parjs } from "#parjs";
|
|
1741
2202
|
|
|
1742
|
-
// packages/experimental/assistant/src/cypher/combinators.ts
|
|
2203
|
+
// packages/experimental/assistant/src/experimental/cypher/combinators.ts
|
|
1743
2204
|
var ws = parjs.whitespace();
|
|
1744
2205
|
var nothing = parjs.string("").pipe(parjsCombinators.map(() => null));
|
|
1745
2206
|
var optional = (parser) => parser.pipe(parjsCombinators.recover(() => ({
|
|
@@ -1813,7 +2274,7 @@ var cypherQuery = ws.pipe(parjsCombinators.then(matchClause, ws, optional(whereC
|
|
|
1813
2274
|
returnClause: returnClause2
|
|
1814
2275
|
})));
|
|
1815
2276
|
|
|
1816
|
-
// packages/experimental/assistant/src/cypher/parser.ts
|
|
2277
|
+
// packages/experimental/assistant/src/experimental/cypher/parser.ts
|
|
1817
2278
|
var parseCypherQuery = (query) => {
|
|
1818
2279
|
const parseResult = cypherQuery.parse(query);
|
|
1819
2280
|
if (parseResult.isOk) {
|
|
@@ -1825,14 +2286,14 @@ var parseCypherQuery = (query) => {
|
|
|
1825
2286
|
}
|
|
1826
2287
|
};
|
|
1827
2288
|
|
|
1828
|
-
// packages/experimental/assistant/src/cypher/query-executor.ts
|
|
1829
|
-
import { log as
|
|
2289
|
+
// packages/experimental/assistant/src/experimental/cypher/query-executor.ts
|
|
2290
|
+
import { log as log9 } from "@dxos/log";
|
|
1830
2291
|
import { mapValues } from "@dxos/util";
|
|
1831
2292
|
|
|
1832
|
-
// packages/experimental/assistant/src/cypher/execution-plan.ts
|
|
1833
|
-
import { invariant as
|
|
1834
|
-
import { log as
|
|
1835
|
-
var
|
|
2293
|
+
// packages/experimental/assistant/src/experimental/cypher/execution-plan.ts
|
|
2294
|
+
import { invariant as invariant7 } from "@dxos/invariant";
|
|
2295
|
+
import { log as log8 } from "@dxos/log";
|
|
2296
|
+
var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/experimental/assistant/src/experimental/cypher/execution-plan.ts";
|
|
1836
2297
|
var createExecutionPlan = (query) => {
|
|
1837
2298
|
return new ExecutionPlanBuilder().build(query);
|
|
1838
2299
|
};
|
|
@@ -1844,10 +2305,10 @@ var ExecutionPlanBuilder = class {
|
|
|
1844
2305
|
return `anon_${this.counter++}`;
|
|
1845
2306
|
}
|
|
1846
2307
|
build(query) {
|
|
1847
|
-
|
|
2308
|
+
log8("Creating execution plan for query", {
|
|
1848
2309
|
query
|
|
1849
2310
|
}, {
|
|
1850
|
-
F:
|
|
2311
|
+
F: __dxlog_file8,
|
|
1851
2312
|
L: 76,
|
|
1852
2313
|
S: this,
|
|
1853
2314
|
C: (f, a) => f(...a)
|
|
@@ -1864,8 +2325,8 @@ var ExecutionPlanBuilder = class {
|
|
|
1864
2325
|
};
|
|
1865
2326
|
}
|
|
1866
2327
|
createStepsForMatchClause(match) {
|
|
1867
|
-
|
|
1868
|
-
F:
|
|
2328
|
+
invariant7(match.pattern.segments.length > 0, void 0, {
|
|
2329
|
+
F: __dxlog_file8,
|
|
1869
2330
|
L: 90,
|
|
1870
2331
|
S: this,
|
|
1871
2332
|
A: [
|
|
@@ -1874,8 +2335,8 @@ var ExecutionPlanBuilder = class {
|
|
|
1874
2335
|
]
|
|
1875
2336
|
});
|
|
1876
2337
|
const firstSegment = match.pattern.segments[0];
|
|
1877
|
-
|
|
1878
|
-
F:
|
|
2338
|
+
invariant7(firstSegment.astKind === "NodePattern", void 0, {
|
|
2339
|
+
F: __dxlog_file8,
|
|
1879
2340
|
L: 92,
|
|
1880
2341
|
S: this,
|
|
1881
2342
|
A: [
|
|
@@ -1902,8 +2363,8 @@ var ExecutionPlanBuilder = class {
|
|
|
1902
2363
|
}
|
|
1903
2364
|
for (let i = 1; i < match.pattern.segments.length; i++) {
|
|
1904
2365
|
const relationshipSegment = match.pattern.segments[i++];
|
|
1905
|
-
|
|
1906
|
-
F:
|
|
2366
|
+
invariant7(relationshipSegment.astKind === "RelationshipPattern", void 0, {
|
|
2367
|
+
F: __dxlog_file8,
|
|
1907
2368
|
L: 115,
|
|
1908
2369
|
S: this,
|
|
1909
2370
|
A: [
|
|
@@ -1912,8 +2373,8 @@ var ExecutionPlanBuilder = class {
|
|
|
1912
2373
|
]
|
|
1913
2374
|
});
|
|
1914
2375
|
const nodeSegment = match.pattern.segments[i];
|
|
1915
|
-
|
|
1916
|
-
F:
|
|
2376
|
+
invariant7(nodeSegment.astKind === "NodePattern", void 0, {
|
|
2377
|
+
F: __dxlog_file8,
|
|
1917
2378
|
L: 117,
|
|
1918
2379
|
S: this,
|
|
1919
2380
|
A: [
|
|
@@ -1995,16 +2456,16 @@ var getDirection = (left, right) => {
|
|
|
1995
2456
|
throw new Error(`Invalid direction: ()${left}[]${right}()`);
|
|
1996
2457
|
};
|
|
1997
2458
|
|
|
1998
|
-
// packages/experimental/assistant/src/cypher/query-executor.ts
|
|
1999
|
-
var
|
|
2459
|
+
// packages/experimental/assistant/src/experimental/cypher/query-executor.ts
|
|
2460
|
+
var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/experimental/assistant/src/experimental/cypher/query-executor.ts";
|
|
2000
2461
|
var executeQueryPlan = async (dataSource, plan) => {
|
|
2001
2462
|
let buffer = [];
|
|
2002
2463
|
const results = [];
|
|
2003
2464
|
for (const step of plan.steps) {
|
|
2004
|
-
|
|
2465
|
+
log9("begin step", {
|
|
2005
2466
|
step
|
|
2006
2467
|
}, {
|
|
2007
|
-
F:
|
|
2468
|
+
F: __dxlog_file9,
|
|
2008
2469
|
L: 41,
|
|
2009
2470
|
S: void 0,
|
|
2010
2471
|
C: (f, a) => f(...a)
|
|
@@ -2090,11 +2551,11 @@ var executeQueryPlan = async (dataSource, plan) => {
|
|
|
2090
2551
|
break;
|
|
2091
2552
|
}
|
|
2092
2553
|
}
|
|
2093
|
-
|
|
2554
|
+
log9("finish step", {
|
|
2094
2555
|
buffer: buffer.map((tuple) => mapValues(tuple, (x) => x.id)),
|
|
2095
2556
|
results
|
|
2096
2557
|
}, {
|
|
2097
|
-
F:
|
|
2558
|
+
F: __dxlog_file9,
|
|
2098
2559
|
L: 118,
|
|
2099
2560
|
S: void 0,
|
|
2100
2561
|
C: (f, a) => f(...a)
|
|
@@ -2121,7 +2582,7 @@ var jsonPathGet = (obj, path) => {
|
|
|
2121
2582
|
return result;
|
|
2122
2583
|
};
|
|
2123
2584
|
|
|
2124
|
-
// packages/experimental/assistant/src/cypher/schema.ts
|
|
2585
|
+
// packages/experimental/assistant/src/experimental/cypher/schema.ts
|
|
2125
2586
|
import { raise } from "@dxos/debug";
|
|
2126
2587
|
import { JSON_SCHEMA_ECHO_REF_ID } from "@dxos/echo-schema";
|
|
2127
2588
|
|
|
@@ -2133,7 +2594,7 @@ var trim = (strings, ...values) => {
|
|
|
2133
2594
|
return combined.replace("/^\n/", "").replace(/\n$/, "");
|
|
2134
2595
|
};
|
|
2135
2596
|
|
|
2136
|
-
// packages/experimental/assistant/src/cypher/schema.ts
|
|
2597
|
+
// packages/experimental/assistant/src/experimental/cypher/schema.ts
|
|
2137
2598
|
var formatJsonSchemaForLLM = (schemaTypes) => {
|
|
2138
2599
|
return schemaTypes.flatMap((schema) => [
|
|
2139
2600
|
formatNodeSchema(schema),
|
|
@@ -2187,18 +2648,18 @@ var formatInferredRelationshipLabel = (typename, property2) => {
|
|
|
2187
2648
|
};
|
|
2188
2649
|
var isReference = (schema) => schema.$id === JSON_SCHEMA_ECHO_REF_ID || schema.type === "array" && !Array.isArray(schema.items) && typeof schema.items === "object" && "$id" in schema.items && schema.items.$id === JSON_SCHEMA_ECHO_REF_ID;
|
|
2189
2650
|
|
|
2190
|
-
// packages/experimental/assistant/src/cypher/echo-data-source.ts
|
|
2651
|
+
// packages/experimental/assistant/src/experimental/cypher/echo-data-source.ts
|
|
2191
2652
|
import { raise as raise2 } from "@dxos/debug";
|
|
2192
2653
|
import { Filter } from "@dxos/echo-db";
|
|
2193
2654
|
import { getSchema, getSchemaTypename, StoredSchema, toJsonSchema } from "@dxos/echo-schema";
|
|
2194
|
-
import { log as
|
|
2195
|
-
function
|
|
2655
|
+
import { log as log10 } from "@dxos/log";
|
|
2656
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
2196
2657
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2197
2658
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2198
2659
|
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;
|
|
2199
2660
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2200
2661
|
}
|
|
2201
|
-
var
|
|
2662
|
+
var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/experimental/assistant/src/experimental/cypher/echo-data-source.ts";
|
|
2202
2663
|
var EchoDataSource = class {
|
|
2203
2664
|
constructor(_db) {
|
|
2204
2665
|
this._db = _db;
|
|
@@ -2208,11 +2669,11 @@ var EchoDataSource = class {
|
|
|
2208
2669
|
const { objects: objects2 } = await this._db.query().run();
|
|
2209
2670
|
return objects2.map(this._objectToNode);
|
|
2210
2671
|
}
|
|
2211
|
-
const schema = (await this._getAllSchema()).find((
|
|
2672
|
+
const schema = (await this._getAllSchema()).find((schema2) => getSchemaTypename(schema2)?.endsWith(label2));
|
|
2212
2673
|
if (!schema) {
|
|
2213
2674
|
return [];
|
|
2214
2675
|
}
|
|
2215
|
-
const { objects } = await this._db.query(Filter.
|
|
2676
|
+
const { objects } = await this._db.query(Filter.type(schema)).run();
|
|
2216
2677
|
return objects.map(this._objectToNode);
|
|
2217
2678
|
}
|
|
2218
2679
|
async getRelationships({ label: label2 }) {
|
|
@@ -2232,14 +2693,14 @@ var EchoDataSource = class {
|
|
|
2232
2693
|
if (!relationship) {
|
|
2233
2694
|
return [];
|
|
2234
2695
|
}
|
|
2235
|
-
const { objects } = await this._db.query(Filter.
|
|
2696
|
+
const { objects } = await this._db.query(Filter.type(relationship.schema)).run();
|
|
2236
2697
|
return (await Promise.all(objects.map((object) => this._projectRefRelationship(object, relationship.property)))).flat();
|
|
2237
2698
|
}
|
|
2238
2699
|
async _getAllSchema() {
|
|
2239
2700
|
return [
|
|
2240
2701
|
...await this._db.schemaRegistry.query().run(),
|
|
2241
2702
|
// TODO(dmaretskyi): Remove once we can serialize recursive schema.
|
|
2242
|
-
...this._db.graph.schemaRegistry.schemas.filter((
|
|
2703
|
+
...this._db.graph.schemaRegistry.schemas.filter((schema) => getSchemaTypename(schema)?.startsWith("example.org"))
|
|
2243
2704
|
].filter((schema) => getSchemaTypename(schema) !== StoredSchema.typename);
|
|
2244
2705
|
}
|
|
2245
2706
|
_objectToNode(object) {
|
|
@@ -2271,18 +2732,18 @@ var EchoDataSource = class {
|
|
|
2271
2732
|
}));
|
|
2272
2733
|
}
|
|
2273
2734
|
};
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
F:
|
|
2277
|
-
L:
|
|
2735
|
+
_ts_decorate2([
|
|
2736
|
+
log10.method(void 0, void 0, {
|
|
2737
|
+
F: __dxlog_file10,
|
|
2738
|
+
L: 18,
|
|
2278
2739
|
S: void 0,
|
|
2279
2740
|
C: (f, a) => f(...a)
|
|
2280
2741
|
})
|
|
2281
2742
|
], EchoDataSource.prototype, "getNodes", null);
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
F:
|
|
2285
|
-
L:
|
|
2743
|
+
_ts_decorate2([
|
|
2744
|
+
log10.method(void 0, void 0, {
|
|
2745
|
+
F: __dxlog_file10,
|
|
2746
|
+
L: 34,
|
|
2286
2747
|
S: void 0,
|
|
2287
2748
|
C: (f, a) => f(...a)
|
|
2288
2749
|
})
|
|
@@ -2304,13 +2765,16 @@ export {
|
|
|
2304
2765
|
ToolTypes,
|
|
2305
2766
|
GenerateRequest,
|
|
2306
2767
|
GenerateResponse,
|
|
2307
|
-
runLLM,
|
|
2308
2768
|
isToolUse,
|
|
2309
2769
|
runTools,
|
|
2770
|
+
VersionPin,
|
|
2771
|
+
AISession,
|
|
2772
|
+
AIServiecOverloadedError,
|
|
2310
2773
|
OllamaClient,
|
|
2311
2774
|
StreamTransform,
|
|
2312
2775
|
MixedStreamParser,
|
|
2313
2776
|
mergeMessageBlock,
|
|
2777
|
+
runLLM,
|
|
2314
2778
|
parseCypherQuery,
|
|
2315
2779
|
executeQueryPlan,
|
|
2316
2780
|
executeQuery,
|
|
@@ -2321,4 +2785,4 @@ export {
|
|
|
2321
2785
|
isReference,
|
|
2322
2786
|
EchoDataSource
|
|
2323
2787
|
};
|
|
2324
|
-
//# sourceMappingURL=chunk-
|
|
2788
|
+
//# sourceMappingURL=chunk-SAWYU3V5.mjs.map
|