@dxos/assistant 0.9.1-main.c7dcc2e112 → 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 +1 -1
- package/dist/lib/neutral/extraction/index.mjs.map +1 -1
- package/dist/lib/neutral/index.mjs +387 -230
- 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/proper-noun-extraction.d.ts +1 -202
- package/dist/types/src/extraction/extraction-llm-function/proper-noun-extraction.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 +13 -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 +5 -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/proper-noun-extraction.ts +1 -1
- package/src/index.ts +1 -1
- package/src/request/AiRequest.ts +35 -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 +43 -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/functions/index.d.ts.map +0 -1
- package/dist/types/src/functions/services.d.ts.map +0 -1
- /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()
|
|
@@ -976,15 +980,15 @@ var Request = class {
|
|
|
976
980
|
* Initialize a session: set up history, perform summarization if needed, and submit the user prompt.
|
|
977
981
|
* Must be called before `runTurn()`.
|
|
978
982
|
*/
|
|
979
|
-
begin = ({ prompt, system, history = [],
|
|
983
|
+
begin = ({ prompt, system, history: history2 = [], skills = [], objects = [] }) => Effect5.gen(this, function* () {
|
|
980
984
|
this._started = Date.now();
|
|
981
985
|
this._history = [
|
|
982
|
-
...
|
|
986
|
+
...history2
|
|
983
987
|
];
|
|
984
988
|
this._pending = [];
|
|
985
989
|
const systemPrompt = yield* formatSystemPrompt({
|
|
986
990
|
system,
|
|
987
|
-
|
|
991
|
+
skills,
|
|
988
992
|
objects
|
|
989
993
|
}).pipe(Effect5.orDie);
|
|
990
994
|
if (this._options.summarizationThreshold !== void 0) {
|
|
@@ -1002,12 +1006,12 @@ var Request = class {
|
|
|
1002
1006
|
}
|
|
1003
1007
|
yield* this._submitMessage(yield* formatUserPrompt({
|
|
1004
1008
|
prompt,
|
|
1005
|
-
history
|
|
1009
|
+
history: history2
|
|
1006
1010
|
}));
|
|
1007
1011
|
}).pipe(Effect5.withSpan("AiRequest.begin"));
|
|
1008
1012
|
/**
|
|
1009
1013
|
* Execute a single turn: one LLM generation followed by tool execution.
|
|
1010
|
-
* 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).
|
|
1011
1015
|
*/
|
|
1012
1016
|
runAgentTurn = ({ system, toolkit: opaqueToolkit }) => Effect5.gen(this, function* () {
|
|
1013
1017
|
log3("request", {
|
|
@@ -1028,6 +1032,7 @@ var Request = class {
|
|
|
1028
1032
|
const toolkit = opaqueToolkit ? yield* opaqueToolkit.handlers : void 0;
|
|
1029
1033
|
const observer = this._observer;
|
|
1030
1034
|
let currentMessageId = null;
|
|
1035
|
+
let finishReason;
|
|
1031
1036
|
const messages = yield* LanguageModel.streamText({
|
|
1032
1037
|
prompt,
|
|
1033
1038
|
toolkit,
|
|
@@ -1039,12 +1044,15 @@ var Request = class {
|
|
|
1039
1044
|
onPart: (part) => observer.onPart(part),
|
|
1040
1045
|
onEnd: (summary) => observer.onEnd(summary)
|
|
1041
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
|
+
}
|
|
1042
1050
|
if (block.pending) {
|
|
1043
1051
|
currentMessageId ??= Obj5.ID.random();
|
|
1044
1052
|
log3("emit ephemeral message", {
|
|
1045
1053
|
id: currentMessageId,
|
|
1046
1054
|
type: block._tag
|
|
1047
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L:
|
|
1055
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 154, S: this });
|
|
1048
1056
|
yield* Trace2.write(PartialBlock, {
|
|
1049
1057
|
messageId: currentMessageId,
|
|
1050
1058
|
role: "assistant",
|
|
@@ -1058,7 +1066,7 @@ var Request = class {
|
|
|
1058
1066
|
log3("emit complete message", {
|
|
1059
1067
|
id,
|
|
1060
1068
|
type: block._tag
|
|
1061
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L:
|
|
1069
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 168, S: this });
|
|
1062
1070
|
const message = Obj5.make(Message3.Message, {
|
|
1063
1071
|
id,
|
|
1064
1072
|
created: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -1077,20 +1085,29 @@ var Request = class {
|
|
|
1077
1085
|
}), Stream.filterMap((_) => _), Stream.runCollect, Effect5.map(Chunk.toArray));
|
|
1078
1086
|
log3("messages", {
|
|
1079
1087
|
messages
|
|
1080
|
-
}, { "~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
|
+
}
|
|
1081
1096
|
const toolCalls = this.getToolCalls();
|
|
1082
1097
|
if (toolCalls.length === 0) {
|
|
1083
1098
|
this._ended = Date.now();
|
|
1084
1099
|
return {
|
|
1085
1100
|
messages,
|
|
1086
|
-
done: true
|
|
1101
|
+
done: true,
|
|
1102
|
+
finishReason
|
|
1087
1103
|
};
|
|
1088
1104
|
} else if (!toolkit) {
|
|
1089
1105
|
throw new Error("No toolkit provided");
|
|
1090
1106
|
}
|
|
1091
1107
|
return {
|
|
1092
1108
|
messages,
|
|
1093
|
-
done: false
|
|
1109
|
+
done: false,
|
|
1110
|
+
finishReason
|
|
1094
1111
|
};
|
|
1095
1112
|
}).pipe(Effect5.withSpan("AiRequest.runAgentTurn"));
|
|
1096
1113
|
runTools = ({ toolkit: opaqueToolkit }) => Effect5.gen(this, function* () {
|
|
@@ -1114,27 +1131,30 @@ var Request = class {
|
|
|
1114
1131
|
/**
|
|
1115
1132
|
* Run a full conversation turn loop. Equivalent to calling `begin()` then `runTurn()` in a loop.
|
|
1116
1133
|
*/
|
|
1117
|
-
run = ({ prompt, system: systemTemplate, history = [], objects = [],
|
|
1134
|
+
run = ({ prompt, system: systemTemplate, history: history2 = [], objects = [], skills = [], toolkit }) => Effect5.gen(this, function* () {
|
|
1118
1135
|
yield* this.begin({
|
|
1119
1136
|
prompt,
|
|
1120
1137
|
system: systemTemplate,
|
|
1121
|
-
history,
|
|
1138
|
+
history: history2,
|
|
1122
1139
|
objects,
|
|
1123
|
-
|
|
1140
|
+
skills
|
|
1124
1141
|
});
|
|
1125
1142
|
const system = yield* formatSystemPrompt({
|
|
1126
1143
|
system: systemTemplate,
|
|
1127
|
-
|
|
1144
|
+
skills,
|
|
1128
1145
|
objects
|
|
1129
1146
|
}).pipe(Effect5.orDie);
|
|
1130
1147
|
do {
|
|
1131
|
-
const { done } = yield* this.runAgentTurn({
|
|
1148
|
+
const { done, finishReason } = yield* this.runAgentTurn({
|
|
1132
1149
|
system,
|
|
1133
1150
|
toolkit
|
|
1134
1151
|
});
|
|
1135
1152
|
if (done) {
|
|
1136
1153
|
break;
|
|
1137
1154
|
}
|
|
1155
|
+
if (finishReason === "pause") {
|
|
1156
|
+
continue;
|
|
1157
|
+
}
|
|
1138
1158
|
yield* this.runTools({
|
|
1139
1159
|
toolkit
|
|
1140
1160
|
});
|
|
@@ -1143,7 +1163,7 @@ var Request = class {
|
|
|
1143
1163
|
pending: this._pending.length,
|
|
1144
1164
|
duration: this.duration,
|
|
1145
1165
|
tools: this._toolCalls
|
|
1146
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L:
|
|
1166
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 267, S: this });
|
|
1147
1167
|
return this._pending;
|
|
1148
1168
|
}).pipe(this._semaphore.withPermits(1), Effect5.withSpan("AiRequest.run"));
|
|
1149
1169
|
};
|
|
@@ -1184,17 +1204,17 @@ import * as Effect6 from "effect/Effect";
|
|
|
1184
1204
|
import * as Layer2 from "effect/Layer";
|
|
1185
1205
|
import { OpaqueToolkit as OpaqueToolkit2, ToolExecutionService as ToolExecutionService2, ToolResolverService as ToolResolverService2 } from "@dxos/ai";
|
|
1186
1206
|
import { isTruthy } from "@dxos/util";
|
|
1187
|
-
var createToolkit = ({ toolkit: toolkitProp,
|
|
1188
|
-
const
|
|
1189
|
-
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));
|
|
1190
1210
|
const opaqueToolkit = OpaqueToolkit2.merge(...opaqueToolkits);
|
|
1191
1211
|
const toolkitDefs = [
|
|
1192
1212
|
toolkitProp?.toolkit,
|
|
1193
|
-
|
|
1213
|
+
skillToolkit,
|
|
1194
1214
|
opaqueToolkit.toolkit
|
|
1195
1215
|
].filter(isTruthy);
|
|
1196
1216
|
const mergedToolkit = Toolkit.merge(...toolkitDefs);
|
|
1197
|
-
const combinedHandlerLayer = Layer2.mergeAll(Layer2.succeedContext(
|
|
1217
|
+
const combinedHandlerLayer = Layer2.mergeAll(Layer2.succeedContext(skillToolHandler), toolkitProp?.layer ?? OpaqueToolkit2.empty.layer, opaqueToolkit.layer);
|
|
1198
1218
|
return OpaqueToolkit2.make(mergedToolkit, combinedHandlerLayer);
|
|
1199
1219
|
});
|
|
1200
1220
|
|
|
@@ -1203,17 +1223,14 @@ var AiContext_exports = {};
|
|
|
1203
1223
|
__export(AiContext_exports, {
|
|
1204
1224
|
Binder: () => Binder,
|
|
1205
1225
|
Binding: () => Binding,
|
|
1206
|
-
Bindings: () => Bindings
|
|
1207
|
-
Service: () => Service
|
|
1226
|
+
Bindings: () => Bindings
|
|
1208
1227
|
});
|
|
1209
1228
|
import { Atom, Registry as AtomRegistry } from "@effect-atom/atom-react";
|
|
1210
1229
|
import * as EArray from "effect/Array";
|
|
1211
|
-
import * as Context3 from "effect/Context";
|
|
1212
|
-
import * as Effect7 from "effect/Effect";
|
|
1213
1230
|
import * as Function3 from "effect/Function";
|
|
1214
1231
|
import * as Runtime from "effect/Runtime";
|
|
1215
1232
|
import * as Schema5 from "effect/Schema";
|
|
1216
|
-
import {
|
|
1233
|
+
import { Skill } from "@dxos/compute";
|
|
1217
1234
|
import { Resource } from "@dxos/context";
|
|
1218
1235
|
import { Annotation, DXN as DXN2, Feed, Obj as Obj6, Query, Ref as Ref3, Type as Type2 } from "@dxos/echo";
|
|
1219
1236
|
import { assertArgument } from "@dxos/invariant";
|
|
@@ -1221,18 +1238,19 @@ import { EID as EID3 } from "@dxos/keys";
|
|
|
1221
1238
|
import { log as log4 } from "@dxos/log";
|
|
1222
1239
|
import { ComplexSet, isNonNullable as isNonNullable3 } from "@dxos/util";
|
|
1223
1240
|
var __dxlog_file5 = "/__w/dxos/dxos/packages/core/compute/assistant/src/session/AiContext.ts";
|
|
1224
|
-
var Binding = Schema5.Struct({
|
|
1225
|
-
|
|
1226
|
-
added: Schema5.Array(Ref3.Ref(
|
|
1227
|
-
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))
|
|
1228
1245
|
}),
|
|
1229
1246
|
objects: Schema5.Struct({
|
|
1230
1247
|
added: Schema5.Array(Ref3.Ref(Obj6.Unknown)),
|
|
1231
1248
|
removed: Schema5.Array(Ref3.Ref(Obj6.Unknown))
|
|
1232
1249
|
})
|
|
1233
|
-
}).pipe(Annotation.HiddenAnnotation.set(true)
|
|
1250
|
+
}).pipe(Annotation.HiddenAnnotation.set(true))) {
|
|
1251
|
+
};
|
|
1234
1252
|
var Bindings = class {
|
|
1235
|
-
|
|
1253
|
+
skills = new ComplexSet((ref) => ref.uri);
|
|
1236
1254
|
// TODO(burdon): Some DXNs have the Space prefix so only compare the object ID.
|
|
1237
1255
|
objects = new ComplexSet((ref) => {
|
|
1238
1256
|
const echoUri = EID3.tryParse(ref.uri);
|
|
@@ -1240,13 +1258,13 @@ var Bindings = class {
|
|
|
1240
1258
|
});
|
|
1241
1259
|
toJSON() {
|
|
1242
1260
|
return {
|
|
1243
|
-
|
|
1261
|
+
skills: EArray.fromIterable(this.skills).map((ref) => ref.uri),
|
|
1244
1262
|
objects: EArray.fromIterable(this.objects).map((ref) => ref.uri)
|
|
1245
1263
|
};
|
|
1246
1264
|
}
|
|
1247
1265
|
};
|
|
1248
1266
|
var Binder = class extends Resource {
|
|
1249
|
-
|
|
1267
|
+
_skills = Atom.make([]).pipe(Atom.keepAlive);
|
|
1250
1268
|
_objects = Atom.make([]).pipe(Atom.keepAlive);
|
|
1251
1269
|
_registry;
|
|
1252
1270
|
_feed;
|
|
@@ -1261,10 +1279,10 @@ var Binder = class extends Resource {
|
|
|
1261
1279
|
this._registry = options.registry ?? AtomRegistry.make();
|
|
1262
1280
|
}
|
|
1263
1281
|
/**
|
|
1264
|
-
* Returns the
|
|
1282
|
+
* Returns the skills atom for subscription.
|
|
1265
1283
|
*/
|
|
1266
|
-
get
|
|
1267
|
-
return this.
|
|
1284
|
+
get skills() {
|
|
1285
|
+
return this._skills;
|
|
1268
1286
|
}
|
|
1269
1287
|
/**
|
|
1270
1288
|
* Returns the objects atom for subscription.
|
|
@@ -1273,10 +1291,10 @@ var Binder = class extends Resource {
|
|
|
1273
1291
|
return this._objects;
|
|
1274
1292
|
}
|
|
1275
1293
|
/**
|
|
1276
|
-
* Gets the current
|
|
1294
|
+
* Gets the current skills value.
|
|
1277
1295
|
*/
|
|
1278
|
-
|
|
1279
|
-
return this._registry.get(this.
|
|
1296
|
+
getSkills() {
|
|
1297
|
+
return this._registry.get(this._skills);
|
|
1280
1298
|
}
|
|
1281
1299
|
/**
|
|
1282
1300
|
* Gets the current objects value.
|
|
@@ -1285,10 +1303,10 @@ var Binder = class extends Resource {
|
|
|
1285
1303
|
return this._registry.get(this._objects);
|
|
1286
1304
|
}
|
|
1287
1305
|
/**
|
|
1288
|
-
* Subscribe to changes in
|
|
1306
|
+
* Subscribe to changes in skills.
|
|
1289
1307
|
*/
|
|
1290
|
-
|
|
1291
|
-
return this._registry.subscribe(this.
|
|
1308
|
+
subscribeSkills(cb) {
|
|
1309
|
+
return this._registry.subscribe(this._skills, () => cb(this._registry.get(this._skills)));
|
|
1292
1310
|
}
|
|
1293
1311
|
/**
|
|
1294
1312
|
* Subscribe to changes in objects.
|
|
@@ -1312,12 +1330,12 @@ var Binder = class extends Resource {
|
|
|
1312
1330
|
const results = await this.#bindingsQuery.run();
|
|
1313
1331
|
log4("sync", {
|
|
1314
1332
|
bindingItems: results.length
|
|
1315
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L:
|
|
1333
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 107, S: this });
|
|
1316
1334
|
await this._updateBindings(results);
|
|
1317
1335
|
log4("sync complete", {
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
}, { "~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 });
|
|
1321
1339
|
}
|
|
1322
1340
|
}
|
|
1323
1341
|
async _updateBindings(items) {
|
|
@@ -1327,75 +1345,75 @@ var Binder = class extends Resource {
|
|
|
1327
1345
|
const bindings = this._reduce(items);
|
|
1328
1346
|
log4("_updateBindings", {
|
|
1329
1347
|
items: items.length,
|
|
1330
|
-
|
|
1331
|
-
...bindings.
|
|
1348
|
+
skillRefs: [
|
|
1349
|
+
...bindings.skills
|
|
1332
1350
|
].map((ref) => ({
|
|
1333
1351
|
uri: ref.uri,
|
|
1334
1352
|
available: ref.isAvailable
|
|
1335
1353
|
}))
|
|
1336
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L:
|
|
1337
|
-
const
|
|
1354
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 123, S: this });
|
|
1355
|
+
const currentSkills = this._registry.get(this._skills);
|
|
1338
1356
|
const currentObjects = this._registry.get(this._objects);
|
|
1339
|
-
const
|
|
1357
|
+
const resolvedSkills = await this._resolve(bindings.skills, currentSkills);
|
|
1340
1358
|
const resolvedObjects = await this._resolve(bindings.objects, currentObjects);
|
|
1341
1359
|
log4("_updateBindings resolved", {
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L:
|
|
1345
|
-
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) => {
|
|
1346
1364
|
if (Obj6.getMeta(bp).key === void 0) {
|
|
1347
|
-
log4.warn("dropping
|
|
1365
|
+
log4.warn("dropping skill with no meta key", {
|
|
1348
1366
|
uri: Obj6.getURI(bp)
|
|
1349
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L:
|
|
1367
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 145, S: this });
|
|
1350
1368
|
return false;
|
|
1351
1369
|
}
|
|
1352
1370
|
return true;
|
|
1353
1371
|
});
|
|
1354
|
-
const
|
|
1355
|
-
...bindings.
|
|
1372
|
+
const reducedSkillDxns = new Set([
|
|
1373
|
+
...bindings.skills
|
|
1356
1374
|
].map((ref) => ref.uri));
|
|
1357
1375
|
const reducedObjectDxns = new Set([
|
|
1358
1376
|
...bindings.objects
|
|
1359
1377
|
].map((ref) => ref.uri));
|
|
1360
|
-
const
|
|
1378
|
+
const filteredSkills = currentSkills.filter((obj) => {
|
|
1361
1379
|
const uri = Obj6.getURI(obj);
|
|
1362
|
-
return uri != null &&
|
|
1380
|
+
return uri != null && reducedSkillDxns.has(uri) && Obj6.getMeta(obj).key !== void 0;
|
|
1363
1381
|
});
|
|
1364
1382
|
const filteredObjects = currentObjects.filter((obj) => {
|
|
1365
1383
|
const uri = Obj6.getURI(obj);
|
|
1366
1384
|
return uri != null && reducedObjectDxns.has(uri);
|
|
1367
1385
|
});
|
|
1368
|
-
const
|
|
1386
|
+
const mergedSkills = this._mergeInto(filteredSkills, keyedSkills);
|
|
1369
1387
|
const mergedObjects = this._mergeInto(filteredObjects, resolvedObjects);
|
|
1370
|
-
this._registry.set(this.
|
|
1388
|
+
this._registry.set(this._skills, mergedSkills);
|
|
1371
1389
|
this._registry.set(this._objects, mergedObjects);
|
|
1372
1390
|
log4("updated bindings", {
|
|
1373
|
-
|
|
1391
|
+
skills: mergedSkills.length,
|
|
1374
1392
|
objects: mergedObjects.length
|
|
1375
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L:
|
|
1393
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 172, S: this });
|
|
1376
1394
|
}
|
|
1377
1395
|
async _close() {
|
|
1378
|
-
this._registry.set(this.
|
|
1396
|
+
this._registry.set(this._skills, []);
|
|
1379
1397
|
this._registry.set(this._objects, []);
|
|
1380
1398
|
}
|
|
1381
|
-
async bind({
|
|
1382
|
-
const
|
|
1399
|
+
async bind({ skills, objects }) {
|
|
1400
|
+
const currentSkills = this._registry.get(this._skills);
|
|
1383
1401
|
const currentObjects = this._registry.get(this._objects);
|
|
1384
|
-
const { added:
|
|
1402
|
+
const { added: addedSkills, next: nextSkills } = this._processBindings(skills, currentSkills);
|
|
1385
1403
|
const { added: addedObjects, next: nextObjects } = this._processBindings(objects, currentObjects);
|
|
1386
|
-
if (!
|
|
1404
|
+
if (!addedSkills.length && !addedObjects.length) {
|
|
1387
1405
|
return;
|
|
1388
1406
|
}
|
|
1389
|
-
this._registry.set(this.
|
|
1407
|
+
this._registry.set(this._skills, nextSkills);
|
|
1390
1408
|
this._registry.set(this._objects, nextObjects);
|
|
1391
1409
|
log4("bind", {
|
|
1392
|
-
|
|
1410
|
+
skills: addedSkills.length,
|
|
1393
1411
|
objects: addedObjects.length
|
|
1394
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L:
|
|
1412
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 193, S: this });
|
|
1395
1413
|
await Runtime.runPromise(this._runtime)(Feed.append(this._feed, [
|
|
1396
1414
|
Obj6.make(Binding, {
|
|
1397
|
-
|
|
1398
|
-
added:
|
|
1415
|
+
skills: {
|
|
1416
|
+
added: addedSkills,
|
|
1399
1417
|
removed: []
|
|
1400
1418
|
},
|
|
1401
1419
|
objects: {
|
|
@@ -1405,29 +1423,29 @@ var Binder = class extends Resource {
|
|
|
1405
1423
|
})
|
|
1406
1424
|
]));
|
|
1407
1425
|
}
|
|
1408
|
-
async unbind({
|
|
1409
|
-
if (!
|
|
1426
|
+
async unbind({ skills, objects }) {
|
|
1427
|
+
if (!skills?.length && !objects?.length) {
|
|
1410
1428
|
return;
|
|
1411
1429
|
}
|
|
1412
|
-
const
|
|
1430
|
+
const removedSkillDxns = (skills ?? []).map((ref) => ref.uri);
|
|
1413
1431
|
const removedObjectDxns = (objects ?? []).map((ref) => ref.uri);
|
|
1414
|
-
if (
|
|
1415
|
-
const current = this._registry.get(this.
|
|
1416
|
-
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)));
|
|
1417
1435
|
}
|
|
1418
1436
|
if (removedObjectDxns.length > 0) {
|
|
1419
1437
|
const current = this._registry.get(this._objects);
|
|
1420
1438
|
this._registry.set(this._objects, current.filter((obj) => !removedObjectDxns.some((uri) => Obj6.getURI(obj) === uri)));
|
|
1421
1439
|
}
|
|
1422
1440
|
log4("unbind", {
|
|
1423
|
-
|
|
1441
|
+
skills: skills?.length,
|
|
1424
1442
|
objects: objects?.length
|
|
1425
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L:
|
|
1443
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 225, S: this });
|
|
1426
1444
|
await Runtime.runPromise(this._runtime)(Feed.append(this._feed, [
|
|
1427
1445
|
Obj6.make(Binding, {
|
|
1428
|
-
|
|
1446
|
+
skills: {
|
|
1429
1447
|
added: [],
|
|
1430
|
-
removed:
|
|
1448
|
+
removed: skills ?? []
|
|
1431
1449
|
},
|
|
1432
1450
|
objects: {
|
|
1433
1451
|
added: [],
|
|
@@ -1471,12 +1489,12 @@ var Binder = class extends Resource {
|
|
|
1471
1489
|
};
|
|
1472
1490
|
}
|
|
1473
1491
|
/**
|
|
1474
|
-
* Reduce results into sets of
|
|
1492
|
+
* Reduce results into sets of skills and objects.
|
|
1475
1493
|
*/
|
|
1476
1494
|
_reduce(items) {
|
|
1477
|
-
return Function3.pipe(items, EArray.reduce(new Bindings(), (context, {
|
|
1478
|
-
|
|
1479
|
-
|
|
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));
|
|
1480
1498
|
objects.added.forEach((ref) => context.objects.add(ref));
|
|
1481
1499
|
objects.removed.forEach((ref) => {
|
|
1482
1500
|
for (const obj of context.objects) {
|
|
@@ -1507,7 +1525,7 @@ var Binder = class extends Resource {
|
|
|
1507
1525
|
}
|
|
1508
1526
|
/**
|
|
1509
1527
|
* Resolve references to objects, loading them first if needed and falling back to existing objects.
|
|
1510
|
-
* 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
|
|
1511
1529
|
* which already spans both the space DB and the hypergraph registry.
|
|
1512
1530
|
*/
|
|
1513
1531
|
async _resolve(refs, current) {
|
|
@@ -1524,47 +1542,56 @@ var Binder = class extends Resource {
|
|
|
1524
1542
|
}).filter(isNonNullable3);
|
|
1525
1543
|
}
|
|
1526
1544
|
};
|
|
1527
|
-
var Service = class _Service extends Context3.Tag("@dxos/assistant/AiContextService")() {
|
|
1528
|
-
static bindContext = ({ blueprints, objects }) => Effect7.gen(function* () {
|
|
1529
|
-
const { binder } = yield* _Service;
|
|
1530
|
-
yield* Effect7.promise(() => binder.bind({
|
|
1531
|
-
blueprints,
|
|
1532
|
-
objects
|
|
1533
|
-
}));
|
|
1534
|
-
});
|
|
1535
|
-
static findObjects = (type) => {
|
|
1536
|
-
return Effect7.gen(function* () {
|
|
1537
|
-
const { binder } = yield* _Service;
|
|
1538
|
-
return binder.getObjects().filter(Obj6.instanceOf(type));
|
|
1539
|
-
});
|
|
1540
|
-
};
|
|
1541
|
-
};
|
|
1542
1545
|
|
|
1543
1546
|
// src/session/AiSession.ts
|
|
1544
1547
|
var AiSession_exports = {};
|
|
1545
1548
|
__export(AiSession_exports, {
|
|
1546
|
-
Service: () => Service2,
|
|
1547
1549
|
Session: () => Session
|
|
1548
1550
|
});
|
|
1549
1551
|
import * as Array4 from "effect/Array";
|
|
1550
|
-
import * as
|
|
1551
|
-
import * as Effect9 from "effect/Effect";
|
|
1552
|
+
import * as Effect10 from "effect/Effect";
|
|
1552
1553
|
import * as Either from "effect/Either";
|
|
1553
1554
|
import { pipe as pipe4 } from "effect/Function";
|
|
1554
|
-
import * as
|
|
1555
|
+
import * as Layer4 from "effect/Layer";
|
|
1555
1556
|
import * as Record2 from "effect/Record";
|
|
1556
1557
|
import * as Runtime2 from "effect/Runtime";
|
|
1557
|
-
import { Operation as
|
|
1558
|
+
import { Operation as Operation3, Trace as Trace3 } from "@dxos/compute";
|
|
1558
1559
|
import { Resource as Resource2 } from "@dxos/context";
|
|
1559
|
-
import {
|
|
1560
|
-
import {
|
|
1561
|
-
import {
|
|
1562
|
-
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";
|
|
1563
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";
|
|
1564
1591
|
import { Message as Message5 } from "@dxos/types";
|
|
1565
1592
|
|
|
1566
1593
|
// src/session/SessionLoader.ts
|
|
1567
|
-
import * as
|
|
1594
|
+
import * as Effect7 from "effect/Effect";
|
|
1568
1595
|
import { Feed as Feed3, Filter as Filter2, Obj as Obj8 } from "@dxos/echo";
|
|
1569
1596
|
import { Message as Message4 } from "@dxos/types";
|
|
1570
1597
|
|
|
@@ -1575,12 +1602,13 @@ __export(SessionLink_exports, {
|
|
|
1575
1602
|
});
|
|
1576
1603
|
import * as Schema6 from "effect/Schema";
|
|
1577
1604
|
import { DXN as DXN3, Feed as Feed2, Obj as Obj7, Ref as Ref4, Type as Type3 } from "@dxos/echo";
|
|
1578
|
-
var SessionLink = Schema6.Struct({
|
|
1605
|
+
var SessionLink = class extends Type3.makeObject(DXN3.make("org.dxos.type.sessionLink", "0.1.0"))(Schema6.Struct({
|
|
1579
1606
|
/** Reference to the feed of the source session. */
|
|
1580
1607
|
feedRef: Ref4.Ref(Feed2.Feed),
|
|
1581
1608
|
/** Messages from the source feed up to and including this message ID are injected. */
|
|
1582
1609
|
messageId: Obj7.ID
|
|
1583
|
-
})
|
|
1610
|
+
})) {
|
|
1611
|
+
};
|
|
1584
1612
|
|
|
1585
1613
|
// src/session/SessionLoader.ts
|
|
1586
1614
|
var SessionLoader = class {
|
|
@@ -1590,8 +1618,8 @@ var SessionLoader = class {
|
|
|
1590
1618
|
* the referenced feed up to and including `messageId` and prepends them.
|
|
1591
1619
|
*/
|
|
1592
1620
|
reifyHistory(feed, messages) {
|
|
1593
|
-
return
|
|
1594
|
-
const links = yield* Feed3.
|
|
1621
|
+
return Effect7.gen(function* () {
|
|
1622
|
+
const links = yield* Feed3.query(feed, Filter2.type(SessionLink)).run;
|
|
1595
1623
|
const sessionLinks = links.filter(Obj8.instanceOf(SessionLink));
|
|
1596
1624
|
const link = sessionLinks[0];
|
|
1597
1625
|
if (!link) {
|
|
@@ -1601,7 +1629,7 @@ var SessionLoader = class {
|
|
|
1601
1629
|
if (!sourceFeed) {
|
|
1602
1630
|
return messages;
|
|
1603
1631
|
}
|
|
1604
|
-
const sourceMessages = yield* Feed3.
|
|
1632
|
+
const sourceMessages = yield* Feed3.query(sourceFeed, Filter2.type(Message4.Message)).run;
|
|
1605
1633
|
const filtered = sourceMessages.filter(Obj8.instanceOf(Message4.Message));
|
|
1606
1634
|
const sorted = [
|
|
1607
1635
|
...filtered
|
|
@@ -1618,12 +1646,138 @@ var SessionLoader = class {
|
|
|
1618
1646
|
}
|
|
1619
1647
|
};
|
|
1620
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
|
+
|
|
1621
1775
|
// src/session/AiSession.ts
|
|
1622
|
-
var
|
|
1776
|
+
var __dxlog_file7 = "/__w/dxos/dxos/packages/core/compute/assistant/src/session/AiSession.ts";
|
|
1623
1777
|
var SUMMARY_THRESHOLD = 8e4;
|
|
1624
1778
|
var Session = class extends Resource2 {
|
|
1625
1779
|
/**
|
|
1626
|
-
*
|
|
1780
|
+
* Skills and objects bound to the session.
|
|
1627
1781
|
*/
|
|
1628
1782
|
_binder;
|
|
1629
1783
|
_feed;
|
|
@@ -1633,8 +1787,8 @@ var Session = class extends Resource2 {
|
|
|
1633
1787
|
super();
|
|
1634
1788
|
this._feed = options.feed;
|
|
1635
1789
|
this._runtime = options.runtime;
|
|
1636
|
-
|
|
1637
|
-
|
|
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", ""] });
|
|
1638
1792
|
this._binder = new Binder({
|
|
1639
1793
|
feed: this._feed,
|
|
1640
1794
|
runtime: this._runtime,
|
|
@@ -1651,134 +1805,116 @@ var Session = class extends Resource2 {
|
|
|
1651
1805
|
return this._binder;
|
|
1652
1806
|
}
|
|
1653
1807
|
async getHistory() {
|
|
1654
|
-
const queryResult = await Runtime2.runPromise(this._runtime)(
|
|
1808
|
+
const queryResult = await Runtime2.runPromise(this._runtime)(Feed5.query(this._feed, Filter4.type(Message6.Message)));
|
|
1655
1809
|
const items = await queryResult.run();
|
|
1656
|
-
const messages = items.filter(
|
|
1810
|
+
const messages = items.filter(Obj10.instanceOf(Message6.Message));
|
|
1657
1811
|
return Runtime2.runPromise(this._runtime)(this._sessionLoader.reifyHistory(this._feed, messages));
|
|
1658
1812
|
}
|
|
1659
1813
|
getTools() {
|
|
1660
|
-
return
|
|
1814
|
+
return Effect10.gen(this, function* () {
|
|
1661
1815
|
const toolkit = yield* createToolkit({
|
|
1662
|
-
|
|
1816
|
+
skills: this.context.getSkills()
|
|
1663
1817
|
});
|
|
1664
1818
|
return toolkit.toolkit.tools;
|
|
1665
|
-
}).pipe(
|
|
1819
|
+
}).pipe(Effect10.orDie);
|
|
1666
1820
|
}
|
|
1667
1821
|
/**
|
|
1668
1822
|
* Not provided by default, since users might want to override them.
|
|
1669
1823
|
*/
|
|
1670
1824
|
makeToolExecutionServices() {
|
|
1671
|
-
return ToolExecutionServices.pipe(
|
|
1672
|
-
conversation:
|
|
1825
|
+
return ToolExecutionServices.pipe(Layer4.provide(Operation3.withInvocationOptions({
|
|
1826
|
+
conversation: Obj10.getURI(this._feed)
|
|
1673
1827
|
})));
|
|
1674
1828
|
}
|
|
1675
1829
|
/**
|
|
1676
1830
|
* Creates a new cancelable request effect.
|
|
1677
1831
|
*/
|
|
1678
1832
|
createRequest(params) {
|
|
1679
|
-
return
|
|
1680
|
-
const
|
|
1681
|
-
const
|
|
1833
|
+
return Effect10.gen(this, function* () {
|
|
1834
|
+
const history2 = yield* Effect10.promise(() => this.getHistory());
|
|
1835
|
+
const skills = this.context.getSkills();
|
|
1682
1836
|
const objects = this.context.getObjects();
|
|
1683
|
-
|
|
1684
|
-
history:
|
|
1685
|
-
|
|
1837
|
+
log6("run", {
|
|
1838
|
+
history: history2.length,
|
|
1839
|
+
skills: skills.length,
|
|
1686
1840
|
objects: objects.length
|
|
1687
|
-
}, { "~LogMeta": "~LogMeta", F:
|
|
1841
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 90, S: this });
|
|
1688
1842
|
const request = new AiRequest_exports.Request({
|
|
1689
1843
|
summarizationThreshold: SUMMARY_THRESHOLD,
|
|
1690
1844
|
observer: params.observer,
|
|
1691
1845
|
persist: params.persist,
|
|
1692
|
-
onOutput: (message) =>
|
|
1846
|
+
onOutput: (message) => Effect10.promise(() => Runtime2.runPromise(this._runtime)(Feed5.append(this._feed, [
|
|
1693
1847
|
message
|
|
1694
1848
|
])))
|
|
1695
1849
|
});
|
|
1696
1850
|
yield* request.begin({
|
|
1697
|
-
history,
|
|
1698
|
-
|
|
1851
|
+
history: history2,
|
|
1852
|
+
skills,
|
|
1699
1853
|
objects,
|
|
1700
1854
|
prompt: params.prompt,
|
|
1701
1855
|
system: params.system
|
|
1702
1856
|
});
|
|
1857
|
+
yield* runHooks({
|
|
1858
|
+
skills,
|
|
1859
|
+
phase: "begin-request",
|
|
1860
|
+
invoke: (operation, input) => Operation3.invoke(operation, input).pipe(Effect10.asVoid, Effect10.orDie)
|
|
1861
|
+
});
|
|
1703
1862
|
do {
|
|
1704
|
-
yield*
|
|
1705
|
-
const
|
|
1706
|
-
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);
|
|
1707
1866
|
const toolkit = yield* createToolkit({
|
|
1708
1867
|
toolkit: params.toolkit,
|
|
1709
|
-
|
|
1868
|
+
skills: currentSkills,
|
|
1710
1869
|
opaqueToolkits: mcps
|
|
1711
1870
|
});
|
|
1712
|
-
|
|
1871
|
+
log6("toolkit", {
|
|
1713
1872
|
tools: Record2.keys(toolkit.toolkit.tools)
|
|
1714
|
-
}, { "~LogMeta": "~LogMeta", F:
|
|
1873
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 127, S: this });
|
|
1715
1874
|
const system = yield* formatSystemPrompt({
|
|
1716
1875
|
system: params.system,
|
|
1717
|
-
|
|
1876
|
+
skills: currentSkills,
|
|
1718
1877
|
objects: this.context.getObjects()
|
|
1719
|
-
}).pipe(
|
|
1720
|
-
const { done } = yield* request.runAgentTurn({
|
|
1878
|
+
}).pipe(Effect10.orDie);
|
|
1879
|
+
const { done, finishReason } = yield* request.runAgentTurn({
|
|
1721
1880
|
system,
|
|
1722
1881
|
toolkit
|
|
1723
1882
|
});
|
|
1724
1883
|
if (done) {
|
|
1725
1884
|
break;
|
|
1726
1885
|
}
|
|
1886
|
+
if (finishReason === "pause") {
|
|
1887
|
+
continue;
|
|
1888
|
+
}
|
|
1727
1889
|
yield* request.runTools({
|
|
1728
1890
|
toolkit
|
|
1729
1891
|
});
|
|
1730
1892
|
} while (true);
|
|
1731
|
-
|
|
1893
|
+
log6("result", {
|
|
1732
1894
|
messages: request.pending.length,
|
|
1733
1895
|
duration: request.duration,
|
|
1734
1896
|
toolCalls: request.toolCalls
|
|
1735
|
-
}, { "~LogMeta": "~LogMeta", F:
|
|
1897
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 151, S: this });
|
|
1736
1898
|
return [
|
|
1737
1899
|
...request.pending
|
|
1738
1900
|
];
|
|
1739
|
-
}).pipe(
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
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"));
|
|
1744
1914
|
}
|
|
1745
1915
|
};
|
|
1746
|
-
var
|
|
1747
|
-
|
|
1748
|
-
* Create a new session layer from options.
|
|
1749
|
-
*/
|
|
1750
|
-
static layer = (options) => aiContextFromSession.pipe(Layer3.provideMerge(Layer3.scoped(_Service, Effect9.gen(function* () {
|
|
1751
|
-
const session = yield* EffectEx.acquireReleaseResource(() => new Session(options));
|
|
1752
|
-
return session;
|
|
1753
|
-
}))));
|
|
1754
|
-
/**
|
|
1755
|
-
* Create a new session with a new feed.
|
|
1756
|
-
*/
|
|
1757
|
-
static layerNewFeed = (options) => Layer3.unwrapScoped(Effect9.gen(function* () {
|
|
1758
|
-
const feed = yield* Database2.add(Feed4.make());
|
|
1759
|
-
const runtime2 = yield* Effect9.runtime();
|
|
1760
|
-
return _Service.layer({
|
|
1761
|
-
...options,
|
|
1762
|
-
feed,
|
|
1763
|
-
runtime: runtime2
|
|
1764
|
-
});
|
|
1765
|
-
}));
|
|
1766
|
-
/**
|
|
1767
|
-
* Run a prompt in the current session.
|
|
1768
|
-
*/
|
|
1769
|
-
static run = (params) => Effect9.gen(function* () {
|
|
1770
|
-
const session = yield* _Service;
|
|
1771
|
-
return yield* session.createRequest(params);
|
|
1772
|
-
});
|
|
1773
|
-
};
|
|
1774
|
-
var aiContextFromSession = Layer3.effect(Service, Effect9.gen(function* () {
|
|
1775
|
-
const session = yield* Service2;
|
|
1776
|
-
return {
|
|
1777
|
-
binder: session.context
|
|
1778
|
-
};
|
|
1779
|
-
}));
|
|
1780
|
-
var connectMcpServers = (blueprints, spaceMcpServers = []) => {
|
|
1781
|
-
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 }) => ({
|
|
1782
1918
|
url,
|
|
1783
1919
|
protocol,
|
|
1784
1920
|
apiKey
|
|
@@ -1789,22 +1925,22 @@ var connectMcpServers = (blueprints, spaceMcpServers = []) => {
|
|
|
1789
1925
|
apiKey
|
|
1790
1926
|
}));
|
|
1791
1927
|
const allServers = [
|
|
1792
|
-
...
|
|
1928
|
+
...skillServers,
|
|
1793
1929
|
...spaceServers
|
|
1794
1930
|
];
|
|
1795
|
-
return pipe4(allServers,
|
|
1931
|
+
return pipe4(allServers, Effect10.forEach((options) => McpToolkit.make(options).pipe(
|
|
1796
1932
|
// NOTE: Type-inference fails here without explicit void return.
|
|
1797
|
-
|
|
1933
|
+
Effect10.tap((toolkit) => log6.info("Connected to MCP server", {
|
|
1798
1934
|
url: options.url,
|
|
1799
1935
|
tools: Object.keys(toolkit.toolkit.tools).length
|
|
1800
|
-
}, { "~LogMeta": "~LogMeta", F:
|
|
1936
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 187, S: void 0 })),
|
|
1801
1937
|
// Surface typed connection failures via ephemeral trace + warn log, then drop the server.
|
|
1802
|
-
|
|
1803
|
-
|
|
1938
|
+
Effect10.tapError((error) => Effect10.gen(function* () {
|
|
1939
|
+
log6.warn("Failed to connect to MCP server", {
|
|
1804
1940
|
url: error.url,
|
|
1805
1941
|
protocol: error.protocol,
|
|
1806
1942
|
message: error.message
|
|
1807
|
-
}, { "~LogMeta": "~LogMeta", F:
|
|
1943
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 192, S: this });
|
|
1808
1944
|
yield* Trace3.write(McpServerError, {
|
|
1809
1945
|
url: error.url,
|
|
1810
1946
|
protocol: error.protocol,
|
|
@@ -1813,36 +1949,54 @@ var connectMcpServers = (blueprints, spaceMcpServers = []) => {
|
|
|
1813
1949
|
})),
|
|
1814
1950
|
// Catch unexpected defects too (e.g. malformed tool schemas) so a single broken
|
|
1815
1951
|
// server can never abort the whole turn — surface them through the same channel.
|
|
1816
|
-
|
|
1952
|
+
Effect10.catchAllDefect((defect) => Effect10.gen(function* () {
|
|
1817
1953
|
const message = defect instanceof Error ? defect.message : String(defect);
|
|
1818
|
-
|
|
1954
|
+
log6.warn("Unexpected MCP defect", {
|
|
1819
1955
|
url: options.url,
|
|
1820
1956
|
message
|
|
1821
|
-
}, { "~LogMeta": "~LogMeta", F:
|
|
1957
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 206, S: this });
|
|
1822
1958
|
yield* Trace3.write(McpServerError, {
|
|
1823
1959
|
url: options.url,
|
|
1824
1960
|
protocol: options.protocol,
|
|
1825
1961
|
message: `Unexpected MCP failure: ${message}`
|
|
1826
1962
|
});
|
|
1827
|
-
return yield*
|
|
1963
|
+
return yield* Effect10.fail(new McpToolkit.McpConnectionError({
|
|
1828
1964
|
url: options.url,
|
|
1829
1965
|
protocol: options.protocol,
|
|
1830
1966
|
message
|
|
1831
1967
|
}));
|
|
1832
1968
|
})),
|
|
1833
|
-
|
|
1834
|
-
)),
|
|
1969
|
+
Effect10.either
|
|
1970
|
+
)), Effect10.map(Array4.filterMap((_) => Either.getRight(_))));
|
|
1835
1971
|
};
|
|
1836
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
|
+
|
|
1837
1991
|
// src/templates/system.ts
|
|
1838
1992
|
import defaultsDeep from "lodash.defaultsdeep";
|
|
1839
1993
|
import { Template as Template2 } from "@dxos/compute";
|
|
1840
1994
|
|
|
1841
1995
|
// raw-loader:/__w/dxos/dxos/packages/core/compute/assistant/src/templates/instructions/format.tpl
|
|
1842
|
-
var format_default = "{{! System Core }}\n\n## Input Formats\n\n###
|
|
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";
|
|
1843
1997
|
|
|
1844
1998
|
// raw-loader:/__w/dxos/dxos/packages/core/compute/assistant/src/templates/instructions/system.tpl
|
|
1845
|
-
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
|
|
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>";
|
|
1846
2000
|
|
|
1847
2001
|
// src/templates/system.ts
|
|
1848
2002
|
var createSystemPrompt = (options = {}) => Template2.process(format_default, defaultsDeep(options, {
|
|
@@ -1866,11 +2020,14 @@ export {
|
|
|
1866
2020
|
CompleteBlock,
|
|
1867
2021
|
ExecutionGraph,
|
|
1868
2022
|
GenerationObserver,
|
|
2023
|
+
Harness_exports as Harness,
|
|
2024
|
+
HarnessControl,
|
|
1869
2025
|
McpServerError,
|
|
1870
2026
|
PartialBlock,
|
|
1871
2027
|
RefFromLLM,
|
|
1872
2028
|
SessionLink_exports as SessionLink,
|
|
1873
2029
|
SessionLoader,
|
|
2030
|
+
SkillHooks_exports as SkillHooks,
|
|
1874
2031
|
ToolExecutionServices,
|
|
1875
2032
|
applyDiffs,
|
|
1876
2033
|
computeDiffsWithCursors,
|