@dxos/assistant 0.7.5-labs.ff2ff30 → 0.7.5-main.5ae2ba8
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 +86 -56
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +20 -20
- package/dist/lib/browser/testing/index.mjs.map +2 -2
- package/dist/lib/node/index.cjs +89 -59
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +20 -20
- package/dist/lib/node/testing/index.cjs.map +2 -2
- package/dist/lib/node-esm/index.mjs +86 -56
- 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 +20 -20
- package/dist/lib/node-esm/testing/index.mjs.map +2 -2
- package/dist/types/src/ai-service/client.d.ts +7 -14
- 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/stream.d.ts.map +1 -1
- package/dist/types/src/ai-service/testing/index.d.ts +3 -0
- package/dist/types/src/ai-service/testing/index.d.ts.map +1 -0
- package/dist/types/src/ai-service/testing/mock.d.ts +7 -0
- package/dist/types/src/ai-service/testing/mock.d.ts.map +1 -0
- package/dist/types/src/ai-service/{testing.d.ts → testing/test-stream.d.ts} +1 -1
- package/dist/types/src/ai-service/testing/test-stream.d.ts.map +1 -0
- package/dist/types/src/ai-service/types.d.ts +97 -14
- package/dist/types/src/ai-service/types.d.ts.map +1 -1
- package/dist/types/src/conversation/conversation.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 +9 -8
- package/src/ai-service/client.ts +16 -29
- 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/stream.ts +1 -1
- package/src/ai-service/testing/index.ts +6 -0
- package/src/ai-service/testing/mock.ts +17 -0
- package/src/ai-service/{testing.ts → testing/test-stream.ts} +1 -1
- package/src/ai-service/types.ts +12 -16
- package/src/bin/chat.ts +4 -3
- package/src/conversation/conversation.test.ts +4 -4
- package/src/conversation/conversation.ts +1 -1
- package/src/testing/artifacts.test.ts +9 -9
- package/src/testing/defs.ts +1 -0
- package/src/testing/object-extraction.test.ts +1 -1
- package/src/testing/query-promts.ts +20 -20
- package/src/testing/query.test.ts +3 -3
- package/dist/types/src/ai-service/testing.d.ts.map +0 -1
|
@@ -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: 34,
|
|
358
359
|
S: this,
|
|
359
360
|
A: [
|
|
360
361
|
"endpoint",
|
|
@@ -363,16 +364,6 @@ var AIServiceClientImpl = class {
|
|
|
363
364
|
});
|
|
364
365
|
this._endpoint = endpoint;
|
|
365
366
|
}
|
|
366
|
-
async getSpace(spaceId) {
|
|
367
|
-
throw new Error("Not implemented");
|
|
368
|
-
}
|
|
369
|
-
async getThread(spaceId, threadId) {
|
|
370
|
-
throw new Error("Not implemented");
|
|
371
|
-
}
|
|
372
|
-
async getMessages(spaceId, threadId) {
|
|
373
|
-
const res = await fetch(`${this._endpoint}/space/${spaceId}/thread/${threadId}/message`);
|
|
374
|
-
return S.decodePromise(S.Array(Message).pipe(S.mutable))((await res.json()).data.results);
|
|
375
|
-
}
|
|
376
367
|
async appendMessages(messages) {
|
|
377
368
|
const url = `${this._endpoint}/message`;
|
|
378
369
|
const res = await fetch(url, {
|
|
@@ -388,14 +379,22 @@ var AIServiceClientImpl = class {
|
|
|
388
379
|
throw new Error(`${await res.text()} [${url}]`);
|
|
389
380
|
}
|
|
390
381
|
}
|
|
391
|
-
// TODO(dmaretskyi): Accept partial message schema.
|
|
392
|
-
async updateMessage(spaceId, threadId, messageId, message) {
|
|
393
|
-
throw new Error("Not implemented");
|
|
394
|
-
}
|
|
395
382
|
/**
|
|
396
|
-
*
|
|
383
|
+
* Process request and open message stream.
|
|
397
384
|
*/
|
|
398
|
-
async
|
|
385
|
+
async exec(request) {
|
|
386
|
+
request = {
|
|
387
|
+
tools: request.tools ?? [],
|
|
388
|
+
...request
|
|
389
|
+
};
|
|
390
|
+
log2.info("requesting", {
|
|
391
|
+
endpoint: this._endpoint
|
|
392
|
+
}, {
|
|
393
|
+
F: __dxlog_file2,
|
|
394
|
+
L: 63,
|
|
395
|
+
S: this,
|
|
396
|
+
C: (f, a) => f(...a)
|
|
397
|
+
});
|
|
399
398
|
const controller = new AbortController();
|
|
400
399
|
const response = await fetch(`${this._endpoint}/generate`, {
|
|
401
400
|
signal: controller.signal,
|
|
@@ -407,7 +406,7 @@ var AIServiceClientImpl = class {
|
|
|
407
406
|
});
|
|
408
407
|
invariant(response.body instanceof ReadableStream, void 0, {
|
|
409
408
|
F: __dxlog_file2,
|
|
410
|
-
L:
|
|
409
|
+
L: 72,
|
|
411
410
|
S: this,
|
|
412
411
|
A: [
|
|
413
412
|
"response.body instanceof ReadableStream",
|
|
@@ -418,12 +417,29 @@ var AIServiceClientImpl = class {
|
|
|
418
417
|
}
|
|
419
418
|
};
|
|
420
419
|
|
|
420
|
+
// packages/experimental/assistant/src/ai-service/defs.ts
|
|
421
|
+
var DEFAULT_LLM_MODEL = "@anthropic/claude-3-5-sonnet-20241022";
|
|
422
|
+
var DEFAULT_LLM_MODELS = [
|
|
423
|
+
// AI Gateway.
|
|
424
|
+
// https://developers.cloudflare.com/ai-gateway
|
|
425
|
+
"@anthropic/claude-3-5-haiku-20241022",
|
|
426
|
+
"@anthropic/claude-3-5-sonnet-20241022",
|
|
427
|
+
"@anthropic/claude-3-7-sonnet-20250219",
|
|
428
|
+
// Workers AI.
|
|
429
|
+
// https://developers.cloudflare.com/workers-ai/models
|
|
430
|
+
"@cf/deepseek-ai/deepseek-r1-distill-qwen-32b",
|
|
431
|
+
"@hf/nousresearch/hermes-2-pro-mistral-7b",
|
|
432
|
+
"@ollama/llama-3-1-nemotron-70b-instruct",
|
|
433
|
+
"@ollama/llama-3-1-nemotron-mini-4b-instruct",
|
|
434
|
+
"@ollama/llama-3-2-3b"
|
|
435
|
+
];
|
|
436
|
+
|
|
421
437
|
// packages/experimental/assistant/src/ai-service/parser.ts
|
|
422
438
|
import { Message as Message2 } from "@dxos/artifact";
|
|
423
439
|
import { Event } from "@dxos/async";
|
|
424
440
|
import { createStatic } from "@dxos/echo-schema";
|
|
425
441
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
426
|
-
import { log as
|
|
442
|
+
import { log as log3 } from "@dxos/log";
|
|
427
443
|
import { isNotFalsy, safeParseJson } from "@dxos/util";
|
|
428
444
|
|
|
429
445
|
// packages/experimental/assistant/src/ai-service/transform.ts
|
|
@@ -566,6 +582,7 @@ var MixedStreamParser = class {
|
|
|
566
582
|
let contentBlock;
|
|
567
583
|
let streamBlock;
|
|
568
584
|
const stack = [];
|
|
585
|
+
const messagesCollected = [];
|
|
569
586
|
for await (const event of stream) {
|
|
570
587
|
switch (event.type) {
|
|
571
588
|
//
|
|
@@ -573,9 +590,9 @@ var MixedStreamParser = class {
|
|
|
573
590
|
//
|
|
574
591
|
case "message_start": {
|
|
575
592
|
if (this._message) {
|
|
576
|
-
|
|
593
|
+
log3.warn("unexpected message_start", void 0, {
|
|
577
594
|
F: __dxlog_file3,
|
|
578
|
-
L:
|
|
595
|
+
L: 88,
|
|
579
596
|
S: this,
|
|
580
597
|
C: (f, a) => f(...a)
|
|
581
598
|
});
|
|
@@ -589,9 +606,9 @@ var MixedStreamParser = class {
|
|
|
589
606
|
}
|
|
590
607
|
case "message_delta": {
|
|
591
608
|
if (!this._message) {
|
|
592
|
-
|
|
609
|
+
log3.warn("unexpected message_delta", void 0, {
|
|
593
610
|
F: __dxlog_file3,
|
|
594
|
-
L:
|
|
611
|
+
L: 98,
|
|
595
612
|
S: this,
|
|
596
613
|
C: (f, a) => f(...a)
|
|
597
614
|
});
|
|
@@ -600,13 +617,14 @@ var MixedStreamParser = class {
|
|
|
600
617
|
}
|
|
601
618
|
case "message_stop": {
|
|
602
619
|
if (!this._message) {
|
|
603
|
-
|
|
620
|
+
log3.warn("unexpected message_stop", void 0, {
|
|
604
621
|
F: __dxlog_file3,
|
|
605
|
-
L:
|
|
622
|
+
L: 106,
|
|
606
623
|
S: this,
|
|
607
624
|
C: (f, a) => f(...a)
|
|
608
625
|
});
|
|
609
626
|
} else {
|
|
627
|
+
messagesCollected.push(this._message);
|
|
610
628
|
this._message = void 0;
|
|
611
629
|
}
|
|
612
630
|
break;
|
|
@@ -616,11 +634,11 @@ var MixedStreamParser = class {
|
|
|
616
634
|
//
|
|
617
635
|
case "content_block_start": {
|
|
618
636
|
if (contentBlock) {
|
|
619
|
-
|
|
637
|
+
log3.warn("unexpected content_block_start", {
|
|
620
638
|
content: contentBlock
|
|
621
639
|
}, {
|
|
622
640
|
F: __dxlog_file3,
|
|
623
|
-
L:
|
|
641
|
+
L: 120,
|
|
624
642
|
S: this,
|
|
625
643
|
C: (f, a) => f(...a)
|
|
626
644
|
});
|
|
@@ -630,9 +648,9 @@ var MixedStreamParser = class {
|
|
|
630
648
|
}
|
|
631
649
|
case "content_block_delta": {
|
|
632
650
|
if (!contentBlock) {
|
|
633
|
-
|
|
651
|
+
log3.warn("unexpected content_block_delta", void 0, {
|
|
634
652
|
F: __dxlog_file3,
|
|
635
|
-
L:
|
|
653
|
+
L: 130,
|
|
636
654
|
S: this,
|
|
637
655
|
C: (f, a) => f(...a)
|
|
638
656
|
});
|
|
@@ -658,7 +676,7 @@ var MixedStreamParser = class {
|
|
|
658
676
|
const top = stack.pop();
|
|
659
677
|
invariant2(top && top.type === "tag", void 0, {
|
|
660
678
|
F: __dxlog_file3,
|
|
661
|
-
L:
|
|
679
|
+
L: 154,
|
|
662
680
|
S: this,
|
|
663
681
|
A: [
|
|
664
682
|
"top && top.type === 'tag'",
|
|
@@ -682,7 +700,7 @@ var MixedStreamParser = class {
|
|
|
682
700
|
const last = streamBlock.content.at(-1);
|
|
683
701
|
invariant2(last, void 0, {
|
|
684
702
|
F: __dxlog_file3,
|
|
685
|
-
L:
|
|
703
|
+
L: 171,
|
|
686
704
|
S: this,
|
|
687
705
|
A: [
|
|
688
706
|
"last",
|
|
@@ -734,11 +752,11 @@ var MixedStreamParser = class {
|
|
|
734
752
|
//
|
|
735
753
|
case "input_json_delta": {
|
|
736
754
|
if (!contentBlock) {
|
|
737
|
-
|
|
755
|
+
log3.warn("unexpected input_json_delta", {
|
|
738
756
|
contentBlock
|
|
739
757
|
}, {
|
|
740
758
|
F: __dxlog_file3,
|
|
741
|
-
L:
|
|
759
|
+
L: 221,
|
|
742
760
|
S: this,
|
|
743
761
|
C: (f, a) => f(...a)
|
|
744
762
|
});
|
|
@@ -759,9 +777,9 @@ var MixedStreamParser = class {
|
|
|
759
777
|
}
|
|
760
778
|
case "content_block_stop": {
|
|
761
779
|
if (!contentBlock) {
|
|
762
|
-
|
|
780
|
+
log3.warn("unexpected content_block_stop", void 0, {
|
|
763
781
|
F: __dxlog_file3,
|
|
764
|
-
L:
|
|
782
|
+
L: 238,
|
|
765
783
|
S: this,
|
|
766
784
|
C: (f, a) => f(...a)
|
|
767
785
|
});
|
|
@@ -777,15 +795,16 @@ var MixedStreamParser = class {
|
|
|
777
795
|
this._emitUpdate(contentBlock, streamBlock);
|
|
778
796
|
}
|
|
779
797
|
}
|
|
798
|
+
return messagesCollected;
|
|
780
799
|
}
|
|
781
800
|
};
|
|
782
801
|
var mergeMessageBlock = (contentBlock, streamBlock) => {
|
|
783
|
-
|
|
802
|
+
log3("mergeMessageBlock", {
|
|
784
803
|
contentBlock,
|
|
785
804
|
streamBlock
|
|
786
805
|
}, {
|
|
787
806
|
F: __dxlog_file3,
|
|
788
|
-
L:
|
|
807
|
+
L: 265,
|
|
789
808
|
S: void 0,
|
|
790
809
|
C: (f, a) => f(...a)
|
|
791
810
|
});
|
|
@@ -852,6 +871,13 @@ var mergeMessageBlock = (contentBlock, streamBlock) => {
|
|
|
852
871
|
})
|
|
853
872
|
};
|
|
854
873
|
}
|
|
874
|
+
case "tool-list": {
|
|
875
|
+
return {
|
|
876
|
+
type: "json",
|
|
877
|
+
disposition: "tool_list",
|
|
878
|
+
json: JSON.stringify({})
|
|
879
|
+
};
|
|
880
|
+
}
|
|
855
881
|
}
|
|
856
882
|
break;
|
|
857
883
|
}
|
|
@@ -882,7 +908,7 @@ import { Schema as S2 } from "@effect/schema";
|
|
|
882
908
|
import { Tool, Message as Message3, SpaceIdSchema } from "@dxos/artifact";
|
|
883
909
|
import { ObjectId } from "@dxos/echo-schema";
|
|
884
910
|
var createArtifactElement = (id) => `<artifact id=${id} />`;
|
|
885
|
-
var LLMModel = S2.Literal(
|
|
911
|
+
var LLMModel = S2.Literal(...DEFAULT_LLM_MODELS);
|
|
886
912
|
var ToolTypes = Object.freeze({
|
|
887
913
|
// TODO(dmaretskyi): Not implemented yet.
|
|
888
914
|
// DatabaseQuery: 'database_query',
|
|
@@ -891,13 +917,14 @@ var ToolTypes = Object.freeze({
|
|
|
891
917
|
var GenerateRequest = S2.Struct({
|
|
892
918
|
spaceId: S2.optional(SpaceIdSchema),
|
|
893
919
|
threadId: S2.optional(ObjectId),
|
|
894
|
-
// TODO(burdon): Make optional with default.
|
|
895
|
-
model: LLMModel,
|
|
896
920
|
/**
|
|
897
|
-
*
|
|
921
|
+
* Preferred model or system default.
|
|
898
922
|
*/
|
|
899
|
-
|
|
900
|
-
|
|
923
|
+
model: S2.optional(LLMModel),
|
|
924
|
+
/**
|
|
925
|
+
* Tools available for the LLM.
|
|
926
|
+
*/
|
|
927
|
+
tools: S2.optional(S2.Array(Tool).pipe(S2.mutable)),
|
|
901
928
|
/**
|
|
902
929
|
* System instructions to the LLM.
|
|
903
930
|
*/
|
|
@@ -905,24 +932,25 @@ var GenerateRequest = S2.Struct({
|
|
|
905
932
|
/**
|
|
906
933
|
* History of messages to include in the context window.
|
|
907
934
|
*/
|
|
935
|
+
// TODO(burdon): Rename messages.
|
|
908
936
|
history: S2.optional(S2.Array(Message3)),
|
|
909
937
|
/**
|
|
910
|
-
*
|
|
938
|
+
* Current request.
|
|
911
939
|
*/
|
|
912
|
-
|
|
940
|
+
prompt: S2.optional(Message3)
|
|
913
941
|
});
|
|
914
942
|
|
|
915
943
|
// packages/experimental/assistant/src/conversation/conversation.ts
|
|
916
944
|
import { ToolResult, Message as Message4 } from "@dxos/artifact";
|
|
917
945
|
import { createStatic as createStatic2, ObjectId as ObjectId2 } from "@dxos/echo-schema";
|
|
918
946
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
919
|
-
import { log as
|
|
947
|
+
import { log as log4 } from "@dxos/log";
|
|
920
948
|
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/experimental/assistant/src/conversation/conversation.ts";
|
|
921
949
|
var runLLM = async (params) => {
|
|
922
950
|
let conversationResult = null;
|
|
923
951
|
const history = params.history ?? [];
|
|
924
952
|
const generate = async () => {
|
|
925
|
-
|
|
953
|
+
log4("llm generate", {
|
|
926
954
|
tools: params.tools
|
|
927
955
|
}, {
|
|
928
956
|
F: __dxlog_file4,
|
|
@@ -931,7 +959,7 @@ var runLLM = async (params) => {
|
|
|
931
959
|
C: (f, a) => f(...a)
|
|
932
960
|
});
|
|
933
961
|
const beginTs = Date.now();
|
|
934
|
-
const stream = await params.client.
|
|
962
|
+
const stream = await params.client.exec({
|
|
935
963
|
model: params.model,
|
|
936
964
|
spaceId: params.spaceId,
|
|
937
965
|
threadId: params.threadId,
|
|
@@ -954,7 +982,7 @@ var runLLM = async (params) => {
|
|
|
954
982
|
""
|
|
955
983
|
]
|
|
956
984
|
});
|
|
957
|
-
|
|
985
|
+
log4("llm result", {
|
|
958
986
|
time: Date.now() - beginTs,
|
|
959
987
|
message
|
|
960
988
|
}, {
|
|
@@ -1009,7 +1037,7 @@ var runLLM = async (params) => {
|
|
|
1009
1037
|
const toolResult = await tool.execute(toolCall.input);
|
|
1010
1038
|
switch (toolResult.kind) {
|
|
1011
1039
|
case "error": {
|
|
1012
|
-
|
|
1040
|
+
log4.warn("tool error", {
|
|
1013
1041
|
message: toolResult.message
|
|
1014
1042
|
}, {
|
|
1015
1043
|
F: __dxlog_file4,
|
|
@@ -1039,7 +1067,7 @@ var runLLM = async (params) => {
|
|
|
1039
1067
|
return true;
|
|
1040
1068
|
}
|
|
1041
1069
|
case "success": {
|
|
1042
|
-
|
|
1070
|
+
log4("tool success", {
|
|
1043
1071
|
result: toolResult.result
|
|
1044
1072
|
}, {
|
|
1045
1073
|
F: __dxlog_file4,
|
|
@@ -1068,7 +1096,7 @@ var runLLM = async (params) => {
|
|
|
1068
1096
|
return true;
|
|
1069
1097
|
}
|
|
1070
1098
|
case "break": {
|
|
1071
|
-
|
|
1099
|
+
log4("tool break", {
|
|
1072
1100
|
result: toolResult.result
|
|
1073
1101
|
}, {
|
|
1074
1102
|
F: __dxlog_file4,
|
|
@@ -1134,7 +1162,7 @@ var runTools = async ({ message, tools, extensions }) => {
|
|
|
1134
1162
|
extensions
|
|
1135
1163
|
});
|
|
1136
1164
|
} catch (error) {
|
|
1137
|
-
|
|
1165
|
+
log4("tool error", {
|
|
1138
1166
|
error
|
|
1139
1167
|
}, {
|
|
1140
1168
|
F: __dxlog_file4,
|
|
@@ -1146,7 +1174,7 @@ var runTools = async ({ message, tools, extensions }) => {
|
|
|
1146
1174
|
}
|
|
1147
1175
|
switch (toolResult.kind) {
|
|
1148
1176
|
case "error": {
|
|
1149
|
-
|
|
1177
|
+
log4("tool error", {
|
|
1150
1178
|
message: toolResult.message
|
|
1151
1179
|
}, {
|
|
1152
1180
|
F: __dxlog_file4,
|
|
@@ -1171,7 +1199,7 @@ var runTools = async ({ message, tools, extensions }) => {
|
|
|
1171
1199
|
};
|
|
1172
1200
|
}
|
|
1173
1201
|
case "success": {
|
|
1174
|
-
|
|
1202
|
+
log4("tool success", {
|
|
1175
1203
|
result: toolResult.result
|
|
1176
1204
|
}, {
|
|
1177
1205
|
F: __dxlog_file4,
|
|
@@ -1195,7 +1223,7 @@ var runTools = async ({ message, tools, extensions }) => {
|
|
|
1195
1223
|
};
|
|
1196
1224
|
}
|
|
1197
1225
|
case "break": {
|
|
1198
|
-
|
|
1226
|
+
log4("tool break", {
|
|
1199
1227
|
result: toolResult.result
|
|
1200
1228
|
}, {
|
|
1201
1229
|
F: __dxlog_file4,
|
|
@@ -1212,6 +1240,8 @@ var runTools = async ({ message, tools, extensions }) => {
|
|
|
1212
1240
|
};
|
|
1213
1241
|
export {
|
|
1214
1242
|
AIServiceClientImpl,
|
|
1243
|
+
DEFAULT_LLM_MODEL,
|
|
1244
|
+
DEFAULT_LLM_MODELS,
|
|
1215
1245
|
EchoDataSource,
|
|
1216
1246
|
GenerateRequest,
|
|
1217
1247
|
GenerationStream,
|