@dxos/assistant 0.8.1 → 0.8.2-main.2f9c567
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-PND5VR6D.mjs → chunk-OLO6SVOL.mjs} +91 -84
- package/dist/lib/browser/chunk-OLO6SVOL.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +276 -154
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +98 -102
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node/{chunk-IBOBRBDF.cjs → chunk-CI5Q7FBG.cjs} +106 -98
- package/dist/lib/node/chunk-CI5Q7FBG.cjs.map +7 -0
- package/dist/lib/node/index.cjs +302 -183
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +88 -93
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/lib/node-esm/{chunk-DCQJOLSR.mjs → chunk-Y3SYOFFJ.mjs} +91 -84
- package/dist/lib/node-esm/chunk-Y3SYOFFJ.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +276 -154
- 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 +98 -102
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/ai-service/edge-client.d.ts +4 -5
- package/dist/types/src/ai-service/edge-client.d.ts.map +1 -1
- package/dist/types/src/ai-service/message-collector.d.ts +0 -6
- package/dist/types/src/ai-service/message-collector.d.ts.map +1 -1
- package/dist/types/src/ai-service/ollama-client.d.ts +6 -2
- package/dist/types/src/ai-service/ollama-client.d.ts.map +1 -1
- package/dist/types/src/ai-service/parser.d.ts +0 -3
- package/dist/types/src/ai-service/parser.d.ts.map +1 -1
- package/dist/types/src/ai-service/service.d.ts +18 -2
- package/dist/types/src/ai-service/service.d.ts.map +1 -1
- package/dist/types/src/ai-service/testing/mock.d.ts +6 -2
- package/dist/types/src/ai-service/testing/mock.d.ts.map +1 -1
- package/dist/types/src/ai-service/types.d.ts +144 -101
- package/dist/types/src/ai-service/types.d.ts.map +1 -1
- package/dist/types/src/conversation/conversation.d.ts +0 -3
- package/dist/types/src/conversation/conversation.d.ts.map +1 -1
- package/dist/types/src/conversation/types.d.ts +11 -12
- package/dist/types/src/conversation/types.d.ts.map +1 -1
- package/dist/types/src/cypher/echo-data-source.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 +32 -13
- package/dist/types/src/session/session.d.ts.map +1 -1
- package/dist/types/src/session/version-pin.d.ts +17 -0
- package/dist/types/src/session/version-pin.d.ts.map +1 -0
- package/dist/types/src/session/version-pin.test.d.ts +2 -0
- package/dist/types/src/session/version-pin.test.d.ts.map +1 -0
- package/dist/types/src/testing/query-promts.d.ts +3 -3
- package/dist/types/src/testing/query-promts.d.ts.map +1 -1
- package/dist/types/src/testing/test-data.d.ts +4 -4
- 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/package.json +15 -14
- package/src/ai-service/client.test.ts +55 -73
- package/src/ai-service/edge-client.ts +13 -20
- package/src/ai-service/ollama-client.ts +16 -9
- package/src/ai-service/parser.ts +13 -2
- package/src/ai-service/service.ts +19 -3
- package/src/ai-service/testing/mock.ts +9 -1
- package/src/ai-service/types.ts +24 -15
- package/src/bin/chat.ts +3 -3
- package/src/conversation/conversation.test.ts +3 -3
- package/src/conversation/conversation.ts +5 -11
- package/src/conversation/types.ts +11 -14
- package/src/cypher/combinators.test.ts +4 -4
- package/src/cypher/echo-data-source.ts +7 -6
- package/src/cypher/execution-plan.test.ts +1 -1
- package/src/cypher/query-executor.test.ts +1 -1
- package/src/cypher/schema.test.ts +3 -3
- package/src/session/index.ts +1 -0
- package/src/session/session.test.ts +29 -22
- package/src/session/session.ts +286 -150
- package/src/session/version-pin.test.ts +26 -0
- package/src/session/version-pin.ts +43 -0
- package/src/testing/artifacts.test.ts +22 -22
- package/src/testing/query-promts.ts +5 -5
- package/src/testing/query.test.ts +17 -19
- package/src/testing/test-data.ts +78 -71
- package/src/testing/test-schema.ts +28 -29
- package/dist/lib/browser/chunk-PND5VR6D.mjs.map +0 -7
- package/dist/lib/node/chunk-IBOBRBDF.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-DCQJOLSR.mjs.map +0 -7
|
@@ -26,8 +26,8 @@ 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_CI5Q7FBG_exports = {};
|
|
30
|
+
__export(chunk_CI5Q7FBG_exports, {
|
|
31
31
|
AIServiceEdgeClient: () => AIServiceEdgeClient,
|
|
32
32
|
DEFAULT_EDGE_MODEL: () => DEFAULT_EDGE_MODEL,
|
|
33
33
|
DEFAULT_EDGE_MODELS: () => DEFAULT_EDGE_MODELS,
|
|
@@ -36,6 +36,7 @@ __export(chunk_IBOBRBDF_exports, {
|
|
|
36
36
|
DEFAULT_OLLAMA_MODELS: () => DEFAULT_OLLAMA_MODELS,
|
|
37
37
|
EchoDataSource: () => EchoDataSource,
|
|
38
38
|
GenerateRequest: () => GenerateRequest,
|
|
39
|
+
GenerateResponse: () => GenerateResponse,
|
|
39
40
|
GenerationStreamImpl: () => GenerationStreamImpl,
|
|
40
41
|
LLMModel: () => LLMModel,
|
|
41
42
|
MessageCollector: () => MessageCollector,
|
|
@@ -59,29 +60,26 @@ __export(chunk_IBOBRBDF_exports, {
|
|
|
59
60
|
runTools: () => runTools,
|
|
60
61
|
trim: () => trim
|
|
61
62
|
});
|
|
62
|
-
module.exports = __toCommonJS(
|
|
63
|
+
module.exports = __toCommonJS(chunk_CI5Q7FBG_exports);
|
|
63
64
|
var import_async = require("@dxos/async");
|
|
64
65
|
var import_log = require("@dxos/log");
|
|
65
|
-
var import_effect = require("effect");
|
|
66
|
-
var import_artifact = require("@dxos/artifact");
|
|
67
66
|
var import_invariant = require("@dxos/invariant");
|
|
68
67
|
var import_log2 = require("@dxos/log");
|
|
69
|
-
var
|
|
68
|
+
var import_effect = require("effect");
|
|
69
|
+
var import_artifact = require("@dxos/artifact");
|
|
70
70
|
var import_artifact2 = require("@dxos/artifact");
|
|
71
71
|
var import_echo_schema = require("@dxos/echo-schema");
|
|
72
|
-
var import_artifact3 = require("@dxos/artifact");
|
|
73
|
-
var import_echo_schema2 = require("@dxos/echo-schema");
|
|
74
72
|
var import_invariant2 = require("@dxos/invariant");
|
|
75
73
|
var import_log3 = require("@dxos/log");
|
|
76
|
-
var
|
|
77
|
-
var
|
|
78
|
-
var
|
|
74
|
+
var import_effect2 = require("effect");
|
|
75
|
+
var import_artifact3 = require("@dxos/artifact");
|
|
76
|
+
var import_echo_schema2 = require("@dxos/echo-schema");
|
|
79
77
|
var import_invariant3 = require("@dxos/invariant");
|
|
80
78
|
var import_log4 = require("@dxos/log");
|
|
81
79
|
var P = __toESM(require("parsimmon"));
|
|
82
|
-
var
|
|
80
|
+
var import_artifact4 = require("@dxos/artifact");
|
|
83
81
|
var import_async2 = require("@dxos/async");
|
|
84
|
-
var
|
|
82
|
+
var import_echo_schema3 = require("@dxos/echo-schema");
|
|
85
83
|
var import_invariant4 = require("@dxos/invariant");
|
|
86
84
|
var import_log5 = require("@dxos/log");
|
|
87
85
|
var import_util = require("@dxos/util");
|
|
@@ -91,11 +89,10 @@ var import_util2 = require("@dxos/util");
|
|
|
91
89
|
var import_invariant5 = require("@dxos/invariant");
|
|
92
90
|
var import_log7 = require("@dxos/log");
|
|
93
91
|
var import_debug = require("@dxos/debug");
|
|
94
|
-
var
|
|
92
|
+
var import_echo_schema4 = require("@dxos/echo-schema");
|
|
95
93
|
var import_debug2 = require("@dxos/debug");
|
|
96
94
|
var import_echo_db = require("@dxos/echo-db");
|
|
97
|
-
var
|
|
98
|
-
var import_live_object = require("@dxos/live-object");
|
|
95
|
+
var import_echo_schema5 = require("@dxos/echo-schema");
|
|
99
96
|
var import_log8 = require("@dxos/log");
|
|
100
97
|
var DEFAULT_EDGE_MODEL = "@anthropic/claude-3-5-sonnet-20241022";
|
|
101
98
|
var DEFAULT_EDGE_MODELS = [
|
|
@@ -451,7 +448,7 @@ var AIServiceEdgeClient = class {
|
|
|
451
448
|
constructor({ endpoint }) {
|
|
452
449
|
(0, import_invariant.invariant)(endpoint, "endpoint is required", {
|
|
453
450
|
F: __dxlog_file2,
|
|
454
|
-
L:
|
|
451
|
+
L: 20,
|
|
455
452
|
S: this,
|
|
456
453
|
A: [
|
|
457
454
|
"endpoint",
|
|
@@ -461,34 +458,21 @@ var AIServiceEdgeClient = class {
|
|
|
461
458
|
this._endpoint = endpoint;
|
|
462
459
|
}
|
|
463
460
|
/**
|
|
464
|
-
*
|
|
461
|
+
* Generate non-streaming response.
|
|
465
462
|
*/
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
const url = `${this._endpoint}/message`;
|
|
469
|
-
const res = await fetch(url, {
|
|
470
|
-
method: "POST",
|
|
471
|
-
headers: {
|
|
472
|
-
"Content-Type": "application/json"
|
|
473
|
-
},
|
|
474
|
-
body: JSON.stringify({
|
|
475
|
-
messages: await import_effect.Schema.encodePromise(import_effect.Schema.Array(import_artifact.Message))(messages)
|
|
476
|
-
})
|
|
477
|
-
});
|
|
478
|
-
if (!res.ok) {
|
|
479
|
-
throw new Error(`${await res.text()} [${url}]`);
|
|
480
|
-
}
|
|
463
|
+
async exec(request) {
|
|
464
|
+
throw new Error("Not implemented");
|
|
481
465
|
}
|
|
482
466
|
/**
|
|
483
467
|
* Process request and open message stream.
|
|
484
468
|
*/
|
|
485
|
-
async
|
|
469
|
+
async execStream(request) {
|
|
486
470
|
(0, import_invariant.assertArgument)(typeof request.model === "string", "model is required");
|
|
487
471
|
(0, import_log2.log)("requesting", {
|
|
488
472
|
endpoint: this._endpoint
|
|
489
473
|
}, {
|
|
490
474
|
F: __dxlog_file2,
|
|
491
|
-
L:
|
|
475
|
+
L: 36,
|
|
492
476
|
S: this,
|
|
493
477
|
C: (f, a) => f(...a)
|
|
494
478
|
});
|
|
@@ -505,9 +489,12 @@ var AIServiceEdgeClient = class {
|
|
|
505
489
|
...request
|
|
506
490
|
})
|
|
507
491
|
});
|
|
492
|
+
if (!response.ok) {
|
|
493
|
+
throw await parseErrorResponse(response);
|
|
494
|
+
}
|
|
508
495
|
(0, import_invariant.invariant)(response.body instanceof ReadableStream, void 0, {
|
|
509
496
|
F: __dxlog_file2,
|
|
510
|
-
L:
|
|
497
|
+
L: 53,
|
|
511
498
|
S: this,
|
|
512
499
|
A: [
|
|
513
500
|
"response.body instanceof ReadableStream",
|
|
@@ -517,6 +504,9 @@ var AIServiceEdgeClient = class {
|
|
|
517
504
|
return createGenerationStream(response, controller);
|
|
518
505
|
}
|
|
519
506
|
};
|
|
507
|
+
var parseErrorResponse = async (response) => {
|
|
508
|
+
throw new Error(`AI Service error: ${response.status} ${response.statusText} ${await response.text()}`);
|
|
509
|
+
};
|
|
520
510
|
var MessageCollector = class {
|
|
521
511
|
constructor() {
|
|
522
512
|
this._messages = [];
|
|
@@ -582,36 +572,41 @@ function* emitMessageAsEvents(message) {
|
|
|
582
572
|
};
|
|
583
573
|
}
|
|
584
574
|
var createArtifactElement = (id) => `<artifact id=${id} />`;
|
|
585
|
-
var LLMModel =
|
|
575
|
+
var LLMModel = import_effect.Schema.Literal(...DEFAULT_EDGE_MODELS, ...DEFAULT_OLLAMA_MODELS);
|
|
586
576
|
var ToolTypes = Object.freeze({
|
|
587
577
|
// TODO(dmaretskyi): Not implemented yet.
|
|
588
578
|
// DatabaseQuery: 'database_query',
|
|
589
579
|
TextToImage: "text_to_image"
|
|
590
580
|
});
|
|
591
|
-
var GenerateRequest =
|
|
592
|
-
spaceId: import_effect2.Schema.optional(import_artifact2.SpaceIdSchema),
|
|
593
|
-
threadId: import_effect2.Schema.optional(import_echo_schema.ObjectId),
|
|
581
|
+
var GenerateRequest = import_effect.Schema.Struct({
|
|
594
582
|
/**
|
|
595
583
|
* Preferred model or system default.
|
|
596
584
|
*/
|
|
597
|
-
model:
|
|
585
|
+
model: import_effect.Schema.optional(LLMModel),
|
|
598
586
|
/**
|
|
599
587
|
* Tools available for the LLM.
|
|
600
588
|
*/
|
|
601
|
-
tools:
|
|
589
|
+
tools: import_effect.Schema.optional(import_effect.Schema.Array(import_artifact.Tool).pipe(import_effect.Schema.mutable)),
|
|
602
590
|
/**
|
|
603
591
|
* System instructions to the LLM.
|
|
604
592
|
*/
|
|
605
|
-
systemPrompt:
|
|
593
|
+
systemPrompt: import_effect.Schema.optional(import_effect.Schema.String),
|
|
606
594
|
/**
|
|
607
595
|
* History of messages to include in the context window.
|
|
608
596
|
*/
|
|
609
597
|
// TODO(burdon): Rename messages.
|
|
610
|
-
history:
|
|
598
|
+
history: import_effect.Schema.optional(import_effect.Schema.Array(import_artifact.Message)),
|
|
611
599
|
/**
|
|
612
600
|
* Current request.
|
|
613
601
|
*/
|
|
614
|
-
prompt:
|
|
602
|
+
prompt: import_effect.Schema.optional(import_artifact.Message)
|
|
603
|
+
});
|
|
604
|
+
var GenerateResponse = import_effect.Schema.Struct({
|
|
605
|
+
messages: import_effect.Schema.Array(import_artifact.Message),
|
|
606
|
+
/**
|
|
607
|
+
* Number of tokens used in the response.
|
|
608
|
+
*/
|
|
609
|
+
tokenCount: import_effect.Schema.optional(import_effect.Schema.Number)
|
|
615
610
|
});
|
|
616
611
|
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/experimental/assistant/src/conversation/conversation.ts";
|
|
617
612
|
var runLLM = async (params) => {
|
|
@@ -627,10 +622,8 @@ var runLLM = async (params) => {
|
|
|
627
622
|
C: (f, a) => f(...a)
|
|
628
623
|
});
|
|
629
624
|
const beginTs = Date.now();
|
|
630
|
-
const stream = await params.client.
|
|
625
|
+
const stream = await params.client.execStream({
|
|
631
626
|
model: params.model,
|
|
632
|
-
spaceId: params.spaceId,
|
|
633
|
-
threadId: params.threadId,
|
|
634
627
|
history,
|
|
635
628
|
systemPrompt: params.system,
|
|
636
629
|
tools: params.tools
|
|
@@ -643,7 +636,7 @@ var runLLM = async (params) => {
|
|
|
643
636
|
const message = messages.at(-1);
|
|
644
637
|
(0, import_invariant2.invariant)(message, void 0, {
|
|
645
638
|
F: __dxlog_file3,
|
|
646
|
-
L:
|
|
639
|
+
L: 61,
|
|
647
640
|
S: void 0,
|
|
648
641
|
A: [
|
|
649
642
|
"message",
|
|
@@ -655,13 +648,13 @@ var runLLM = async (params) => {
|
|
|
655
648
|
message
|
|
656
649
|
}, {
|
|
657
650
|
F: __dxlog_file3,
|
|
658
|
-
L:
|
|
651
|
+
L: 63,
|
|
659
652
|
S: void 0,
|
|
660
653
|
C: (f, a) => f(...a)
|
|
661
654
|
});
|
|
662
655
|
(0, import_invariant2.invariant)(message, void 0, {
|
|
663
656
|
F: __dxlog_file3,
|
|
664
|
-
L:
|
|
657
|
+
L: 64,
|
|
665
658
|
S: void 0,
|
|
666
659
|
A: [
|
|
667
660
|
"message",
|
|
@@ -681,7 +674,7 @@ var runLLM = async (params) => {
|
|
|
681
674
|
const toolCalls = message.content.filter((block) => block.type === "tool_use");
|
|
682
675
|
(0, import_invariant2.invariant)(toolCalls.length === 1, void 0, {
|
|
683
676
|
F: __dxlog_file3,
|
|
684
|
-
L:
|
|
677
|
+
L: 75,
|
|
685
678
|
S: void 0,
|
|
686
679
|
A: [
|
|
687
680
|
"toolCalls.length === 1",
|
|
@@ -695,7 +688,7 @@ var runLLM = async (params) => {
|
|
|
695
688
|
}
|
|
696
689
|
(0, import_invariant2.invariant)(tool.execute, void 0, {
|
|
697
690
|
F: __dxlog_file3,
|
|
698
|
-
L:
|
|
691
|
+
L: 82,
|
|
699
692
|
S: void 0,
|
|
700
693
|
A: [
|
|
701
694
|
"tool.execute",
|
|
@@ -709,14 +702,12 @@ var runLLM = async (params) => {
|
|
|
709
702
|
message: toolResult.message
|
|
710
703
|
}, {
|
|
711
704
|
F: __dxlog_file3,
|
|
712
|
-
L:
|
|
705
|
+
L: 86,
|
|
713
706
|
S: void 0,
|
|
714
707
|
C: (f, a) => f(...a)
|
|
715
708
|
});
|
|
716
709
|
const resultMessage = {
|
|
717
|
-
id:
|
|
718
|
-
spaceId: params.spaceId,
|
|
719
|
-
threadId: params.threadId,
|
|
710
|
+
id: import_echo_schema.ObjectId.random(),
|
|
720
711
|
role: "user",
|
|
721
712
|
content: [
|
|
722
713
|
{
|
|
@@ -739,14 +730,12 @@ var runLLM = async (params) => {
|
|
|
739
730
|
result: toolResult.result
|
|
740
731
|
}, {
|
|
741
732
|
F: __dxlog_file3,
|
|
742
|
-
L:
|
|
733
|
+
L: 106,
|
|
743
734
|
S: void 0,
|
|
744
735
|
C: (f, a) => f(...a)
|
|
745
736
|
});
|
|
746
737
|
const resultMessage = {
|
|
747
|
-
id:
|
|
748
|
-
spaceId: params.spaceId,
|
|
749
|
-
threadId: params.threadId,
|
|
738
|
+
id: import_echo_schema.ObjectId.random(),
|
|
750
739
|
role: "user",
|
|
751
740
|
content: [
|
|
752
741
|
{
|
|
@@ -768,7 +757,7 @@ var runLLM = async (params) => {
|
|
|
768
757
|
result: toolResult.result
|
|
769
758
|
}, {
|
|
770
759
|
F: __dxlog_file3,
|
|
771
|
-
L:
|
|
760
|
+
L: 125,
|
|
772
761
|
S: void 0,
|
|
773
762
|
C: (f, a) => f(...a)
|
|
774
763
|
});
|
|
@@ -790,7 +779,7 @@ var isToolUse = (message, { onlyToolNames } = {}) => {
|
|
|
790
779
|
const block = message.content.at(-1);
|
|
791
780
|
(0, import_invariant2.invariant)(block, void 0, {
|
|
792
781
|
F: __dxlog_file3,
|
|
793
|
-
L:
|
|
782
|
+
L: 146,
|
|
794
783
|
S: void 0,
|
|
795
784
|
A: [
|
|
796
785
|
"block",
|
|
@@ -803,7 +792,7 @@ var runTools = async ({ message, tools, extensions }) => {
|
|
|
803
792
|
const toolCalls = message.content.filter((block) => block.type === "tool_use");
|
|
804
793
|
(0, import_invariant2.invariant)(toolCalls.length === 1, void 0, {
|
|
805
794
|
F: __dxlog_file3,
|
|
806
|
-
L:
|
|
795
|
+
L: 168,
|
|
807
796
|
S: void 0,
|
|
808
797
|
A: [
|
|
809
798
|
"toolCalls.length === 1",
|
|
@@ -813,7 +802,7 @@ var runTools = async ({ message, tools, extensions }) => {
|
|
|
813
802
|
const toolCall = toolCalls[0];
|
|
814
803
|
const tool = tools.find((tool2) => tool2.name === toolCall.name);
|
|
815
804
|
if (!tool) {
|
|
816
|
-
const resultMessage = (0,
|
|
805
|
+
const resultMessage = (0, import_echo_schema.create)(import_artifact2.Message, {
|
|
817
806
|
role: "user",
|
|
818
807
|
content: [
|
|
819
808
|
{
|
|
@@ -833,7 +822,7 @@ var runTools = async ({ message, tools, extensions }) => {
|
|
|
833
822
|
try {
|
|
834
823
|
(0, import_invariant2.invariant)(tool.execute, void 0, {
|
|
835
824
|
F: __dxlog_file3,
|
|
836
|
-
L:
|
|
825
|
+
L: 193,
|
|
837
826
|
S: void 0,
|
|
838
827
|
A: [
|
|
839
828
|
"tool.execute",
|
|
@@ -848,11 +837,11 @@ var runTools = async ({ message, tools, extensions }) => {
|
|
|
848
837
|
error
|
|
849
838
|
}, {
|
|
850
839
|
F: __dxlog_file3,
|
|
851
|
-
L:
|
|
840
|
+
L: 196,
|
|
852
841
|
S: void 0,
|
|
853
842
|
C: (f, a) => f(...a)
|
|
854
843
|
});
|
|
855
|
-
toolResult =
|
|
844
|
+
toolResult = import_artifact2.ToolResult.Error(error.message);
|
|
856
845
|
}
|
|
857
846
|
switch (toolResult.kind) {
|
|
858
847
|
case "error": {
|
|
@@ -860,11 +849,11 @@ var runTools = async ({ message, tools, extensions }) => {
|
|
|
860
849
|
message: toolResult.message
|
|
861
850
|
}, {
|
|
862
851
|
F: __dxlog_file3,
|
|
863
|
-
L:
|
|
852
|
+
L: 202,
|
|
864
853
|
S: void 0,
|
|
865
854
|
C: (f, a) => f(...a)
|
|
866
855
|
});
|
|
867
|
-
const resultMessage = (0,
|
|
856
|
+
const resultMessage = (0, import_echo_schema.create)(import_artifact2.Message, {
|
|
868
857
|
role: "user",
|
|
869
858
|
content: [
|
|
870
859
|
{
|
|
@@ -885,11 +874,11 @@ var runTools = async ({ message, tools, extensions }) => {
|
|
|
885
874
|
result: toolResult.result
|
|
886
875
|
}, {
|
|
887
876
|
F: __dxlog_file3,
|
|
888
|
-
L:
|
|
877
|
+
L: 223,
|
|
889
878
|
S: void 0,
|
|
890
879
|
C: (f, a) => f(...a)
|
|
891
880
|
});
|
|
892
|
-
const resultMessage = (0,
|
|
881
|
+
const resultMessage = (0, import_echo_schema.create)(import_artifact2.Message, {
|
|
893
882
|
role: "user",
|
|
894
883
|
content: [
|
|
895
884
|
{
|
|
@@ -910,7 +899,7 @@ var runTools = async ({ message, tools, extensions }) => {
|
|
|
910
899
|
result: toolResult.result
|
|
911
900
|
}, {
|
|
912
901
|
F: __dxlog_file3,
|
|
913
|
-
L:
|
|
902
|
+
L: 244,
|
|
914
903
|
S: void 0,
|
|
915
904
|
C: (f, a) => f(...a)
|
|
916
905
|
});
|
|
@@ -1063,14 +1052,14 @@ var OllamaClient = class {
|
|
|
1063
1052
|
signal
|
|
1064
1053
|
});
|
|
1065
1054
|
if (!response.ok) {
|
|
1066
|
-
throw await
|
|
1055
|
+
throw await parseErrorResponse2(response);
|
|
1067
1056
|
}
|
|
1068
1057
|
if (!response.body) {
|
|
1069
1058
|
throw new Error("Ollama API returned no response body");
|
|
1070
1059
|
}
|
|
1071
1060
|
const reader = response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new OllamaDecoderStream()).getReader();
|
|
1072
1061
|
try {
|
|
1073
|
-
const messageId =
|
|
1062
|
+
const messageId = import_echo_schema2.ObjectId.random();
|
|
1074
1063
|
yield {
|
|
1075
1064
|
type: "message_start",
|
|
1076
1065
|
message: {
|
|
@@ -1130,7 +1119,7 @@ var OllamaClient = class {
|
|
|
1130
1119
|
index: currentBlockIndex,
|
|
1131
1120
|
content: {
|
|
1132
1121
|
type: "tool_use",
|
|
1133
|
-
id:
|
|
1122
|
+
id: import_echo_schema2.ObjectId.random(),
|
|
1134
1123
|
name: data.message.tool_calls[0].function.name,
|
|
1135
1124
|
input: sanitizeToolArguments(data.message.tool_calls[0].function.arguments)
|
|
1136
1125
|
}
|
|
@@ -1154,7 +1143,13 @@ var OllamaClient = class {
|
|
|
1154
1143
|
reader.releaseLock();
|
|
1155
1144
|
}
|
|
1156
1145
|
}
|
|
1146
|
+
/**
|
|
1147
|
+
* Generate non-streaming response.
|
|
1148
|
+
*/
|
|
1157
1149
|
async exec(request) {
|
|
1150
|
+
throw new Error("Not implemented");
|
|
1151
|
+
}
|
|
1152
|
+
async execStream(request) {
|
|
1158
1153
|
const controller = new AbortController();
|
|
1159
1154
|
try {
|
|
1160
1155
|
return new GenerationStreamImpl(controller, async function* () {
|
|
@@ -1213,19 +1208,19 @@ var sanitizeToolArguments = (args) => {
|
|
|
1213
1208
|
};
|
|
1214
1209
|
var SAMPLE_IMAGE_URL = "https://images.nightcafe.studio/jobs/BNmcRhHCM1JRKoUtqSei/BNmcRhHCM1JRKoUtqSei--1--5b9rv.jpg";
|
|
1215
1210
|
var WELL_KNOWN_TOOLS = {
|
|
1216
|
-
[ToolTypes.TextToImage]: (0,
|
|
1211
|
+
[ToolTypes.TextToImage]: (0, import_artifact3.defineTool)("system", {
|
|
1217
1212
|
name: "text-to-image",
|
|
1218
1213
|
description: "Generate an image from a text prompt",
|
|
1219
|
-
schema:
|
|
1220
|
-
prompt:
|
|
1214
|
+
schema: import_effect2.Schema.Struct({
|
|
1215
|
+
prompt: import_effect2.Schema.String.annotations({
|
|
1221
1216
|
description: "The text prompt describing the image to generate"
|
|
1222
1217
|
})
|
|
1223
1218
|
}),
|
|
1224
1219
|
execute: async ({ prompt }) => {
|
|
1225
1220
|
const image = await fetch(SAMPLE_IMAGE_URL).then(async (res) => Buffer.from(await res.arrayBuffer()));
|
|
1226
1221
|
const imageBase64 = image.toString("base64");
|
|
1227
|
-
const id =
|
|
1228
|
-
return
|
|
1222
|
+
const id = import_echo_schema2.ObjectId.random();
|
|
1223
|
+
return import_artifact3.ToolResult.Success(`The generation was successful. Image ID: ${id} Prompt: ${prompt}`, [
|
|
1229
1224
|
{
|
|
1230
1225
|
type: "image",
|
|
1231
1226
|
id,
|
|
@@ -1260,12 +1255,12 @@ var OllamaDecoderStream = class extends TransformStream {
|
|
|
1260
1255
|
this._buffer = "";
|
|
1261
1256
|
}
|
|
1262
1257
|
};
|
|
1263
|
-
var ModelDoesNotSupportToolsError = class extends
|
|
1264
|
-
model:
|
|
1258
|
+
var ModelDoesNotSupportToolsError = class extends import_effect2.Schema.TaggedError()("ModelDoesNotSupportToolsError", {
|
|
1259
|
+
model: import_effect2.Schema.String
|
|
1265
1260
|
}) {
|
|
1266
1261
|
};
|
|
1267
|
-
var ModelNotFoundError = class extends
|
|
1268
|
-
model:
|
|
1262
|
+
var ModelNotFoundError = class extends import_effect2.Schema.TaggedError()("ModelNotFoundError", {
|
|
1263
|
+
model: import_effect2.Schema.String
|
|
1269
1264
|
}) {
|
|
1270
1265
|
};
|
|
1271
1266
|
var parseOllamaError = (error) => {
|
|
@@ -1287,7 +1282,7 @@ var parseOllamaError = (error) => {
|
|
|
1287
1282
|
}
|
|
1288
1283
|
throw new Error(`Ollama API error: ${error}`);
|
|
1289
1284
|
};
|
|
1290
|
-
var
|
|
1285
|
+
var parseErrorResponse2 = async (response) => {
|
|
1291
1286
|
if (response.headers.get("content-type")?.includes("application/json")) {
|
|
1292
1287
|
const body = await response.json();
|
|
1293
1288
|
return parseOllamaError(body.error);
|
|
@@ -1446,7 +1441,7 @@ var MixedStreamParser = class {
|
|
|
1446
1441
|
C: (f, a) => f(...a)
|
|
1447
1442
|
});
|
|
1448
1443
|
}
|
|
1449
|
-
this._message = (0,
|
|
1444
|
+
this._message = (0, import_echo_schema3.create)(import_artifact4.Message, {
|
|
1450
1445
|
role: event.message.role,
|
|
1451
1446
|
content: [
|
|
1452
1447
|
...event.message.content
|
|
@@ -1727,6 +1722,18 @@ var mergeMessageBlock = (contentBlock, streamBlock) => {
|
|
|
1727
1722
|
}
|
|
1728
1723
|
break;
|
|
1729
1724
|
}
|
|
1725
|
+
case "proposal": {
|
|
1726
|
+
if (streamBlock.content.length === 1 && streamBlock.content[0].type === "text") {
|
|
1727
|
+
return {
|
|
1728
|
+
type: "json",
|
|
1729
|
+
disposition: "proposal",
|
|
1730
|
+
json: JSON.stringify({
|
|
1731
|
+
text: streamBlock.content[0].content
|
|
1732
|
+
})
|
|
1733
|
+
};
|
|
1734
|
+
}
|
|
1735
|
+
break;
|
|
1736
|
+
}
|
|
1730
1737
|
case "select": {
|
|
1731
1738
|
return {
|
|
1732
1739
|
type: "json",
|
|
@@ -2194,7 +2201,7 @@ var formatInferredRelationshipLabel = (typename, property2) => {
|
|
|
2194
2201
|
const nodeLabel = formatNodeLabel(typename);
|
|
2195
2202
|
return `${nodeLabel}_${property2}`.toUpperCase();
|
|
2196
2203
|
};
|
|
2197
|
-
var isReference = (schema) => schema.$id ===
|
|
2204
|
+
var isReference = (schema) => schema.$id === import_echo_schema4.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_schema4.JSON_SCHEMA_ECHO_REF_ID;
|
|
2198
2205
|
function _ts_decorate(decorators, target, key, desc) {
|
|
2199
2206
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2200
2207
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -2211,7 +2218,7 @@ var EchoDataSource = class {
|
|
|
2211
2218
|
const { objects: objects2 } = await this._db.query().run();
|
|
2212
2219
|
return objects2.map(this._objectToNode);
|
|
2213
2220
|
}
|
|
2214
|
-
const schema = (await this._getAllSchema()).find((s) => (0,
|
|
2221
|
+
const schema = (await this._getAllSchema()).find((s) => (0, import_echo_schema5.getSchemaTypename)(s)?.endsWith(label2));
|
|
2215
2222
|
if (!schema) {
|
|
2216
2223
|
return [];
|
|
2217
2224
|
}
|
|
@@ -2219,8 +2226,8 @@ var EchoDataSource = class {
|
|
|
2219
2226
|
return objects.map(this._objectToNode);
|
|
2220
2227
|
}
|
|
2221
2228
|
async getRelationships({ label: label2 }) {
|
|
2222
|
-
const syntheticRefRelationships = (await this._getAllSchema()).filter((schema) => (0,
|
|
2223
|
-
const jsonSchema = (0,
|
|
2229
|
+
const syntheticRefRelationships = (await this._getAllSchema()).filter((schema) => (0, import_echo_schema5.getSchemaTypename)(schema) !== import_echo_schema5.StoredSchema.typename).flatMap((schema) => {
|
|
2230
|
+
const jsonSchema = (0, import_echo_schema5.toJsonSchema)(schema);
|
|
2224
2231
|
const relationships = Object.entries(jsonSchema.properties).filter(([key, prop]) => isReference(prop));
|
|
2225
2232
|
return relationships.map(([key, value]) => {
|
|
2226
2233
|
const relationshipLabel = formatInferredRelationshipLabel(jsonSchema.typename ?? (0, import_debug2.raise)(new Error("Schema must have typename")), key);
|
|
@@ -2242,15 +2249,15 @@ var EchoDataSource = class {
|
|
|
2242
2249
|
return [
|
|
2243
2250
|
...await this._db.schemaRegistry.query().run(),
|
|
2244
2251
|
// TODO(dmaretskyi): Remove once we can serialize recursive schema.
|
|
2245
|
-
...this._db.graph.schemaRegistry.schemas.filter((s) => (0,
|
|
2246
|
-
].filter((schema) => (0,
|
|
2252
|
+
...this._db.graph.schemaRegistry.schemas.filter((s) => (0, import_echo_schema5.getSchemaTypename)(s)?.startsWith("example.org"))
|
|
2253
|
+
].filter((schema) => (0, import_echo_schema5.getSchemaTypename)(schema) !== import_echo_schema5.StoredSchema.typename);
|
|
2247
2254
|
}
|
|
2248
2255
|
_objectToNode(object) {
|
|
2249
2256
|
const { id, ...properties2 } = object;
|
|
2250
2257
|
return {
|
|
2251
2258
|
id,
|
|
2252
2259
|
kind: "node",
|
|
2253
|
-
label: formatNodeLabel((0,
|
|
2260
|
+
label: formatNodeLabel((0, import_echo_schema5.getSchemaTypename)((0, import_echo_schema5.getSchema)(object))),
|
|
2254
2261
|
properties: properties2
|
|
2255
2262
|
};
|
|
2256
2263
|
}
|
|
@@ -2266,7 +2273,7 @@ var EchoDataSource = class {
|
|
|
2266
2273
|
return {
|
|
2267
2274
|
id: `${object.id}-${prop}-${target.id}`,
|
|
2268
2275
|
kind: "relationship",
|
|
2269
|
-
label: formatInferredRelationshipLabel((0,
|
|
2276
|
+
label: formatInferredRelationshipLabel((0, import_echo_schema5.getSchemaTypename)((0, import_echo_schema5.getSchema)(object)), prop),
|
|
2270
2277
|
properties: {},
|
|
2271
2278
|
source: this._objectToNode(object),
|
|
2272
2279
|
target: this._objectToNode(target)
|
|
@@ -2277,7 +2284,7 @@ var EchoDataSource = class {
|
|
|
2277
2284
|
_ts_decorate([
|
|
2278
2285
|
import_log8.log.method(void 0, void 0, {
|
|
2279
2286
|
F: __dxlog_file8,
|
|
2280
|
-
L:
|
|
2287
|
+
L: 18,
|
|
2281
2288
|
S: void 0,
|
|
2282
2289
|
C: (f, a) => f(...a)
|
|
2283
2290
|
})
|
|
@@ -2285,7 +2292,7 @@ _ts_decorate([
|
|
|
2285
2292
|
_ts_decorate([
|
|
2286
2293
|
import_log8.log.method(void 0, void 0, {
|
|
2287
2294
|
F: __dxlog_file8,
|
|
2288
|
-
L:
|
|
2295
|
+
L: 35,
|
|
2289
2296
|
S: void 0,
|
|
2290
2297
|
C: (f, a) => f(...a)
|
|
2291
2298
|
})
|
|
@@ -2300,6 +2307,7 @@ _ts_decorate([
|
|
|
2300
2307
|
DEFAULT_OLLAMA_MODELS,
|
|
2301
2308
|
EchoDataSource,
|
|
2302
2309
|
GenerateRequest,
|
|
2310
|
+
GenerateResponse,
|
|
2303
2311
|
GenerationStreamImpl,
|
|
2304
2312
|
LLMModel,
|
|
2305
2313
|
MessageCollector,
|
|
@@ -2323,4 +2331,4 @@ _ts_decorate([
|
|
|
2323
2331
|
runTools,
|
|
2324
2332
|
trim
|
|
2325
2333
|
});
|
|
2326
|
-
//# sourceMappingURL=chunk-
|
|
2334
|
+
//# sourceMappingURL=chunk-CI5Q7FBG.cjs.map
|