@dxos/assistant 0.7.5-labs.ff2ff30 → 0.7.5-main.b19bfc8
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/index.mjs +81 -37
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs.map +2 -2
- package/dist/lib/node/index.cjs +84 -40
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs.map +2 -2
- package/dist/lib/node-esm/index.mjs +81 -37
- 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.map +2 -2
- package/dist/types/src/ai-service/client.d.ts.map +1 -1
- package/dist/types/src/ai-service/defs.d.ts +3 -0
- package/dist/types/src/ai-service/defs.d.ts.map +1 -0
- package/dist/types/src/ai-service/index.d.ts +1 -0
- package/dist/types/src/ai-service/index.d.ts.map +1 -1
- package/dist/types/src/ai-service/parser.d.ts +3 -3
- package/dist/types/src/ai-service/parser.d.ts.map +1 -1
- package/dist/types/src/ai-service/types.d.ts +9 -6
- package/dist/types/src/ai-service/types.d.ts.map +1 -1
- package/dist/types/src/testing/defs.d.ts.map +1 -1
- package/package.json +13 -13
- package/src/ai-service/client.test.ts +5 -4
- package/src/ai-service/client.ts +8 -0
- package/src/ai-service/defs.ts +24 -0
- package/src/ai-service/index.ts +1 -0
- package/src/ai-service/parser.ts +14 -1
- package/src/ai-service/types.ts +11 -15
- package/src/bin/chat.ts +4 -3
- package/src/conversation/conversation.test.ts +3 -3
- package/src/testing/artifacts.test.ts +2 -2
- package/src/testing/defs.ts +1 -0
- package/src/testing/object-extraction.test.ts +1 -1
- package/src/testing/query.test.ts +3 -3
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
import { Schema as S } from "@effect/schema";
|
|
14
14
|
import { Message } from "@dxos/artifact";
|
|
15
15
|
import { invariant } from "@dxos/invariant";
|
|
16
|
+
import { log as log2 } from "@dxos/log";
|
|
16
17
|
|
|
17
18
|
// packages/experimental/assistant/src/ai-service/stream.ts
|
|
18
19
|
import { Trigger } from "@dxos/async";
|
|
@@ -354,7 +355,7 @@ var AIServiceClientImpl = class {
|
|
|
354
355
|
constructor({ endpoint }) {
|
|
355
356
|
invariant(endpoint, "endpoint is required", {
|
|
356
357
|
F: __dxlog_file2,
|
|
357
|
-
L:
|
|
358
|
+
L: 37,
|
|
358
359
|
S: this,
|
|
359
360
|
A: [
|
|
360
361
|
"endpoint",
|
|
@@ -396,6 +397,18 @@ var AIServiceClientImpl = class {
|
|
|
396
397
|
* Open message stream.
|
|
397
398
|
*/
|
|
398
399
|
async generate(request) {
|
|
400
|
+
request = {
|
|
401
|
+
tools: request.tools ?? [],
|
|
402
|
+
...request
|
|
403
|
+
};
|
|
404
|
+
log2.info("requesting", {
|
|
405
|
+
endpoint: this._endpoint
|
|
406
|
+
}, {
|
|
407
|
+
F: __dxlog_file2,
|
|
408
|
+
L: 84,
|
|
409
|
+
S: this,
|
|
410
|
+
C: (f, a) => f(...a)
|
|
411
|
+
});
|
|
399
412
|
const controller = new AbortController();
|
|
400
413
|
const response = await fetch(`${this._endpoint}/generate`, {
|
|
401
414
|
signal: controller.signal,
|
|
@@ -407,7 +420,7 @@ var AIServiceClientImpl = class {
|
|
|
407
420
|
});
|
|
408
421
|
invariant(response.body instanceof ReadableStream, void 0, {
|
|
409
422
|
F: __dxlog_file2,
|
|
410
|
-
L:
|
|
423
|
+
L: 93,
|
|
411
424
|
S: this,
|
|
412
425
|
A: [
|
|
413
426
|
"response.body instanceof ReadableStream",
|
|
@@ -418,12 +431,29 @@ var AIServiceClientImpl = class {
|
|
|
418
431
|
}
|
|
419
432
|
};
|
|
420
433
|
|
|
434
|
+
// packages/experimental/assistant/src/ai-service/defs.ts
|
|
435
|
+
var DEFAULT_LLM_MODEL = "@anthropic/claude-3-5-sonnet-20241022";
|
|
436
|
+
var DEFAULT_LLM_MODELS = [
|
|
437
|
+
// AI Gateway.
|
|
438
|
+
// https://developers.cloudflare.com/ai-gateway
|
|
439
|
+
"@anthropic/claude-3-5-haiku-20241022",
|
|
440
|
+
"@anthropic/claude-3-5-sonnet-20241022",
|
|
441
|
+
"@anthropic/claude-3-7-sonnet-20250219",
|
|
442
|
+
// Workers AI.
|
|
443
|
+
// https://developers.cloudflare.com/workers-ai/models
|
|
444
|
+
"@cf/deepseek-ai/deepseek-r1-distill-qwen-32b",
|
|
445
|
+
"@hf/nousresearch/hermes-2-pro-mistral-7b",
|
|
446
|
+
"@ollama/llama-3-1-nemotron-70b-instruct",
|
|
447
|
+
"@ollama/llama-3-1-nemotron-mini-4b-instruct",
|
|
448
|
+
"@ollama/llama-3-2-3b"
|
|
449
|
+
];
|
|
450
|
+
|
|
421
451
|
// packages/experimental/assistant/src/ai-service/parser.ts
|
|
422
452
|
import { Message as Message2 } from "@dxos/artifact";
|
|
423
453
|
import { Event } from "@dxos/async";
|
|
424
454
|
import { createStatic } from "@dxos/echo-schema";
|
|
425
455
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
426
|
-
import { log as
|
|
456
|
+
import { log as log3 } from "@dxos/log";
|
|
427
457
|
import { isNotFalsy, safeParseJson } from "@dxos/util";
|
|
428
458
|
|
|
429
459
|
// packages/experimental/assistant/src/ai-service/transform.ts
|
|
@@ -566,6 +596,7 @@ var MixedStreamParser = class {
|
|
|
566
596
|
let contentBlock;
|
|
567
597
|
let streamBlock;
|
|
568
598
|
const stack = [];
|
|
599
|
+
const messagesCollected = [];
|
|
569
600
|
for await (const event of stream) {
|
|
570
601
|
switch (event.type) {
|
|
571
602
|
//
|
|
@@ -573,9 +604,9 @@ var MixedStreamParser = class {
|
|
|
573
604
|
//
|
|
574
605
|
case "message_start": {
|
|
575
606
|
if (this._message) {
|
|
576
|
-
|
|
607
|
+
log3.warn("unexpected message_start", void 0, {
|
|
577
608
|
F: __dxlog_file3,
|
|
578
|
-
L:
|
|
609
|
+
L: 88,
|
|
579
610
|
S: this,
|
|
580
611
|
C: (f, a) => f(...a)
|
|
581
612
|
});
|
|
@@ -589,9 +620,9 @@ var MixedStreamParser = class {
|
|
|
589
620
|
}
|
|
590
621
|
case "message_delta": {
|
|
591
622
|
if (!this._message) {
|
|
592
|
-
|
|
623
|
+
log3.warn("unexpected message_delta", void 0, {
|
|
593
624
|
F: __dxlog_file3,
|
|
594
|
-
L:
|
|
625
|
+
L: 98,
|
|
595
626
|
S: this,
|
|
596
627
|
C: (f, a) => f(...a)
|
|
597
628
|
});
|
|
@@ -600,13 +631,14 @@ var MixedStreamParser = class {
|
|
|
600
631
|
}
|
|
601
632
|
case "message_stop": {
|
|
602
633
|
if (!this._message) {
|
|
603
|
-
|
|
634
|
+
log3.warn("unexpected message_stop", void 0, {
|
|
604
635
|
F: __dxlog_file3,
|
|
605
|
-
L:
|
|
636
|
+
L: 106,
|
|
606
637
|
S: this,
|
|
607
638
|
C: (f, a) => f(...a)
|
|
608
639
|
});
|
|
609
640
|
} else {
|
|
641
|
+
messagesCollected.push(this._message);
|
|
610
642
|
this._message = void 0;
|
|
611
643
|
}
|
|
612
644
|
break;
|
|
@@ -616,11 +648,11 @@ var MixedStreamParser = class {
|
|
|
616
648
|
//
|
|
617
649
|
case "content_block_start": {
|
|
618
650
|
if (contentBlock) {
|
|
619
|
-
|
|
651
|
+
log3.warn("unexpected content_block_start", {
|
|
620
652
|
content: contentBlock
|
|
621
653
|
}, {
|
|
622
654
|
F: __dxlog_file3,
|
|
623
|
-
L:
|
|
655
|
+
L: 120,
|
|
624
656
|
S: this,
|
|
625
657
|
C: (f, a) => f(...a)
|
|
626
658
|
});
|
|
@@ -630,9 +662,9 @@ var MixedStreamParser = class {
|
|
|
630
662
|
}
|
|
631
663
|
case "content_block_delta": {
|
|
632
664
|
if (!contentBlock) {
|
|
633
|
-
|
|
665
|
+
log3.warn("unexpected content_block_delta", void 0, {
|
|
634
666
|
F: __dxlog_file3,
|
|
635
|
-
L:
|
|
667
|
+
L: 130,
|
|
636
668
|
S: this,
|
|
637
669
|
C: (f, a) => f(...a)
|
|
638
670
|
});
|
|
@@ -658,7 +690,7 @@ var MixedStreamParser = class {
|
|
|
658
690
|
const top = stack.pop();
|
|
659
691
|
invariant2(top && top.type === "tag", void 0, {
|
|
660
692
|
F: __dxlog_file3,
|
|
661
|
-
L:
|
|
693
|
+
L: 154,
|
|
662
694
|
S: this,
|
|
663
695
|
A: [
|
|
664
696
|
"top && top.type === 'tag'",
|
|
@@ -682,7 +714,7 @@ var MixedStreamParser = class {
|
|
|
682
714
|
const last = streamBlock.content.at(-1);
|
|
683
715
|
invariant2(last, void 0, {
|
|
684
716
|
F: __dxlog_file3,
|
|
685
|
-
L:
|
|
717
|
+
L: 171,
|
|
686
718
|
S: this,
|
|
687
719
|
A: [
|
|
688
720
|
"last",
|
|
@@ -734,11 +766,11 @@ var MixedStreamParser = class {
|
|
|
734
766
|
//
|
|
735
767
|
case "input_json_delta": {
|
|
736
768
|
if (!contentBlock) {
|
|
737
|
-
|
|
769
|
+
log3.warn("unexpected input_json_delta", {
|
|
738
770
|
contentBlock
|
|
739
771
|
}, {
|
|
740
772
|
F: __dxlog_file3,
|
|
741
|
-
L:
|
|
773
|
+
L: 221,
|
|
742
774
|
S: this,
|
|
743
775
|
C: (f, a) => f(...a)
|
|
744
776
|
});
|
|
@@ -759,9 +791,9 @@ var MixedStreamParser = class {
|
|
|
759
791
|
}
|
|
760
792
|
case "content_block_stop": {
|
|
761
793
|
if (!contentBlock) {
|
|
762
|
-
|
|
794
|
+
log3.warn("unexpected content_block_stop", void 0, {
|
|
763
795
|
F: __dxlog_file3,
|
|
764
|
-
L:
|
|
796
|
+
L: 238,
|
|
765
797
|
S: this,
|
|
766
798
|
C: (f, a) => f(...a)
|
|
767
799
|
});
|
|
@@ -777,15 +809,16 @@ var MixedStreamParser = class {
|
|
|
777
809
|
this._emitUpdate(contentBlock, streamBlock);
|
|
778
810
|
}
|
|
779
811
|
}
|
|
812
|
+
return messagesCollected;
|
|
780
813
|
}
|
|
781
814
|
};
|
|
782
815
|
var mergeMessageBlock = (contentBlock, streamBlock) => {
|
|
783
|
-
|
|
816
|
+
log3("mergeMessageBlock", {
|
|
784
817
|
contentBlock,
|
|
785
818
|
streamBlock
|
|
786
819
|
}, {
|
|
787
820
|
F: __dxlog_file3,
|
|
788
|
-
L:
|
|
821
|
+
L: 265,
|
|
789
822
|
S: void 0,
|
|
790
823
|
C: (f, a) => f(...a)
|
|
791
824
|
});
|
|
@@ -852,6 +885,13 @@ var mergeMessageBlock = (contentBlock, streamBlock) => {
|
|
|
852
885
|
})
|
|
853
886
|
};
|
|
854
887
|
}
|
|
888
|
+
case "tool-list": {
|
|
889
|
+
return {
|
|
890
|
+
type: "json",
|
|
891
|
+
disposition: "tool_list",
|
|
892
|
+
json: JSON.stringify({})
|
|
893
|
+
};
|
|
894
|
+
}
|
|
855
895
|
}
|
|
856
896
|
break;
|
|
857
897
|
}
|
|
@@ -882,7 +922,7 @@ import { Schema as S2 } from "@effect/schema";
|
|
|
882
922
|
import { Tool, Message as Message3, SpaceIdSchema } from "@dxos/artifact";
|
|
883
923
|
import { ObjectId } from "@dxos/echo-schema";
|
|
884
924
|
var createArtifactElement = (id) => `<artifact id=${id} />`;
|
|
885
|
-
var LLMModel = S2.Literal(
|
|
925
|
+
var LLMModel = S2.Literal(...DEFAULT_LLM_MODELS);
|
|
886
926
|
var ToolTypes = Object.freeze({
|
|
887
927
|
// TODO(dmaretskyi): Not implemented yet.
|
|
888
928
|
// DatabaseQuery: 'database_query',
|
|
@@ -891,18 +931,20 @@ var ToolTypes = Object.freeze({
|
|
|
891
931
|
var GenerateRequest = S2.Struct({
|
|
892
932
|
spaceId: S2.optional(SpaceIdSchema),
|
|
893
933
|
threadId: S2.optional(ObjectId),
|
|
894
|
-
// TODO(burdon): Make optional with default.
|
|
895
|
-
model: LLMModel,
|
|
896
934
|
/**
|
|
897
|
-
*
|
|
935
|
+
* Preferred model or system default.
|
|
898
936
|
*/
|
|
899
|
-
|
|
900
|
-
// prompt: Message,
|
|
937
|
+
model: S2.optional(LLMModel),
|
|
901
938
|
/**
|
|
902
939
|
* System instructions to the LLM.
|
|
903
940
|
*/
|
|
904
941
|
systemPrompt: S2.optional(S2.String),
|
|
905
942
|
/**
|
|
943
|
+
* Current request.
|
|
944
|
+
*/
|
|
945
|
+
// TODO(burdon): Remove from history.
|
|
946
|
+
// prompt: Message,
|
|
947
|
+
/**
|
|
906
948
|
* History of messages to include in the context window.
|
|
907
949
|
*/
|
|
908
950
|
history: S2.optional(S2.Array(Message3)),
|
|
@@ -916,13 +958,13 @@ var GenerateRequest = S2.Struct({
|
|
|
916
958
|
import { ToolResult, Message as Message4 } from "@dxos/artifact";
|
|
917
959
|
import { createStatic as createStatic2, ObjectId as ObjectId2 } from "@dxos/echo-schema";
|
|
918
960
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
919
|
-
import { log as
|
|
961
|
+
import { log as log4 } from "@dxos/log";
|
|
920
962
|
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/experimental/assistant/src/conversation/conversation.ts";
|
|
921
963
|
var runLLM = async (params) => {
|
|
922
964
|
let conversationResult = null;
|
|
923
965
|
const history = params.history ?? [];
|
|
924
966
|
const generate = async () => {
|
|
925
|
-
|
|
967
|
+
log4("llm generate", {
|
|
926
968
|
tools: params.tools
|
|
927
969
|
}, {
|
|
928
970
|
F: __dxlog_file4,
|
|
@@ -954,7 +996,7 @@ var runLLM = async (params) => {
|
|
|
954
996
|
""
|
|
955
997
|
]
|
|
956
998
|
});
|
|
957
|
-
|
|
999
|
+
log4("llm result", {
|
|
958
1000
|
time: Date.now() - beginTs,
|
|
959
1001
|
message
|
|
960
1002
|
}, {
|
|
@@ -1009,7 +1051,7 @@ var runLLM = async (params) => {
|
|
|
1009
1051
|
const toolResult = await tool.execute(toolCall.input);
|
|
1010
1052
|
switch (toolResult.kind) {
|
|
1011
1053
|
case "error": {
|
|
1012
|
-
|
|
1054
|
+
log4.warn("tool error", {
|
|
1013
1055
|
message: toolResult.message
|
|
1014
1056
|
}, {
|
|
1015
1057
|
F: __dxlog_file4,
|
|
@@ -1039,7 +1081,7 @@ var runLLM = async (params) => {
|
|
|
1039
1081
|
return true;
|
|
1040
1082
|
}
|
|
1041
1083
|
case "success": {
|
|
1042
|
-
|
|
1084
|
+
log4("tool success", {
|
|
1043
1085
|
result: toolResult.result
|
|
1044
1086
|
}, {
|
|
1045
1087
|
F: __dxlog_file4,
|
|
@@ -1068,7 +1110,7 @@ var runLLM = async (params) => {
|
|
|
1068
1110
|
return true;
|
|
1069
1111
|
}
|
|
1070
1112
|
case "break": {
|
|
1071
|
-
|
|
1113
|
+
log4("tool break", {
|
|
1072
1114
|
result: toolResult.result
|
|
1073
1115
|
}, {
|
|
1074
1116
|
F: __dxlog_file4,
|
|
@@ -1134,7 +1176,7 @@ var runTools = async ({ message, tools, extensions }) => {
|
|
|
1134
1176
|
extensions
|
|
1135
1177
|
});
|
|
1136
1178
|
} catch (error) {
|
|
1137
|
-
|
|
1179
|
+
log4("tool error", {
|
|
1138
1180
|
error
|
|
1139
1181
|
}, {
|
|
1140
1182
|
F: __dxlog_file4,
|
|
@@ -1146,7 +1188,7 @@ var runTools = async ({ message, tools, extensions }) => {
|
|
|
1146
1188
|
}
|
|
1147
1189
|
switch (toolResult.kind) {
|
|
1148
1190
|
case "error": {
|
|
1149
|
-
|
|
1191
|
+
log4("tool error", {
|
|
1150
1192
|
message: toolResult.message
|
|
1151
1193
|
}, {
|
|
1152
1194
|
F: __dxlog_file4,
|
|
@@ -1171,7 +1213,7 @@ var runTools = async ({ message, tools, extensions }) => {
|
|
|
1171
1213
|
};
|
|
1172
1214
|
}
|
|
1173
1215
|
case "success": {
|
|
1174
|
-
|
|
1216
|
+
log4("tool success", {
|
|
1175
1217
|
result: toolResult.result
|
|
1176
1218
|
}, {
|
|
1177
1219
|
F: __dxlog_file4,
|
|
@@ -1195,7 +1237,7 @@ var runTools = async ({ message, tools, extensions }) => {
|
|
|
1195
1237
|
};
|
|
1196
1238
|
}
|
|
1197
1239
|
case "break": {
|
|
1198
|
-
|
|
1240
|
+
log4("tool break", {
|
|
1199
1241
|
result: toolResult.result
|
|
1200
1242
|
}, {
|
|
1201
1243
|
F: __dxlog_file4,
|
|
@@ -1212,6 +1254,8 @@ var runTools = async ({ message, tools, extensions }) => {
|
|
|
1212
1254
|
};
|
|
1213
1255
|
export {
|
|
1214
1256
|
AIServiceClientImpl,
|
|
1257
|
+
DEFAULT_LLM_MODEL,
|
|
1258
|
+
DEFAULT_LLM_MODELS,
|
|
1215
1259
|
EchoDataSource,
|
|
1216
1260
|
GenerateRequest,
|
|
1217
1261
|
GenerationStream,
|