@dxos/assistant 0.9.0 → 0.9.1-staging.ee54ba693a
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/neutral/extraction/index.mjs +108 -119
- package/dist/lib/neutral/extraction/index.mjs.map +4 -4
- package/dist/lib/neutral/index.mjs +395 -234
- package/dist/lib/neutral/index.mjs.map +4 -4
- package/dist/lib/neutral/meta.json +1 -1
- package/dist/types/src/extraction/extraction-llm-function/index.d.ts +2 -0
- package/dist/types/src/extraction/extraction-llm-function/index.d.ts.map +1 -0
- package/dist/types/src/extraction/extraction-llm-function/proper-noun-extraction.d.ts +26 -0
- package/dist/types/src/extraction/extraction-llm-function/proper-noun-extraction.d.ts.map +1 -0
- package/dist/types/src/extraction/index.d.ts +1 -1
- package/dist/types/src/extraction/index.d.ts.map +1 -1
- package/dist/types/src/extraction/quotes.d.ts +8 -1
- package/dist/types/src/extraction/quotes.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/request/AiRequest.d.ts +19 -208
- package/dist/types/src/request/AiRequest.d.ts.map +1 -1
- package/dist/types/src/request/format.d.ts +1 -1
- package/dist/types/src/request/format.d.ts.map +1 -1
- package/dist/types/src/session/AiContext.d.ts +27 -105
- package/dist/types/src/session/AiContext.d.ts.map +1 -1
- package/dist/types/src/session/AiSession.d.ts +11 -29
- package/dist/types/src/session/AiSession.d.ts.map +1 -1
- package/dist/types/src/session/Harness.d.ts +122 -0
- package/dist/types/src/session/Harness.d.ts.map +1 -0
- package/dist/types/src/session/SessionLink.d.ts +8 -11
- package/dist/types/src/session/SessionLink.d.ts.map +1 -1
- package/dist/types/src/session/SessionLoader.d.ts +2 -2
- package/dist/types/src/session/SessionLoader.d.ts.map +1 -1
- package/dist/types/src/session/SkillHooks.d.ts +28 -0
- package/dist/types/src/session/SkillHooks.d.ts.map +1 -0
- package/dist/types/src/session/harness-control.d.ts +177 -0
- package/dist/types/src/session/harness-control.d.ts.map +1 -0
- package/dist/types/src/session/index.d.ts +3 -0
- package/dist/types/src/session/index.d.ts.map +1 -1
- package/dist/types/src/session/toolkit.d.ts +4 -4
- package/dist/types/src/session/toolkit.d.ts.map +1 -1
- package/dist/types/src/templates/system.d.ts +4 -6
- package/dist/types/src/templates/system.d.ts.map +1 -1
- package/dist/types/src/tool-runtime/index.d.ts.map +1 -0
- package/dist/types/src/tool-runtime/services.d.ts.map +1 -0
- package/dist/types/src/util/artifact.d.ts.map +1 -1
- package/dist/types/src/util/diff.d.ts +9 -3
- package/dist/types/src/util/diff.d.ts.map +1 -1
- package/dist/types/src/util/tracing.d.ts +40 -0
- package/dist/types/src/util/tracing.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +28 -25
- package/src/extraction/extraction-llm-function/index.ts +5 -0
- package/src/extraction/extraction-llm-function/proper-noun-extraction.ts +78 -0
- package/src/extraction/index.ts +1 -1
- package/src/extraction/quotes.test.ts +67 -2
- package/src/extraction/quotes.ts +47 -13
- package/src/index.ts +1 -1
- package/src/request/AiRequest.ts +45 -14
- package/src/request/format.ts +9 -11
- package/src/session/AiContext.test.ts +52 -32
- package/src/session/AiContext.ts +73 -95
- package/src/session/AiSession.test.ts +4 -4
- package/src/session/AiSession.ts +51 -83
- package/src/session/Harness.ts +241 -0
- package/src/session/SessionLink.ts +8 -8
- package/src/session/SessionLoader.ts +4 -4
- package/src/session/SkillHooks.ts +71 -0
- package/src/session/harness-control.ts +30 -0
- package/src/session/index.ts +3 -0
- package/src/session/toolkit.ts +8 -8
- package/src/templates/instructions/format.tpl +3 -3
- package/src/templates/instructions/system.tpl +10 -12
- package/src/templates/system.ts +6 -2
- package/src/util/artifact.ts +9 -2
- package/src/util/diff.test.ts +4 -4
- package/src/util/diff.ts +15 -8
- package/src/util/tracing.ts +1 -1
- package/dist/types/src/extraction/extraction.d.ts +0 -1677
- package/dist/types/src/extraction/extraction.d.ts.map +0 -1
- package/dist/types/src/functions/index.d.ts.map +0 -1
- package/dist/types/src/functions/services.d.ts.map +0 -1
- package/src/extraction/extraction-llm-function/transcription-instructions.tpl +0 -28
- package/src/extraction/extraction.ts +0 -105
- /package/dist/types/src/{functions → tool-runtime}/index.d.ts +0 -0
- /package/dist/types/src/{functions → tool-runtime}/services.d.ts +0 -0
- /package/src/{functions → tool-runtime}/index.ts +0 -0
- /package/src/{functions → tool-runtime}/services.ts +0 -0
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
__export
|
|
3
3
|
} from "./chunk-J5LGTIGS.mjs";
|
|
4
4
|
|
|
5
|
-
// src/
|
|
5
|
+
// src/tool-runtime/services.ts
|
|
6
6
|
import * as Tool from "@effect/ai/Tool";
|
|
7
7
|
import * as Context from "effect/Context";
|
|
8
8
|
import * as Effect2 from "effect/Effect";
|
|
@@ -77,8 +77,11 @@ var ArtifactURI = class extends Schema.String.annotations({
|
|
|
77
77
|
}
|
|
78
78
|
};
|
|
79
79
|
var RefFromLLM = Schema.transform(ArtifactURI, Ref.Ref(Obj.Unknown), {
|
|
80
|
-
decode: (fromA
|
|
81
|
-
|
|
80
|
+
decode: (fromA) => {
|
|
81
|
+
const eid = ArtifactURI.toEchoURI(fromA);
|
|
82
|
+
return EncodedReference.fromURI(EID.toLocal(eid));
|
|
83
|
+
},
|
|
84
|
+
encode: (toI) => EncodedReference.toURI(toI),
|
|
82
85
|
strict: false
|
|
83
86
|
}).annotations({
|
|
84
87
|
description: ArtifactURI.ast.annotations.description
|
|
@@ -86,7 +89,8 @@ var RefFromLLM = Schema.transform(ArtifactURI, Ref.Ref(Obj.Unknown), {
|
|
|
86
89
|
|
|
87
90
|
// src/util/diff.ts
|
|
88
91
|
import { next as A } from "@automerge/automerge";
|
|
89
|
-
import {
|
|
92
|
+
import { toCursorRange } from "@dxos/echo-client";
|
|
93
|
+
import { Doc } from "@dxos/echo-doc";
|
|
90
94
|
import { log } from "@dxos/log";
|
|
91
95
|
import { isNonNullable } from "@dxos/util";
|
|
92
96
|
var __dxlog_file = "/__w/dxos/dxos/packages/core/compute/assistant/src/util/diff.ts";
|
|
@@ -125,7 +129,7 @@ var reduceDiffs = (diffs) => {
|
|
|
125
129
|
};
|
|
126
130
|
var computeDiffsWithCursors = (accessor, diffs) => {
|
|
127
131
|
return reduceDiffs(diffs).map((diff) => {
|
|
128
|
-
const text =
|
|
132
|
+
const text = Doc.getValue(accessor);
|
|
129
133
|
const idx = text.indexOf(diff.match);
|
|
130
134
|
if (idx !== -1) {
|
|
131
135
|
return {
|
|
@@ -138,7 +142,7 @@ var computeDiffsWithCursors = (accessor, diffs) => {
|
|
|
138
142
|
var applyDiffs = (accessor, diffs, { errorOnNotFound = false } = {}) => {
|
|
139
143
|
for (const diff of reduceDiffs(diffs)) {
|
|
140
144
|
accessor.handle.change((doc) => {
|
|
141
|
-
const text =
|
|
145
|
+
const text = Doc.getValue(accessor);
|
|
142
146
|
const idx = text.indexOf(diff.match);
|
|
143
147
|
if (idx !== -1) {
|
|
144
148
|
A.splice(doc, accessor.path, idx, diff.match.length, diff.replace);
|
|
@@ -146,12 +150,12 @@ var applyDiffs = (accessor, diffs, { errorOnNotFound = false } = {}) => {
|
|
|
146
150
|
if (errorOnNotFound) {
|
|
147
151
|
throw new Error(`Diff not found: ${diff.match}`);
|
|
148
152
|
} else {
|
|
149
|
-
log.warn("diff not found", diff, { "~LogMeta": "~LogMeta", F: __dxlog_file, L:
|
|
153
|
+
log.warn("diff not found", diff, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 76, S: void 0 });
|
|
150
154
|
}
|
|
151
155
|
}
|
|
152
156
|
});
|
|
153
157
|
}
|
|
154
|
-
return
|
|
158
|
+
return Doc.getValue(accessor);
|
|
155
159
|
};
|
|
156
160
|
|
|
157
161
|
// src/util/error-handling.ts
|
|
@@ -584,7 +588,7 @@ var stringifyObject = (obj) => {
|
|
|
584
588
|
import * as Schema3 from "effect/Schema";
|
|
585
589
|
import { Trace } from "@dxos/compute";
|
|
586
590
|
import { Obj as Obj3 } from "@dxos/echo";
|
|
587
|
-
import { ContentBlock as ContentBlock2
|
|
591
|
+
import { Actor, ContentBlock as ContentBlock2 } from "@dxos/types";
|
|
588
592
|
var PartialBlock = Trace.EventType("assistant.partialBlock", {
|
|
589
593
|
schema: Schema3.Struct({
|
|
590
594
|
messageId: Obj3.ID,
|
|
@@ -621,8 +625,8 @@ var McpServerError = Trace.EventType("assistant.mcpServerError", {
|
|
|
621
625
|
isEphemeral: true
|
|
622
626
|
});
|
|
623
627
|
|
|
624
|
-
// src/
|
|
625
|
-
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/compute/assistant/src/
|
|
628
|
+
// src/tool-runtime/services.ts
|
|
629
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/compute/assistant/src/tool-runtime/services.ts";
|
|
626
630
|
var makeToolResolverFromOperations = ({ toolkit: extraToolkit = OpaqueToolkit.empty } = {}) => {
|
|
627
631
|
return Layer.effect(ToolResolverService, Effect2.gen(function* () {
|
|
628
632
|
const toolkitProvider = yield* OpaqueToolkit.OpaqueToolkitProvider;
|
|
@@ -761,16 +765,16 @@ var ArtifactDiffResolver = class extends Context2.Tag("@dxos/assistant/ArtifactD
|
|
|
761
765
|
|
|
762
766
|
// src/request/format.ts
|
|
763
767
|
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/compute/assistant/src/request/format.ts";
|
|
764
|
-
var formatSystemPrompt = ({ system,
|
|
765
|
-
const
|
|
768
|
+
var formatSystemPrompt = ({ system, skills = [], objects = [] }) => Effect3.gen(function* () {
|
|
769
|
+
const skillDefs = yield* Function.pipe(skills, Effect3.forEach((skill) => Effect3.succeed(skill.instructions)), Effect3.flatMap(Effect3.forEach((template) => Effect3.gen(function* () {
|
|
766
770
|
return trim2`
|
|
767
|
-
<
|
|
771
|
+
<skill>
|
|
768
772
|
${yield* Template.processTemplate(template)}
|
|
769
|
-
</
|
|
773
|
+
</skill>
|
|
770
774
|
`;
|
|
771
|
-
}))), Effect3.map((
|
|
772
|
-
"##
|
|
773
|
-
...
|
|
775
|
+
}))), Effect3.map((skills2) => skills2.length > 0 ? [
|
|
776
|
+
"## Skills Definitions",
|
|
777
|
+
...skills2
|
|
774
778
|
].join("\n\n") : void 0));
|
|
775
779
|
const objectDefs = yield* Function.pipe(objects, Effect3.forEach((object) => Effect3.succeed(trim2`
|
|
776
780
|
<object>
|
|
@@ -783,15 +787,15 @@ var formatSystemPrompt = ({ system, blueprints = [], objects = [] }) => Effect3.
|
|
|
783
787
|
].join("\n\n") : void 0));
|
|
784
788
|
return yield* Function.pipe(Effect3.succeed([
|
|
785
789
|
system,
|
|
786
|
-
|
|
790
|
+
skillDefs,
|
|
787
791
|
objectDefs
|
|
788
792
|
].filter((def) => def !== void 0)), Effect3.map((parts) => parts.join("\n\n")));
|
|
789
793
|
}).pipe(Effect3.withSpan("formatSystemPrompt"));
|
|
790
|
-
var formatUserPrompt = ({ prompt, history = [] }) => Effect3.gen(function* () {
|
|
794
|
+
var formatUserPrompt = ({ prompt, history: history2 = [] }) => Effect3.gen(function* () {
|
|
791
795
|
const blocks = [];
|
|
792
796
|
const artifactDiffResolver = yield* Effect3.serviceOption(ArtifactDiffResolver);
|
|
793
797
|
if (Option2.isSome(artifactDiffResolver)) {
|
|
794
|
-
const versions = gatherObjectVersions(
|
|
798
|
+
const versions = gatherObjectVersions(history2);
|
|
795
799
|
const artifactDiff = yield* Effect3.tryPromise({
|
|
796
800
|
try: () => artifactDiffResolver.value.resolve([
|
|
797
801
|
...versions.entries()
|
|
@@ -947,12 +951,15 @@ var Request = class {
|
|
|
947
951
|
_submitMessage = (message) => Effect5.gen(this, function* () {
|
|
948
952
|
this._pending.push(message);
|
|
949
953
|
yield* this._observer.onMessage(message);
|
|
954
|
+
if (this._options.persist === false) {
|
|
955
|
+
return message;
|
|
956
|
+
}
|
|
950
957
|
for (const block of message.blocks) {
|
|
951
958
|
log3("write complete block", {
|
|
952
959
|
messageId: message.id,
|
|
953
960
|
role: message.sender.role,
|
|
954
961
|
block: JSON.stringify(block)
|
|
955
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L:
|
|
962
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 62, S: this });
|
|
956
963
|
yield* Trace2.write(CompleteBlock, {
|
|
957
964
|
messageId: message.id,
|
|
958
965
|
role: message.sender.role,
|
|
@@ -973,15 +980,15 @@ var Request = class {
|
|
|
973
980
|
* Initialize a session: set up history, perform summarization if needed, and submit the user prompt.
|
|
974
981
|
* Must be called before `runTurn()`.
|
|
975
982
|
*/
|
|
976
|
-
begin = ({ prompt, system, history = [],
|
|
983
|
+
begin = ({ prompt, system, history: history2 = [], skills = [], objects = [] }) => Effect5.gen(this, function* () {
|
|
977
984
|
this._started = Date.now();
|
|
978
985
|
this._history = [
|
|
979
|
-
...
|
|
986
|
+
...history2
|
|
980
987
|
];
|
|
981
988
|
this._pending = [];
|
|
982
989
|
const systemPrompt = yield* formatSystemPrompt({
|
|
983
990
|
system,
|
|
984
|
-
|
|
991
|
+
skills,
|
|
985
992
|
objects
|
|
986
993
|
}).pipe(Effect5.orDie);
|
|
987
994
|
if (this._options.summarizationThreshold !== void 0) {
|
|
@@ -999,12 +1006,12 @@ var Request = class {
|
|
|
999
1006
|
}
|
|
1000
1007
|
yield* this._submitMessage(yield* formatUserPrompt({
|
|
1001
1008
|
prompt,
|
|
1002
|
-
history
|
|
1009
|
+
history: history2
|
|
1003
1010
|
}));
|
|
1004
1011
|
}).pipe(Effect5.withSpan("AiRequest.begin"));
|
|
1005
1012
|
/**
|
|
1006
1013
|
* Execute a single turn: one LLM generation followed by tool execution.
|
|
1007
|
-
* The toolkit and system prompt can be updated between turns to reflect context changes (e.g. dynamically enabled
|
|
1014
|
+
* The toolkit and system prompt can be updated between turns to reflect context changes (e.g. dynamically enabled skills).
|
|
1008
1015
|
*/
|
|
1009
1016
|
runAgentTurn = ({ system, toolkit: opaqueToolkit }) => Effect5.gen(this, function* () {
|
|
1010
1017
|
log3("request", {
|
|
@@ -1014,7 +1021,7 @@ var Request = class {
|
|
|
1014
1021
|
},
|
|
1015
1022
|
pending: this._pending.length,
|
|
1016
1023
|
history: this._history.length
|
|
1017
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L:
|
|
1024
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 119, S: this });
|
|
1018
1025
|
const prompt = yield* AiPreprocessor.preprocessPrompt([
|
|
1019
1026
|
...this._history,
|
|
1020
1027
|
...this._pending
|
|
@@ -1025,6 +1032,7 @@ var Request = class {
|
|
|
1025
1032
|
const toolkit = opaqueToolkit ? yield* opaqueToolkit.handlers : void 0;
|
|
1026
1033
|
const observer = this._observer;
|
|
1027
1034
|
let currentMessageId = null;
|
|
1035
|
+
let finishReason;
|
|
1028
1036
|
const messages = yield* LanguageModel.streamText({
|
|
1029
1037
|
prompt,
|
|
1030
1038
|
toolkit,
|
|
@@ -1036,12 +1044,15 @@ var Request = class {
|
|
|
1036
1044
|
onPart: (part) => observer.onPart(part),
|
|
1037
1045
|
onEnd: (summary) => observer.onEnd(summary)
|
|
1038
1046
|
}), Stream.map((block) => enrichToolCallBlock(block, toolkit)), Stream.mapEffect((block) => Effect5.gen(this, function* () {
|
|
1047
|
+
if (block._tag === "stats" && block.finishReason !== void 0) {
|
|
1048
|
+
finishReason = block.finishReason;
|
|
1049
|
+
}
|
|
1039
1050
|
if (block.pending) {
|
|
1040
1051
|
currentMessageId ??= Obj5.ID.random();
|
|
1041
1052
|
log3("emit ephemeral message", {
|
|
1042
1053
|
id: currentMessageId,
|
|
1043
1054
|
type: block._tag
|
|
1044
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L:
|
|
1055
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 154, S: this });
|
|
1045
1056
|
yield* Trace2.write(PartialBlock, {
|
|
1046
1057
|
messageId: currentMessageId,
|
|
1047
1058
|
role: "assistant",
|
|
@@ -1055,7 +1066,7 @@ var Request = class {
|
|
|
1055
1066
|
log3("emit complete message", {
|
|
1056
1067
|
id,
|
|
1057
1068
|
type: block._tag
|
|
1058
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L:
|
|
1069
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 168, S: this });
|
|
1059
1070
|
const message = Obj5.make(Message3.Message, {
|
|
1060
1071
|
id,
|
|
1061
1072
|
created: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -1074,20 +1085,29 @@ var Request = class {
|
|
|
1074
1085
|
}), Stream.filterMap((_) => _), Stream.runCollect, Effect5.map(Chunk.toArray));
|
|
1075
1086
|
log3("messages", {
|
|
1076
1087
|
messages
|
|
1077
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L:
|
|
1088
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 188, S: this });
|
|
1089
|
+
if (finishReason === "pause") {
|
|
1090
|
+
return {
|
|
1091
|
+
messages,
|
|
1092
|
+
done: false,
|
|
1093
|
+
finishReason
|
|
1094
|
+
};
|
|
1095
|
+
}
|
|
1078
1096
|
const toolCalls = this.getToolCalls();
|
|
1079
1097
|
if (toolCalls.length === 0) {
|
|
1080
1098
|
this._ended = Date.now();
|
|
1081
1099
|
return {
|
|
1082
1100
|
messages,
|
|
1083
|
-
done: true
|
|
1101
|
+
done: true,
|
|
1102
|
+
finishReason
|
|
1084
1103
|
};
|
|
1085
1104
|
} else if (!toolkit) {
|
|
1086
1105
|
throw new Error("No toolkit provided");
|
|
1087
1106
|
}
|
|
1088
1107
|
return {
|
|
1089
1108
|
messages,
|
|
1090
|
-
done: false
|
|
1109
|
+
done: false,
|
|
1110
|
+
finishReason
|
|
1091
1111
|
};
|
|
1092
1112
|
}).pipe(Effect5.withSpan("AiRequest.runAgentTurn"));
|
|
1093
1113
|
runTools = ({ toolkit: opaqueToolkit }) => Effect5.gen(this, function* () {
|
|
@@ -1111,27 +1131,30 @@ var Request = class {
|
|
|
1111
1131
|
/**
|
|
1112
1132
|
* Run a full conversation turn loop. Equivalent to calling `begin()` then `runTurn()` in a loop.
|
|
1113
1133
|
*/
|
|
1114
|
-
run = ({ prompt, system: systemTemplate, history = [], objects = [],
|
|
1134
|
+
run = ({ prompt, system: systemTemplate, history: history2 = [], objects = [], skills = [], toolkit }) => Effect5.gen(this, function* () {
|
|
1115
1135
|
yield* this.begin({
|
|
1116
1136
|
prompt,
|
|
1117
1137
|
system: systemTemplate,
|
|
1118
|
-
history,
|
|
1138
|
+
history: history2,
|
|
1119
1139
|
objects,
|
|
1120
|
-
|
|
1140
|
+
skills
|
|
1121
1141
|
});
|
|
1122
1142
|
const system = yield* formatSystemPrompt({
|
|
1123
1143
|
system: systemTemplate,
|
|
1124
|
-
|
|
1144
|
+
skills,
|
|
1125
1145
|
objects
|
|
1126
1146
|
}).pipe(Effect5.orDie);
|
|
1127
1147
|
do {
|
|
1128
|
-
const { done } = yield* this.runAgentTurn({
|
|
1148
|
+
const { done, finishReason } = yield* this.runAgentTurn({
|
|
1129
1149
|
system,
|
|
1130
1150
|
toolkit
|
|
1131
1151
|
});
|
|
1132
1152
|
if (done) {
|
|
1133
1153
|
break;
|
|
1134
1154
|
}
|
|
1155
|
+
if (finishReason === "pause") {
|
|
1156
|
+
continue;
|
|
1157
|
+
}
|
|
1135
1158
|
yield* this.runTools({
|
|
1136
1159
|
toolkit
|
|
1137
1160
|
});
|
|
@@ -1140,7 +1163,7 @@ var Request = class {
|
|
|
1140
1163
|
pending: this._pending.length,
|
|
1141
1164
|
duration: this.duration,
|
|
1142
1165
|
tools: this._toolCalls
|
|
1143
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L:
|
|
1166
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 267, S: this });
|
|
1144
1167
|
return this._pending;
|
|
1145
1168
|
}).pipe(this._semaphore.withPermits(1), Effect5.withSpan("AiRequest.run"));
|
|
1146
1169
|
};
|
|
@@ -1181,17 +1204,17 @@ import * as Effect6 from "effect/Effect";
|
|
|
1181
1204
|
import * as Layer2 from "effect/Layer";
|
|
1182
1205
|
import { OpaqueToolkit as OpaqueToolkit2, ToolExecutionService as ToolExecutionService2, ToolResolverService as ToolResolverService2 } from "@dxos/ai";
|
|
1183
1206
|
import { isTruthy } from "@dxos/util";
|
|
1184
|
-
var createToolkit = ({ toolkit: toolkitProp,
|
|
1185
|
-
const
|
|
1186
|
-
const
|
|
1207
|
+
var createToolkit = ({ toolkit: toolkitProp, skills = [], opaqueToolkits = [] }) => Effect6.gen(function* () {
|
|
1208
|
+
const skillToolkit = yield* ToolResolverService2.resolveToolkit(skills.flatMap(({ tools }) => tools));
|
|
1209
|
+
const skillToolHandler = yield* skillToolkit.toContext(ToolExecutionService2.handlersFor(skillToolkit));
|
|
1187
1210
|
const opaqueToolkit = OpaqueToolkit2.merge(...opaqueToolkits);
|
|
1188
1211
|
const toolkitDefs = [
|
|
1189
1212
|
toolkitProp?.toolkit,
|
|
1190
|
-
|
|
1213
|
+
skillToolkit,
|
|
1191
1214
|
opaqueToolkit.toolkit
|
|
1192
1215
|
].filter(isTruthy);
|
|
1193
1216
|
const mergedToolkit = Toolkit.merge(...toolkitDefs);
|
|
1194
|
-
const combinedHandlerLayer = Layer2.mergeAll(Layer2.succeedContext(
|
|
1217
|
+
const combinedHandlerLayer = Layer2.mergeAll(Layer2.succeedContext(skillToolHandler), toolkitProp?.layer ?? OpaqueToolkit2.empty.layer, opaqueToolkit.layer);
|
|
1195
1218
|
return OpaqueToolkit2.make(mergedToolkit, combinedHandlerLayer);
|
|
1196
1219
|
});
|
|
1197
1220
|
|
|
@@ -1200,17 +1223,14 @@ var AiContext_exports = {};
|
|
|
1200
1223
|
__export(AiContext_exports, {
|
|
1201
1224
|
Binder: () => Binder,
|
|
1202
1225
|
Binding: () => Binding,
|
|
1203
|
-
Bindings: () => Bindings
|
|
1204
|
-
Service: () => Service
|
|
1226
|
+
Bindings: () => Bindings
|
|
1205
1227
|
});
|
|
1206
1228
|
import { Atom, Registry as AtomRegistry } from "@effect-atom/atom-react";
|
|
1207
1229
|
import * as EArray from "effect/Array";
|
|
1208
|
-
import * as Context3 from "effect/Context";
|
|
1209
|
-
import * as Effect7 from "effect/Effect";
|
|
1210
1230
|
import * as Function3 from "effect/Function";
|
|
1211
1231
|
import * as Runtime from "effect/Runtime";
|
|
1212
1232
|
import * as Schema5 from "effect/Schema";
|
|
1213
|
-
import {
|
|
1233
|
+
import { Skill } from "@dxos/compute";
|
|
1214
1234
|
import { Resource } from "@dxos/context";
|
|
1215
1235
|
import { Annotation, DXN as DXN2, Feed, Obj as Obj6, Query, Ref as Ref3, Type as Type2 } from "@dxos/echo";
|
|
1216
1236
|
import { assertArgument } from "@dxos/invariant";
|
|
@@ -1218,18 +1238,19 @@ import { EID as EID3 } from "@dxos/keys";
|
|
|
1218
1238
|
import { log as log4 } from "@dxos/log";
|
|
1219
1239
|
import { ComplexSet, isNonNullable as isNonNullable3 } from "@dxos/util";
|
|
1220
1240
|
var __dxlog_file5 = "/__w/dxos/dxos/packages/core/compute/assistant/src/session/AiContext.ts";
|
|
1221
|
-
var Binding = Schema5.Struct({
|
|
1222
|
-
|
|
1223
|
-
added: Schema5.Array(Ref3.Ref(
|
|
1224
|
-
removed: Schema5.Array(Ref3.Ref(
|
|
1241
|
+
var Binding = class extends Type2.makeObject(DXN2.make("org.dxos.type.contextBinding", "0.1.0"))(Schema5.Struct({
|
|
1242
|
+
skills: Schema5.Struct({
|
|
1243
|
+
added: Schema5.Array(Ref3.Ref(Skill.Skill)),
|
|
1244
|
+
removed: Schema5.Array(Ref3.Ref(Skill.Skill))
|
|
1225
1245
|
}),
|
|
1226
1246
|
objects: Schema5.Struct({
|
|
1227
1247
|
added: Schema5.Array(Ref3.Ref(Obj6.Unknown)),
|
|
1228
1248
|
removed: Schema5.Array(Ref3.Ref(Obj6.Unknown))
|
|
1229
1249
|
})
|
|
1230
|
-
}).pipe(Annotation.HiddenAnnotation.set(true)
|
|
1250
|
+
}).pipe(Annotation.HiddenAnnotation.set(true))) {
|
|
1251
|
+
};
|
|
1231
1252
|
var Bindings = class {
|
|
1232
|
-
|
|
1253
|
+
skills = new ComplexSet((ref) => ref.uri);
|
|
1233
1254
|
// TODO(burdon): Some DXNs have the Space prefix so only compare the object ID.
|
|
1234
1255
|
objects = new ComplexSet((ref) => {
|
|
1235
1256
|
const echoUri = EID3.tryParse(ref.uri);
|
|
@@ -1237,13 +1258,13 @@ var Bindings = class {
|
|
|
1237
1258
|
});
|
|
1238
1259
|
toJSON() {
|
|
1239
1260
|
return {
|
|
1240
|
-
|
|
1261
|
+
skills: EArray.fromIterable(this.skills).map((ref) => ref.uri),
|
|
1241
1262
|
objects: EArray.fromIterable(this.objects).map((ref) => ref.uri)
|
|
1242
1263
|
};
|
|
1243
1264
|
}
|
|
1244
1265
|
};
|
|
1245
1266
|
var Binder = class extends Resource {
|
|
1246
|
-
|
|
1267
|
+
_skills = Atom.make([]).pipe(Atom.keepAlive);
|
|
1247
1268
|
_objects = Atom.make([]).pipe(Atom.keepAlive);
|
|
1248
1269
|
_registry;
|
|
1249
1270
|
_feed;
|
|
@@ -1258,10 +1279,10 @@ var Binder = class extends Resource {
|
|
|
1258
1279
|
this._registry = options.registry ?? AtomRegistry.make();
|
|
1259
1280
|
}
|
|
1260
1281
|
/**
|
|
1261
|
-
* Returns the
|
|
1282
|
+
* Returns the skills atom for subscription.
|
|
1262
1283
|
*/
|
|
1263
|
-
get
|
|
1264
|
-
return this.
|
|
1284
|
+
get skills() {
|
|
1285
|
+
return this._skills;
|
|
1265
1286
|
}
|
|
1266
1287
|
/**
|
|
1267
1288
|
* Returns the objects atom for subscription.
|
|
@@ -1270,10 +1291,10 @@ var Binder = class extends Resource {
|
|
|
1270
1291
|
return this._objects;
|
|
1271
1292
|
}
|
|
1272
1293
|
/**
|
|
1273
|
-
* Gets the current
|
|
1294
|
+
* Gets the current skills value.
|
|
1274
1295
|
*/
|
|
1275
|
-
|
|
1276
|
-
return this._registry.get(this.
|
|
1296
|
+
getSkills() {
|
|
1297
|
+
return this._registry.get(this._skills);
|
|
1277
1298
|
}
|
|
1278
1299
|
/**
|
|
1279
1300
|
* Gets the current objects value.
|
|
@@ -1282,10 +1303,10 @@ var Binder = class extends Resource {
|
|
|
1282
1303
|
return this._registry.get(this._objects);
|
|
1283
1304
|
}
|
|
1284
1305
|
/**
|
|
1285
|
-
* Subscribe to changes in
|
|
1306
|
+
* Subscribe to changes in skills.
|
|
1286
1307
|
*/
|
|
1287
|
-
|
|
1288
|
-
return this._registry.subscribe(this.
|
|
1308
|
+
subscribeSkills(cb) {
|
|
1309
|
+
return this._registry.subscribe(this._skills, () => cb(this._registry.get(this._skills)));
|
|
1289
1310
|
}
|
|
1290
1311
|
/**
|
|
1291
1312
|
* Subscribe to changes in objects.
|
|
@@ -1309,12 +1330,12 @@ var Binder = class extends Resource {
|
|
|
1309
1330
|
const results = await this.#bindingsQuery.run();
|
|
1310
1331
|
log4("sync", {
|
|
1311
1332
|
bindingItems: results.length
|
|
1312
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L:
|
|
1333
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 107, S: this });
|
|
1313
1334
|
await this._updateBindings(results);
|
|
1314
1335
|
log4("sync complete", {
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L:
|
|
1336
|
+
skills: this._registry.get(this._skills).length,
|
|
1337
|
+
skillKeys: this._registry.get(this._skills).map((bp) => Skill.getKey(bp))
|
|
1338
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 111, S: this });
|
|
1318
1339
|
}
|
|
1319
1340
|
}
|
|
1320
1341
|
async _updateBindings(items) {
|
|
@@ -1324,75 +1345,75 @@ var Binder = class extends Resource {
|
|
|
1324
1345
|
const bindings = this._reduce(items);
|
|
1325
1346
|
log4("_updateBindings", {
|
|
1326
1347
|
items: items.length,
|
|
1327
|
-
|
|
1328
|
-
...bindings.
|
|
1348
|
+
skillRefs: [
|
|
1349
|
+
...bindings.skills
|
|
1329
1350
|
].map((ref) => ({
|
|
1330
1351
|
uri: ref.uri,
|
|
1331
1352
|
available: ref.isAvailable
|
|
1332
1353
|
}))
|
|
1333
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L:
|
|
1334
|
-
const
|
|
1354
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 123, S: this });
|
|
1355
|
+
const currentSkills = this._registry.get(this._skills);
|
|
1335
1356
|
const currentObjects = this._registry.get(this._objects);
|
|
1336
|
-
const
|
|
1357
|
+
const resolvedSkills = await this._resolve(bindings.skills, currentSkills);
|
|
1337
1358
|
const resolvedObjects = await this._resolve(bindings.objects, currentObjects);
|
|
1338
1359
|
log4("_updateBindings resolved", {
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L:
|
|
1342
|
-
const
|
|
1360
|
+
resolvedSkills: resolvedSkills.length,
|
|
1361
|
+
resolvedSkillKeys: resolvedSkills.map((bp) => Obj6.getMeta(bp).key ?? "<missing>")
|
|
1362
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 137, S: this });
|
|
1363
|
+
const keyedSkills = resolvedSkills.filter((bp) => {
|
|
1343
1364
|
if (Obj6.getMeta(bp).key === void 0) {
|
|
1344
|
-
log4.warn("dropping
|
|
1365
|
+
log4.warn("dropping skill with no meta key", {
|
|
1345
1366
|
uri: Obj6.getURI(bp)
|
|
1346
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L:
|
|
1367
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 145, S: this });
|
|
1347
1368
|
return false;
|
|
1348
1369
|
}
|
|
1349
1370
|
return true;
|
|
1350
1371
|
});
|
|
1351
|
-
const
|
|
1352
|
-
...bindings.
|
|
1372
|
+
const reducedSkillDxns = new Set([
|
|
1373
|
+
...bindings.skills
|
|
1353
1374
|
].map((ref) => ref.uri));
|
|
1354
1375
|
const reducedObjectDxns = new Set([
|
|
1355
1376
|
...bindings.objects
|
|
1356
1377
|
].map((ref) => ref.uri));
|
|
1357
|
-
const
|
|
1378
|
+
const filteredSkills = currentSkills.filter((obj) => {
|
|
1358
1379
|
const uri = Obj6.getURI(obj);
|
|
1359
|
-
return uri != null &&
|
|
1380
|
+
return uri != null && reducedSkillDxns.has(uri) && Obj6.getMeta(obj).key !== void 0;
|
|
1360
1381
|
});
|
|
1361
1382
|
const filteredObjects = currentObjects.filter((obj) => {
|
|
1362
1383
|
const uri = Obj6.getURI(obj);
|
|
1363
1384
|
return uri != null && reducedObjectDxns.has(uri);
|
|
1364
1385
|
});
|
|
1365
|
-
const
|
|
1386
|
+
const mergedSkills = this._mergeInto(filteredSkills, keyedSkills);
|
|
1366
1387
|
const mergedObjects = this._mergeInto(filteredObjects, resolvedObjects);
|
|
1367
|
-
this._registry.set(this.
|
|
1388
|
+
this._registry.set(this._skills, mergedSkills);
|
|
1368
1389
|
this._registry.set(this._objects, mergedObjects);
|
|
1369
1390
|
log4("updated bindings", {
|
|
1370
|
-
|
|
1391
|
+
skills: mergedSkills.length,
|
|
1371
1392
|
objects: mergedObjects.length
|
|
1372
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L:
|
|
1393
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 172, S: this });
|
|
1373
1394
|
}
|
|
1374
1395
|
async _close() {
|
|
1375
|
-
this._registry.set(this.
|
|
1396
|
+
this._registry.set(this._skills, []);
|
|
1376
1397
|
this._registry.set(this._objects, []);
|
|
1377
1398
|
}
|
|
1378
|
-
async bind({
|
|
1379
|
-
const
|
|
1399
|
+
async bind({ skills, objects }) {
|
|
1400
|
+
const currentSkills = this._registry.get(this._skills);
|
|
1380
1401
|
const currentObjects = this._registry.get(this._objects);
|
|
1381
|
-
const { added:
|
|
1402
|
+
const { added: addedSkills, next: nextSkills } = this._processBindings(skills, currentSkills);
|
|
1382
1403
|
const { added: addedObjects, next: nextObjects } = this._processBindings(objects, currentObjects);
|
|
1383
|
-
if (!
|
|
1404
|
+
if (!addedSkills.length && !addedObjects.length) {
|
|
1384
1405
|
return;
|
|
1385
1406
|
}
|
|
1386
|
-
this._registry.set(this.
|
|
1407
|
+
this._registry.set(this._skills, nextSkills);
|
|
1387
1408
|
this._registry.set(this._objects, nextObjects);
|
|
1388
1409
|
log4("bind", {
|
|
1389
|
-
|
|
1410
|
+
skills: addedSkills.length,
|
|
1390
1411
|
objects: addedObjects.length
|
|
1391
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L:
|
|
1412
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 193, S: this });
|
|
1392
1413
|
await Runtime.runPromise(this._runtime)(Feed.append(this._feed, [
|
|
1393
1414
|
Obj6.make(Binding, {
|
|
1394
|
-
|
|
1395
|
-
added:
|
|
1415
|
+
skills: {
|
|
1416
|
+
added: addedSkills,
|
|
1396
1417
|
removed: []
|
|
1397
1418
|
},
|
|
1398
1419
|
objects: {
|
|
@@ -1402,29 +1423,29 @@ var Binder = class extends Resource {
|
|
|
1402
1423
|
})
|
|
1403
1424
|
]));
|
|
1404
1425
|
}
|
|
1405
|
-
async unbind({
|
|
1406
|
-
if (!
|
|
1426
|
+
async unbind({ skills, objects }) {
|
|
1427
|
+
if (!skills?.length && !objects?.length) {
|
|
1407
1428
|
return;
|
|
1408
1429
|
}
|
|
1409
|
-
const
|
|
1430
|
+
const removedSkillDxns = (skills ?? []).map((ref) => ref.uri);
|
|
1410
1431
|
const removedObjectDxns = (objects ?? []).map((ref) => ref.uri);
|
|
1411
|
-
if (
|
|
1412
|
-
const current = this._registry.get(this.
|
|
1413
|
-
this._registry.set(this.
|
|
1432
|
+
if (removedSkillDxns.length > 0) {
|
|
1433
|
+
const current = this._registry.get(this._skills);
|
|
1434
|
+
this._registry.set(this._skills, current.filter((obj) => !removedSkillDxns.some((uri) => Obj6.getURI(obj) === uri)));
|
|
1414
1435
|
}
|
|
1415
1436
|
if (removedObjectDxns.length > 0) {
|
|
1416
1437
|
const current = this._registry.get(this._objects);
|
|
1417
1438
|
this._registry.set(this._objects, current.filter((obj) => !removedObjectDxns.some((uri) => Obj6.getURI(obj) === uri)));
|
|
1418
1439
|
}
|
|
1419
1440
|
log4("unbind", {
|
|
1420
|
-
|
|
1441
|
+
skills: skills?.length,
|
|
1421
1442
|
objects: objects?.length
|
|
1422
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L:
|
|
1443
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 225, S: this });
|
|
1423
1444
|
await Runtime.runPromise(this._runtime)(Feed.append(this._feed, [
|
|
1424
1445
|
Obj6.make(Binding, {
|
|
1425
|
-
|
|
1446
|
+
skills: {
|
|
1426
1447
|
added: [],
|
|
1427
|
-
removed:
|
|
1448
|
+
removed: skills ?? []
|
|
1428
1449
|
},
|
|
1429
1450
|
objects: {
|
|
1430
1451
|
added: [],
|
|
@@ -1468,12 +1489,12 @@ var Binder = class extends Resource {
|
|
|
1468
1489
|
};
|
|
1469
1490
|
}
|
|
1470
1491
|
/**
|
|
1471
|
-
* Reduce results into sets of
|
|
1492
|
+
* Reduce results into sets of skills and objects.
|
|
1472
1493
|
*/
|
|
1473
1494
|
_reduce(items) {
|
|
1474
|
-
return Function3.pipe(items, EArray.reduce(new Bindings(), (context, {
|
|
1475
|
-
|
|
1476
|
-
|
|
1495
|
+
return Function3.pipe(items, EArray.reduce(new Bindings(), (context, { skills, objects }) => {
|
|
1496
|
+
skills.added.forEach((ref) => context.skills.add(ref));
|
|
1497
|
+
skills.removed.forEach((ref) => context.skills.delete(ref));
|
|
1477
1498
|
objects.added.forEach((ref) => context.objects.add(ref));
|
|
1478
1499
|
objects.removed.forEach((ref) => {
|
|
1479
1500
|
for (const obj of context.objects) {
|
|
@@ -1504,7 +1525,7 @@ var Binder = class extends Resource {
|
|
|
1504
1525
|
}
|
|
1505
1526
|
/**
|
|
1506
1527
|
* Resolve references to objects, loading them first if needed and falling back to existing objects.
|
|
1507
|
-
* DXN refs (e.g. `dxn:org.dxos.
|
|
1528
|
+
* DXN refs (e.g. `dxn:org.dxos.skill.database`) resolve via the wired-up ECHO ref resolver
|
|
1508
1529
|
* which already spans both the space DB and the hypergraph registry.
|
|
1509
1530
|
*/
|
|
1510
1531
|
async _resolve(refs, current) {
|
|
@@ -1521,47 +1542,56 @@ var Binder = class extends Resource {
|
|
|
1521
1542
|
}).filter(isNonNullable3);
|
|
1522
1543
|
}
|
|
1523
1544
|
};
|
|
1524
|
-
var Service = class _Service extends Context3.Tag("@dxos/assistant/AiContextService")() {
|
|
1525
|
-
static bindContext = ({ blueprints, objects }) => Effect7.gen(function* () {
|
|
1526
|
-
const { binder } = yield* _Service;
|
|
1527
|
-
yield* Effect7.promise(() => binder.bind({
|
|
1528
|
-
blueprints,
|
|
1529
|
-
objects
|
|
1530
|
-
}));
|
|
1531
|
-
});
|
|
1532
|
-
static findObjects = (type) => {
|
|
1533
|
-
return Effect7.gen(function* () {
|
|
1534
|
-
const { binder } = yield* _Service;
|
|
1535
|
-
return binder.getObjects().filter(Obj6.instanceOf(type));
|
|
1536
|
-
});
|
|
1537
|
-
};
|
|
1538
|
-
};
|
|
1539
1545
|
|
|
1540
1546
|
// src/session/AiSession.ts
|
|
1541
1547
|
var AiSession_exports = {};
|
|
1542
1548
|
__export(AiSession_exports, {
|
|
1543
|
-
Service: () => Service2,
|
|
1544
1549
|
Session: () => Session
|
|
1545
1550
|
});
|
|
1546
1551
|
import * as Array4 from "effect/Array";
|
|
1547
|
-
import * as
|
|
1548
|
-
import * as Effect9 from "effect/Effect";
|
|
1552
|
+
import * as Effect10 from "effect/Effect";
|
|
1549
1553
|
import * as Either from "effect/Either";
|
|
1550
1554
|
import { pipe as pipe4 } from "effect/Function";
|
|
1551
|
-
import * as
|
|
1555
|
+
import * as Layer4 from "effect/Layer";
|
|
1552
1556
|
import * as Record2 from "effect/Record";
|
|
1553
1557
|
import * as Runtime2 from "effect/Runtime";
|
|
1554
|
-
import { Operation as
|
|
1558
|
+
import { Operation as Operation3, Trace as Trace3 } from "@dxos/compute";
|
|
1555
1559
|
import { Resource as Resource2 } from "@dxos/context";
|
|
1556
|
-
import {
|
|
1557
|
-
import {
|
|
1558
|
-
import {
|
|
1559
|
-
import { log as log5 } from "@dxos/log";
|
|
1560
|
+
import { Feed as Feed5, Filter as Filter4, Obj as Obj10 } from "@dxos/echo";
|
|
1561
|
+
import { invariant as invariant3 } from "@dxos/invariant";
|
|
1562
|
+
import { log as log6 } from "@dxos/log";
|
|
1560
1563
|
import { McpToolkit } from "@dxos/mcp-client";
|
|
1564
|
+
import { Message as Message6 } from "@dxos/types";
|
|
1565
|
+
|
|
1566
|
+
// src/session/Harness.ts
|
|
1567
|
+
var Harness_exports = {};
|
|
1568
|
+
__export(Harness_exports, {
|
|
1569
|
+
HarnessService: () => HarnessService,
|
|
1570
|
+
NotSupportedError: () => NotSupportedError,
|
|
1571
|
+
bindContext: () => bindContext,
|
|
1572
|
+
binder: () => binder,
|
|
1573
|
+
enqueueMessage: () => enqueueMessage,
|
|
1574
|
+
fromBinder: () => fromBinder,
|
|
1575
|
+
history: () => history,
|
|
1576
|
+
layerSpec: () => layerSpec,
|
|
1577
|
+
make: () => make3,
|
|
1578
|
+
queryContext: () => queryContext,
|
|
1579
|
+
setAlarm: () => setAlarm
|
|
1580
|
+
});
|
|
1581
|
+
import * as Context3 from "effect/Context";
|
|
1582
|
+
import * as DateTime from "effect/DateTime";
|
|
1583
|
+
import * as Effect8 from "effect/Effect";
|
|
1584
|
+
import * as Layer3 from "effect/Layer";
|
|
1585
|
+
import * as Option4 from "effect/Option";
|
|
1586
|
+
import { LayerSpec, Process, ServiceNotAvailableError } from "@dxos/compute";
|
|
1587
|
+
import { ProcessManager } from "@dxos/compute-runtime";
|
|
1588
|
+
import { Annotation as Annotation2, Database as Database2, EID as EID4, Feed as Feed4, Filter as Filter3 } from "@dxos/echo";
|
|
1589
|
+
import { EffectEx } from "@dxos/effect";
|
|
1590
|
+
import { BaseError as BaseError2 } from "@dxos/errors";
|
|
1561
1591
|
import { Message as Message5 } from "@dxos/types";
|
|
1562
1592
|
|
|
1563
1593
|
// src/session/SessionLoader.ts
|
|
1564
|
-
import * as
|
|
1594
|
+
import * as Effect7 from "effect/Effect";
|
|
1565
1595
|
import { Feed as Feed3, Filter as Filter2, Obj as Obj8 } from "@dxos/echo";
|
|
1566
1596
|
import { Message as Message4 } from "@dxos/types";
|
|
1567
1597
|
|
|
@@ -1572,12 +1602,13 @@ __export(SessionLink_exports, {
|
|
|
1572
1602
|
});
|
|
1573
1603
|
import * as Schema6 from "effect/Schema";
|
|
1574
1604
|
import { DXN as DXN3, Feed as Feed2, Obj as Obj7, Ref as Ref4, Type as Type3 } from "@dxos/echo";
|
|
1575
|
-
var SessionLink = Schema6.Struct({
|
|
1605
|
+
var SessionLink = class extends Type3.makeObject(DXN3.make("org.dxos.type.sessionLink", "0.1.0"))(Schema6.Struct({
|
|
1576
1606
|
/** Reference to the feed of the source session. */
|
|
1577
1607
|
feedRef: Ref4.Ref(Feed2.Feed),
|
|
1578
1608
|
/** Messages from the source feed up to and including this message ID are injected. */
|
|
1579
1609
|
messageId: Obj7.ID
|
|
1580
|
-
})
|
|
1610
|
+
})) {
|
|
1611
|
+
};
|
|
1581
1612
|
|
|
1582
1613
|
// src/session/SessionLoader.ts
|
|
1583
1614
|
var SessionLoader = class {
|
|
@@ -1587,8 +1618,8 @@ var SessionLoader = class {
|
|
|
1587
1618
|
* the referenced feed up to and including `messageId` and prepends them.
|
|
1588
1619
|
*/
|
|
1589
1620
|
reifyHistory(feed, messages) {
|
|
1590
|
-
return
|
|
1591
|
-
const links = yield* Feed3.
|
|
1621
|
+
return Effect7.gen(function* () {
|
|
1622
|
+
const links = yield* Feed3.query(feed, Filter2.type(SessionLink)).run;
|
|
1592
1623
|
const sessionLinks = links.filter(Obj8.instanceOf(SessionLink));
|
|
1593
1624
|
const link = sessionLinks[0];
|
|
1594
1625
|
if (!link) {
|
|
@@ -1598,7 +1629,7 @@ var SessionLoader = class {
|
|
|
1598
1629
|
if (!sourceFeed) {
|
|
1599
1630
|
return messages;
|
|
1600
1631
|
}
|
|
1601
|
-
const sourceMessages = yield* Feed3.
|
|
1632
|
+
const sourceMessages = yield* Feed3.query(sourceFeed, Filter2.type(Message4.Message)).run;
|
|
1602
1633
|
const filtered = sourceMessages.filter(Obj8.instanceOf(Message4.Message));
|
|
1603
1634
|
const sorted = [
|
|
1604
1635
|
...filtered
|
|
@@ -1615,12 +1646,138 @@ var SessionLoader = class {
|
|
|
1615
1646
|
}
|
|
1616
1647
|
};
|
|
1617
1648
|
|
|
1649
|
+
// src/session/Harness.ts
|
|
1650
|
+
var HarnessService = class extends Context3.Tag("@dxos/assistant/HarnessService")() {
|
|
1651
|
+
};
|
|
1652
|
+
var binder = Effect8.flatMap(HarnessService, (service) => service.binder);
|
|
1653
|
+
var queryContext = (filter2) => Effect8.flatMap(HarnessService, (service) => service.queryContext(filter2));
|
|
1654
|
+
var history = Effect8.flatMap(HarnessService, (service) => service.history);
|
|
1655
|
+
var enqueueMessage = (options) => Effect8.flatMap(HarnessService, (service) => service.enqueueMessage(options));
|
|
1656
|
+
var setAlarm = (options) => Effect8.flatMap(HarnessService, (service) => service.setAlarm(options));
|
|
1657
|
+
var bindContext = ({ skills, objects }) => Effect8.gen(function* () {
|
|
1658
|
+
const sessionBinder = yield* binder;
|
|
1659
|
+
yield* Effect8.promise(() => sessionBinder.bind({
|
|
1660
|
+
skills,
|
|
1661
|
+
objects
|
|
1662
|
+
}));
|
|
1663
|
+
});
|
|
1664
|
+
var NotSupportedError = class extends BaseError2.extend("NotSupportedError", "Operation not supported") {
|
|
1665
|
+
};
|
|
1666
|
+
var layerSpec = LayerSpec.make({
|
|
1667
|
+
affinity: "process",
|
|
1668
|
+
requires: [
|
|
1669
|
+
Database2.Service,
|
|
1670
|
+
ProcessManager.Service
|
|
1671
|
+
],
|
|
1672
|
+
provides: [
|
|
1673
|
+
HarnessService
|
|
1674
|
+
]
|
|
1675
|
+
}, (context) => Layer3.scoped(HarnessService, Effect8.gen(function* () {
|
|
1676
|
+
if (!context.conversation) {
|
|
1677
|
+
return yield* Effect8.die(new ServiceNotAvailableError(HarnessService.key, {
|
|
1678
|
+
message: `Service not available: ${HarnessService.key} \u2014 process spawn is missing 'conversation' in environment (set via Operation.withInvocationOptions or ProcessManager.spawn environment)`
|
|
1679
|
+
}));
|
|
1680
|
+
}
|
|
1681
|
+
const conversation = context.conversation;
|
|
1682
|
+
const processManager = yield* ProcessManager.Service;
|
|
1683
|
+
const runtime2 = yield* Effect8.runtime();
|
|
1684
|
+
return yield* make3({
|
|
1685
|
+
conversation,
|
|
1686
|
+
processManager,
|
|
1687
|
+
runtime: runtime2
|
|
1688
|
+
});
|
|
1689
|
+
})));
|
|
1690
|
+
var make3 = ({ conversation, processManager, runtime: runtime2 }) => Effect8.gen(function* () {
|
|
1691
|
+
const feed = yield* Database2.resolve(EID4.parse(conversation), Feed4.Feed).pipe(Effect8.provide(runtime2), Effect8.orDie);
|
|
1692
|
+
const boundBinder = yield* EffectEx.acquireReleaseResource(() => new Binder({
|
|
1693
|
+
feed,
|
|
1694
|
+
runtime: runtime2
|
|
1695
|
+
}));
|
|
1696
|
+
return makeService({
|
|
1697
|
+
feed,
|
|
1698
|
+
runtime: runtime2,
|
|
1699
|
+
binder: boundBinder,
|
|
1700
|
+
owningHost: lookupOwningHost(processManager, conversation)
|
|
1701
|
+
});
|
|
1702
|
+
});
|
|
1703
|
+
var fromBinder = ({ feed, runtime: runtime2, binder: binder2 }) => makeService({
|
|
1704
|
+
feed,
|
|
1705
|
+
runtime: runtime2,
|
|
1706
|
+
binder: binder2,
|
|
1707
|
+
owningHost: Effect8.fail(new NotSupportedError())
|
|
1708
|
+
});
|
|
1709
|
+
var makeService = ({ feed, runtime: runtime2, binder: binder2, owningHost }) => ({
|
|
1710
|
+
binder: Effect8.succeed(binder2),
|
|
1711
|
+
history: Effect8.gen(function* () {
|
|
1712
|
+
const messages = yield* Feed4.query(feed, Filter3.type(Message5.Message)).run;
|
|
1713
|
+
return yield* new SessionLoader().reifyHistory(feed, messages);
|
|
1714
|
+
}).pipe(Effect8.provide(runtime2)),
|
|
1715
|
+
queryContext: (filter2) => Effect8.sync(() => {
|
|
1716
|
+
const match = Filter3.toPredicate(filter2);
|
|
1717
|
+
return binder2.getObjects().filter(match);
|
|
1718
|
+
}),
|
|
1719
|
+
enqueueMessage: ({ content }) => owningHost.pipe(Effect8.flatMap((rpc) => rpc.enqueueMessage({
|
|
1720
|
+
content
|
|
1721
|
+
}))),
|
|
1722
|
+
setAlarm: ({ at, message }) => owningHost.pipe(Effect8.flatMap((rpc) => rpc.setAlarm({
|
|
1723
|
+
at: DateTime.toUtc(at),
|
|
1724
|
+
message
|
|
1725
|
+
})))
|
|
1726
|
+
});
|
|
1727
|
+
var lookupOwningHost = (processManager, conversation) => Effect8.gen(function* () {
|
|
1728
|
+
const processes = yield* processManager.list({
|
|
1729
|
+
target: conversation
|
|
1730
|
+
});
|
|
1731
|
+
const host = processes.find((process) => !isTerminalProcess(process.status.state) && Option4.getOrElse(Annotation2.getDictionary(process.params.annotations, Process.HarnessHostAnnotation), () => false));
|
|
1732
|
+
if (!host) {
|
|
1733
|
+
return yield* Effect8.fail(new NotSupportedError());
|
|
1734
|
+
}
|
|
1735
|
+
return host.rpc;
|
|
1736
|
+
});
|
|
1737
|
+
var isTerminalProcess = (state) => state === Process.State.SUCCEEDED || state === Process.State.FAILED || state === Process.State.TERMINATED;
|
|
1738
|
+
|
|
1739
|
+
// src/session/SkillHooks.ts
|
|
1740
|
+
var SkillHooks_exports = {};
|
|
1741
|
+
__export(SkillHooks_exports, {
|
|
1742
|
+
runHooks: () => runHooks
|
|
1743
|
+
});
|
|
1744
|
+
import * as Effect9 from "effect/Effect";
|
|
1745
|
+
import { Operation as Operation2, Skill as Skill2 } from "@dxos/compute";
|
|
1746
|
+
import { Database as Database3, Obj as Obj9 } from "@dxos/echo";
|
|
1747
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
1748
|
+
import { log as log5 } from "@dxos/log";
|
|
1749
|
+
var __dxlog_file6 = "/__w/dxos/dxos/packages/core/compute/assistant/src/session/SkillHooks.ts";
|
|
1750
|
+
var runHooks = ({ skills, phase, invoke }) => Effect9.gen(function* () {
|
|
1751
|
+
for (const skill of skills) {
|
|
1752
|
+
for (const hook of skill.hooks ?? []) {
|
|
1753
|
+
if (hook.spec._tag !== phase) {
|
|
1754
|
+
continue;
|
|
1755
|
+
}
|
|
1756
|
+
if (!hook.function) {
|
|
1757
|
+
continue;
|
|
1758
|
+
}
|
|
1759
|
+
yield* Effect9.gen(function* () {
|
|
1760
|
+
const record = yield* Database3.load(hook.function);
|
|
1761
|
+
invariant2(Obj9.instanceOf(Operation2.PersistentOperation, record), "Hook function must be an operation.", { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 28, S: this, A: ["Obj.instanceOf(Operation.PersistentOperation, record)", "'Hook function must be an operation.'"] });
|
|
1762
|
+
const operation = Operation2.deserialize(record);
|
|
1763
|
+
yield* invoke(operation, {
|
|
1764
|
+
...hook.input
|
|
1765
|
+
});
|
|
1766
|
+
}).pipe(Effect9.catchAllCause((cause) => Effect9.sync(() => log5.warn("skill hook failed", {
|
|
1767
|
+
phase,
|
|
1768
|
+
skill: Skill2.getKey(skill),
|
|
1769
|
+
cause
|
|
1770
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 35, S: this }))));
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
});
|
|
1774
|
+
|
|
1618
1775
|
// src/session/AiSession.ts
|
|
1619
|
-
var
|
|
1776
|
+
var __dxlog_file7 = "/__w/dxos/dxos/packages/core/compute/assistant/src/session/AiSession.ts";
|
|
1620
1777
|
var SUMMARY_THRESHOLD = 8e4;
|
|
1621
1778
|
var Session = class extends Resource2 {
|
|
1622
1779
|
/**
|
|
1623
|
-
*
|
|
1780
|
+
* Skills and objects bound to the session.
|
|
1624
1781
|
*/
|
|
1625
1782
|
_binder;
|
|
1626
1783
|
_feed;
|
|
@@ -1630,8 +1787,8 @@ var Session = class extends Resource2 {
|
|
|
1630
1787
|
super();
|
|
1631
1788
|
this._feed = options.feed;
|
|
1632
1789
|
this._runtime = options.runtime;
|
|
1633
|
-
|
|
1634
|
-
|
|
1790
|
+
invariant3(this._feed, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 45, S: this, A: ["this._feed", ""] });
|
|
1791
|
+
invariant3(this._runtime, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 46, S: this, A: ["this._runtime", ""] });
|
|
1635
1792
|
this._binder = new Binder({
|
|
1636
1793
|
feed: this._feed,
|
|
1637
1794
|
runtime: this._runtime,
|
|
@@ -1648,133 +1805,116 @@ var Session = class extends Resource2 {
|
|
|
1648
1805
|
return this._binder;
|
|
1649
1806
|
}
|
|
1650
1807
|
async getHistory() {
|
|
1651
|
-
const queryResult = await Runtime2.runPromise(this._runtime)(
|
|
1808
|
+
const queryResult = await Runtime2.runPromise(this._runtime)(Feed5.query(this._feed, Filter4.type(Message6.Message)));
|
|
1652
1809
|
const items = await queryResult.run();
|
|
1653
|
-
const messages = items.filter(
|
|
1810
|
+
const messages = items.filter(Obj10.instanceOf(Message6.Message));
|
|
1654
1811
|
return Runtime2.runPromise(this._runtime)(this._sessionLoader.reifyHistory(this._feed, messages));
|
|
1655
1812
|
}
|
|
1656
1813
|
getTools() {
|
|
1657
|
-
return
|
|
1814
|
+
return Effect10.gen(this, function* () {
|
|
1658
1815
|
const toolkit = yield* createToolkit({
|
|
1659
|
-
|
|
1816
|
+
skills: this.context.getSkills()
|
|
1660
1817
|
});
|
|
1661
1818
|
return toolkit.toolkit.tools;
|
|
1662
|
-
}).pipe(
|
|
1819
|
+
}).pipe(Effect10.orDie);
|
|
1663
1820
|
}
|
|
1664
1821
|
/**
|
|
1665
1822
|
* Not provided by default, since users might want to override them.
|
|
1666
1823
|
*/
|
|
1667
1824
|
makeToolExecutionServices() {
|
|
1668
|
-
return ToolExecutionServices.pipe(
|
|
1669
|
-
conversation:
|
|
1825
|
+
return ToolExecutionServices.pipe(Layer4.provide(Operation3.withInvocationOptions({
|
|
1826
|
+
conversation: Obj10.getURI(this._feed)
|
|
1670
1827
|
})));
|
|
1671
1828
|
}
|
|
1672
1829
|
/**
|
|
1673
1830
|
* Creates a new cancelable request effect.
|
|
1674
1831
|
*/
|
|
1675
1832
|
createRequest(params) {
|
|
1676
|
-
return
|
|
1677
|
-
const
|
|
1678
|
-
const
|
|
1833
|
+
return Effect10.gen(this, function* () {
|
|
1834
|
+
const history2 = yield* Effect10.promise(() => this.getHistory());
|
|
1835
|
+
const skills = this.context.getSkills();
|
|
1679
1836
|
const objects = this.context.getObjects();
|
|
1680
|
-
|
|
1681
|
-
history:
|
|
1682
|
-
|
|
1837
|
+
log6("run", {
|
|
1838
|
+
history: history2.length,
|
|
1839
|
+
skills: skills.length,
|
|
1683
1840
|
objects: objects.length
|
|
1684
|
-
}, { "~LogMeta": "~LogMeta", F:
|
|
1841
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 90, S: this });
|
|
1685
1842
|
const request = new AiRequest_exports.Request({
|
|
1686
1843
|
summarizationThreshold: SUMMARY_THRESHOLD,
|
|
1687
1844
|
observer: params.observer,
|
|
1688
|
-
|
|
1845
|
+
persist: params.persist,
|
|
1846
|
+
onOutput: (message) => Effect10.promise(() => Runtime2.runPromise(this._runtime)(Feed5.append(this._feed, [
|
|
1689
1847
|
message
|
|
1690
1848
|
])))
|
|
1691
1849
|
});
|
|
1692
1850
|
yield* request.begin({
|
|
1693
|
-
history,
|
|
1694
|
-
|
|
1851
|
+
history: history2,
|
|
1852
|
+
skills,
|
|
1695
1853
|
objects,
|
|
1696
1854
|
prompt: params.prompt,
|
|
1697
1855
|
system: params.system
|
|
1698
1856
|
});
|
|
1857
|
+
yield* runHooks({
|
|
1858
|
+
skills,
|
|
1859
|
+
phase: "begin-request",
|
|
1860
|
+
invoke: (operation, input) => Operation3.invoke(operation, input).pipe(Effect10.asVoid, Effect10.orDie)
|
|
1861
|
+
});
|
|
1699
1862
|
do {
|
|
1700
|
-
yield*
|
|
1701
|
-
const
|
|
1702
|
-
const mcps = yield* connectMcpServers(
|
|
1863
|
+
yield* Effect10.promise(() => this.context.sync());
|
|
1864
|
+
const currentSkills = this.context.getSkills();
|
|
1865
|
+
const mcps = yield* connectMcpServers(currentSkills, params.mcpServers);
|
|
1703
1866
|
const toolkit = yield* createToolkit({
|
|
1704
1867
|
toolkit: params.toolkit,
|
|
1705
|
-
|
|
1868
|
+
skills: currentSkills,
|
|
1706
1869
|
opaqueToolkits: mcps
|
|
1707
1870
|
});
|
|
1708
|
-
|
|
1871
|
+
log6("toolkit", {
|
|
1709
1872
|
tools: Record2.keys(toolkit.toolkit.tools)
|
|
1710
|
-
}, { "~LogMeta": "~LogMeta", F:
|
|
1873
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 127, S: this });
|
|
1711
1874
|
const system = yield* formatSystemPrompt({
|
|
1712
1875
|
system: params.system,
|
|
1713
|
-
|
|
1876
|
+
skills: currentSkills,
|
|
1714
1877
|
objects: this.context.getObjects()
|
|
1715
|
-
}).pipe(
|
|
1716
|
-
const { done } = yield* request.runAgentTurn({
|
|
1878
|
+
}).pipe(Effect10.orDie);
|
|
1879
|
+
const { done, finishReason } = yield* request.runAgentTurn({
|
|
1717
1880
|
system,
|
|
1718
1881
|
toolkit
|
|
1719
1882
|
});
|
|
1720
1883
|
if (done) {
|
|
1721
1884
|
break;
|
|
1722
1885
|
}
|
|
1886
|
+
if (finishReason === "pause") {
|
|
1887
|
+
continue;
|
|
1888
|
+
}
|
|
1723
1889
|
yield* request.runTools({
|
|
1724
1890
|
toolkit
|
|
1725
1891
|
});
|
|
1726
1892
|
} while (true);
|
|
1727
|
-
|
|
1893
|
+
log6("result", {
|
|
1728
1894
|
messages: request.pending.length,
|
|
1729
1895
|
duration: request.duration,
|
|
1730
1896
|
toolCalls: request.toolCalls
|
|
1731
|
-
}, { "~LogMeta": "~LogMeta", F:
|
|
1897
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 151, S: this });
|
|
1732
1898
|
return [
|
|
1733
1899
|
...request.pending
|
|
1734
1900
|
];
|
|
1735
|
-
}).pipe(
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1901
|
+
}).pipe(Effect10.provide(Layer4.mergeAll(
|
|
1902
|
+
// Tier A only: the agent's own turn fiber has no `ProcessManager.Service` in scope, so
|
|
1903
|
+
// Tier B (setAlarm/enqueueMessage) is reachable only by child operations through the
|
|
1904
|
+
// process-affinity HarnessService LayerSpec — not from here.
|
|
1905
|
+
Layer4.succeed(HarnessService, fromBinder({
|
|
1906
|
+
feed: this._feed,
|
|
1907
|
+
runtime: this._runtime,
|
|
1908
|
+
binder: this.context
|
|
1909
|
+
})),
|
|
1910
|
+
Operation3.withInvocationOptions({
|
|
1911
|
+
conversation: Obj10.getURI(this._feed)
|
|
1912
|
+
})
|
|
1913
|
+
)), Effect10.withSpan("AiSession.createRequest"));
|
|
1740
1914
|
}
|
|
1741
1915
|
};
|
|
1742
|
-
var
|
|
1743
|
-
|
|
1744
|
-
* Create a new session layer from options.
|
|
1745
|
-
*/
|
|
1746
|
-
static layer = (options) => aiContextFromSession.pipe(Layer3.provideMerge(Layer3.scoped(_Service, Effect9.gen(function* () {
|
|
1747
|
-
const session = yield* EffectEx.acquireReleaseResource(() => new Session(options));
|
|
1748
|
-
return session;
|
|
1749
|
-
}))));
|
|
1750
|
-
/**
|
|
1751
|
-
* Create a new session with a new feed.
|
|
1752
|
-
*/
|
|
1753
|
-
static layerNewFeed = (options) => Layer3.unwrapScoped(Effect9.gen(function* () {
|
|
1754
|
-
const feed = yield* Database2.add(Feed4.make());
|
|
1755
|
-
const runtime2 = yield* Effect9.runtime();
|
|
1756
|
-
return _Service.layer({
|
|
1757
|
-
...options,
|
|
1758
|
-
feed,
|
|
1759
|
-
runtime: runtime2
|
|
1760
|
-
});
|
|
1761
|
-
}));
|
|
1762
|
-
/**
|
|
1763
|
-
* Run a prompt in the current session.
|
|
1764
|
-
*/
|
|
1765
|
-
static run = (params) => Effect9.gen(function* () {
|
|
1766
|
-
const session = yield* _Service;
|
|
1767
|
-
return yield* session.createRequest(params);
|
|
1768
|
-
});
|
|
1769
|
-
};
|
|
1770
|
-
var aiContextFromSession = Layer3.effect(Service, Effect9.gen(function* () {
|
|
1771
|
-
const session = yield* Service2;
|
|
1772
|
-
return {
|
|
1773
|
-
binder: session.context
|
|
1774
|
-
};
|
|
1775
|
-
}));
|
|
1776
|
-
var connectMcpServers = (blueprints, spaceMcpServers = []) => {
|
|
1777
|
-
const blueprintServers = pipe4(blueprints, Array4.flatMap((_) => _.mcpServers ?? []), Array4.map(({ url, protocol, apiKey }) => ({
|
|
1916
|
+
var connectMcpServers = (skills, spaceMcpServers = []) => {
|
|
1917
|
+
const skillServers = pipe4(skills, Array4.flatMap((_) => _.mcpServers ?? []), Array4.map(({ url, protocol, apiKey }) => ({
|
|
1778
1918
|
url,
|
|
1779
1919
|
protocol,
|
|
1780
1920
|
apiKey
|
|
@@ -1785,22 +1925,22 @@ var connectMcpServers = (blueprints, spaceMcpServers = []) => {
|
|
|
1785
1925
|
apiKey
|
|
1786
1926
|
}));
|
|
1787
1927
|
const allServers = [
|
|
1788
|
-
...
|
|
1928
|
+
...skillServers,
|
|
1789
1929
|
...spaceServers
|
|
1790
1930
|
];
|
|
1791
|
-
return pipe4(allServers,
|
|
1931
|
+
return pipe4(allServers, Effect10.forEach((options) => McpToolkit.make(options).pipe(
|
|
1792
1932
|
// NOTE: Type-inference fails here without explicit void return.
|
|
1793
|
-
|
|
1933
|
+
Effect10.tap((toolkit) => log6.info("Connected to MCP server", {
|
|
1794
1934
|
url: options.url,
|
|
1795
1935
|
tools: Object.keys(toolkit.toolkit.tools).length
|
|
1796
|
-
}, { "~LogMeta": "~LogMeta", F:
|
|
1936
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 187, S: void 0 })),
|
|
1797
1937
|
// Surface typed connection failures via ephemeral trace + warn log, then drop the server.
|
|
1798
|
-
|
|
1799
|
-
|
|
1938
|
+
Effect10.tapError((error) => Effect10.gen(function* () {
|
|
1939
|
+
log6.warn("Failed to connect to MCP server", {
|
|
1800
1940
|
url: error.url,
|
|
1801
1941
|
protocol: error.protocol,
|
|
1802
1942
|
message: error.message
|
|
1803
|
-
}, { "~LogMeta": "~LogMeta", F:
|
|
1943
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 192, S: this });
|
|
1804
1944
|
yield* Trace3.write(McpServerError, {
|
|
1805
1945
|
url: error.url,
|
|
1806
1946
|
protocol: error.protocol,
|
|
@@ -1809,36 +1949,54 @@ var connectMcpServers = (blueprints, spaceMcpServers = []) => {
|
|
|
1809
1949
|
})),
|
|
1810
1950
|
// Catch unexpected defects too (e.g. malformed tool schemas) so a single broken
|
|
1811
1951
|
// server can never abort the whole turn — surface them through the same channel.
|
|
1812
|
-
|
|
1952
|
+
Effect10.catchAllDefect((defect) => Effect10.gen(function* () {
|
|
1813
1953
|
const message = defect instanceof Error ? defect.message : String(defect);
|
|
1814
|
-
|
|
1954
|
+
log6.warn("Unexpected MCP defect", {
|
|
1815
1955
|
url: options.url,
|
|
1816
1956
|
message
|
|
1817
|
-
}, { "~LogMeta": "~LogMeta", F:
|
|
1957
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 206, S: this });
|
|
1818
1958
|
yield* Trace3.write(McpServerError, {
|
|
1819
1959
|
url: options.url,
|
|
1820
1960
|
protocol: options.protocol,
|
|
1821
1961
|
message: `Unexpected MCP failure: ${message}`
|
|
1822
1962
|
});
|
|
1823
|
-
return yield*
|
|
1963
|
+
return yield* Effect10.fail(new McpToolkit.McpConnectionError({
|
|
1824
1964
|
url: options.url,
|
|
1825
1965
|
protocol: options.protocol,
|
|
1826
1966
|
message
|
|
1827
1967
|
}));
|
|
1828
1968
|
})),
|
|
1829
|
-
|
|
1830
|
-
)),
|
|
1969
|
+
Effect10.either
|
|
1970
|
+
)), Effect10.map(Array4.filterMap((_) => Either.getRight(_))));
|
|
1831
1971
|
};
|
|
1832
1972
|
|
|
1973
|
+
// src/session/harness-control.ts
|
|
1974
|
+
import * as Rpc from "@effect/rpc/Rpc";
|
|
1975
|
+
import * as RpcGroup from "@effect/rpc/RpcGroup";
|
|
1976
|
+
import * as Schema7 from "effect/Schema";
|
|
1977
|
+
import { ContentBlock as ContentBlock4 } from "@dxos/types";
|
|
1978
|
+
var HarnessControl = RpcGroup.make(Rpc.make("setAlarm", {
|
|
1979
|
+
payload: Schema7.Struct({
|
|
1980
|
+
at: Schema7.DateTimeUtc,
|
|
1981
|
+
message: Schema7.NullOr(Schema7.String)
|
|
1982
|
+
}),
|
|
1983
|
+
success: Schema7.Void
|
|
1984
|
+
}), Rpc.make("enqueueMessage", {
|
|
1985
|
+
payload: Schema7.Struct({
|
|
1986
|
+
content: Schema7.Array(ContentBlock4.Any)
|
|
1987
|
+
}),
|
|
1988
|
+
success: Schema7.Void
|
|
1989
|
+
}));
|
|
1990
|
+
|
|
1833
1991
|
// src/templates/system.ts
|
|
1834
1992
|
import defaultsDeep from "lodash.defaultsdeep";
|
|
1835
1993
|
import { Template as Template2 } from "@dxos/compute";
|
|
1836
1994
|
|
|
1837
|
-
// raw-loader:/__w/dxos/dxos/packages/core/compute/assistant/src/templates/instructions/format.tpl
|
|
1838
|
-
var format_default = "{{! System Core }}\n\n## Input Formats\n\n###
|
|
1995
|
+
// raw-loader:/__w/dxos/dxos/packages/core/compute/assistant/src/templates/instructions/format.tpl
|
|
1996
|
+
var format_default = "{{! System Core }}\n\n## Input Formats\n\n### Skills\n\nYou may be provided with Skill definitions that include specific instructions and tools for a given set of tasks.\nBlue print instructions will be enclosed in a <skill> tag.\n\n### Context objects\n\nYou may be provided with references to objects that are relevant to the current prompt.\nObjects will be in the form of a <object> tag with a <dxn> element that is the unique key of the object required by many tools.\nThe <typename> element is the type of the object.\n\n<object>\n <dxn>object-id</dxn>\n <typename>example.com/type/TypeName</typename>\n</object>\n\n## Response Formats\n\nIt is very important to respond in the correct format.\nYou response must be valid Markdown.\nIn some cases you should respond with well-formed XML tags along with the content.\nCode snippets should use 2-space indents.\n\n{{#if cot}}\nBefore responding, explain your reasoning and include your detailed chain-of-thought enclosed in a <cot> tag.\nThe <cot> tag should be the first thing in your response.\n{{/if}}\n\n## Block references\n\nYou can reply with a block reference for objects if you have the DXN. For example:\n\n<object>\n <dxn>dxn:queue:data:B6INSIBY3CBEF4M5VZRYBCMAHQMPYK5AJ:01K24XMVHSZHS97SG1VTVQDM5Z:01K24XPK464FSCKVQJAB2H662M</dxn>\n</object>\n<object>\n <dxn>dxn:echo:@:01K24XPK464FSCKVQJAB2H662M</dxn>\n</object>\n\n### Suggestions\n\nEach suggestion must in the form of a proposed action enclosed in a <suggestion> tag.\nExample: <suggestion>Show on a map</suggestion>\nDo not use bullets when listing suggestions.\n\n### Multiple choice questions\n\nYou may ask multiple choice questions by wrapping consise options inside <option> tags inside a well formed <select> tag.\nExample: <select><option>Yes</option><option>No</option></select>\n\n## Context\n\nThe current date and time is {{DATETIME}}.\n";
|
|
1839
1997
|
|
|
1840
|
-
// raw-loader:/__w/dxos/dxos/packages/core/compute/assistant/src/templates/instructions/system.tpl
|
|
1841
|
-
var system_default = "{{! System Prompt }}\n\n- You are a helpful assistant called Kai. \n- Your name is Kai and you are powered by different language models.\n- You were created by DXOS and operate inside of Composer and on the DXOS EDGE network.\n- In your initial greeting state your name and make some suggestions based on the current context objects.\n- You are an advanced AI assistant capable of creating and managing artifacts from provided data and tools.\n- Your task is to process user commands and questions and decide how best to respond.\n- In general be concise and direct.\n- Follow all instructions carefully.\n\n## Planning\n\n- Analyze the structure and type of the content in the user's message.\n- Determine if you complete the task using the available
|
|
1998
|
+
// raw-loader:/__w/dxos/dxos/packages/core/compute/assistant/src/templates/instructions/system.tpl
|
|
1999
|
+
var system_default = "{{! System Prompt }}\n\n- You are a helpful assistant called Kai. \n- Your name is Kai and you are powered by different language models.\n- You were created by DXOS and operate inside of Composer and on the DXOS EDGE network.\n- In your initial greeting state your name and make some suggestions based on the current context objects.\n- You are an advanced AI assistant capable of creating and managing artifacts from provided data and tools.\n- Your task is to process user commands and questions and decide how best to respond.\n- In general be concise and direct.\n- Follow all instructions carefully.\n\n## Planning\n\n- Analyze the structure and type of the content in the user's message.\n- Determine if you complete the task using the available skill definitions?\n- If you can't complete the task using the available skill definitions, query the list of available skill definitions using the appropriate tool.\n- Identify which skill definitions are relevant to the user's request.\n- Evaluate the potential benefits of creating an artifact vs. normal processing for each identified element.\n- Make a final decision on whether to create an artifact and explain your reasoning.\n- Are the required skill definitions already available?\n- If not, select which skill definition(s) will be the most relevant and require them using the require_artifact_definitions tool.\n- The require'd artifact tools will be available for use after require.\n- If creating an artifact, outline how you will structure it within the response.\n- Decide if the artifact needs to be shown to the user.\n- Call the show tool to show the artifact to the user.\n- Your reasoning must include: whether to use artifacts or not, to create one or query, whether to show the artifact to the user, and how to structure the response.\n\n## Skills and Artifacts\n\n- Determine if the interaction involves an artifact. Prefer artifacts for tables, lists, spreadsheets, kanbans, games, images, and other structured data.\n- Determine if the user is explicitly talking about creating a new artifact, or wants to use an existing artifact.\n- If it is ambiguous, query for existing artifacts first and then decide.\n- If you decide to create an artifact, call the associated tool to create the artifact.\n- Artifacts are stored in the database. Tools are used to create and query artifacts.\n- If you are unsure about creating an artifact ask the user for clarification.\n- Artifacts are mutable objects that can change over the course of the conversation.\n- Always re-query the artifact using the tool (like query or inspect) to get the latest state of the artifact before answering the user.\n- You must never generate the id of the artifact; only recall the ids that are already in the history.\n- Artifacts are created by requiring the specific artifact using the require_artifact tool and creating it by calling the associated tool.\n- You can add suggested actions at the end of your response.\n- Suggested actions should be very concise and start with a verb and be phrased as a command to an agent -- not a question to the user.\n- Suggested actions must be in the form of a user instruction that you can follow.\n- Suggested actions could include actions that create artifacts.\n- After creating an artifact use a tool to add it to the chat context.\n\n## Navigation\n\n- When the user asks to open, go to, navigate to, or show a specific document, page, or object, use the navigation tools instead of loading content inline. Navigation is always two steps: first resolve a navigation path with Resolve navigation targets, then open that path with Open.\n- The Open tool accepts navigation **paths** only. Never pass an object DXN, URI, or id to Open \u2014 pass only a `path` returned by Resolve navigation targets. Passing anything else will fail to navigate.\n- To open a specific object: call Resolve navigation targets with the object's URI in the `query.uri` field \u2014 use the value from the object's `<dxn>` tag in context (which may be an `echo:` EID or a `dxn:` DXN), then pass the returned target's `path` to Open.\n- To navigate to a page (not a specific object): call Resolve navigation targets without arguments to list the available pages, then pass the chosen target's `path` to Open.\n- Do not respond with the document's content when the user asks to open it \u2014 open it in the main content area instead.\n- If multiple targets match, present the options to the user and let them choose which to open.\n\n## Response format\n\n- NEVER output narration text outside `<status>` tags or the final user-facing answer. Any progress update, transition sentence, or \"let me\u2026\" lead-in MUST be wrapped in `<status>...</status>`. Violating this is an error.\n- When updating the user about the progress of the work you are doing, put the update in a <status> XML tag.\n- Only when you need to show the result to the user or ask a question use a text block without status tags.\n- After a `</status>` tag, the next output must be either another `<status>` tag, a tool call, or the final user-facing answer \u2014 never a transition sentence.\n\n<example>\n// reasoning...\n<status>Looking for emails from Depot</status>\n// tool call..\n<status>Found 2 emails from Depot.</status>\n<status>Loading email details</status>\n// tool call\n<status>Located mailbox</status>\nI found **2 emails from Depot**:\n</example>\n\nDo not do (no status tags):\n\n<incorrect_example>\n// reasoning...\n// tool call..\nI found 2 emails from Depot. Let me load their details:\n// tool call\nI found **2 emails from Depot**:\n</incorrect_example>\n\nDo not do (transition sentence after a status tag, before tool calls):\n\n<incorrect_example>\n<status>Doing X</status>\nLet me start by doing X:\n// tool call\n</incorrect_example>\n\n- NEVER write a lead-in sentence before a tool call. Use a `<status>` tag instead.\n- Avoid using plain text to tell the user what you are about to do; instead, use status blocks.\n- WRONG: Let me get...\n- CORRECT: <status>Getting...</status>";
|
|
1842
2000
|
|
|
1843
2001
|
// src/templates/system.ts
|
|
1844
2002
|
var createSystemPrompt = (options = {}) => Template2.process(format_default, defaultsDeep(options, {
|
|
@@ -1862,11 +2020,14 @@ export {
|
|
|
1862
2020
|
CompleteBlock,
|
|
1863
2021
|
ExecutionGraph,
|
|
1864
2022
|
GenerationObserver,
|
|
2023
|
+
Harness_exports as Harness,
|
|
2024
|
+
HarnessControl,
|
|
1865
2025
|
McpServerError,
|
|
1866
2026
|
PartialBlock,
|
|
1867
2027
|
RefFromLLM,
|
|
1868
2028
|
SessionLink_exports as SessionLink,
|
|
1869
2029
|
SessionLoader,
|
|
2030
|
+
SkillHooks_exports as SkillHooks,
|
|
1870
2031
|
ToolExecutionServices,
|
|
1871
2032
|
applyDiffs,
|
|
1872
2033
|
computeDiffsWithCursors,
|