@dxos/assistant 0.8.4-main.9be5663bfe → 0.8.4-main.abd8ff62ef
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 +4 -21
- package/dist/lib/neutral/extraction/index.mjs.map +3 -3
- package/dist/lib/neutral/index.mjs +1259 -79
- package/dist/lib/neutral/index.mjs.map +4 -4
- package/dist/lib/neutral/meta.json +1 -1
- package/dist/types/src/conversation/context.d.ts +9 -12
- package/dist/types/src/conversation/context.d.ts.map +1 -1
- package/dist/types/src/conversation/index.d.ts +1 -1
- package/dist/types/src/conversation/index.d.ts.map +1 -1
- package/dist/types/src/conversation/session.d.ts +78 -0
- package/dist/types/src/conversation/session.d.ts.map +1 -0
- package/dist/types/src/diff.d.ts.map +1 -1
- package/dist/types/src/errors.d.ts +12 -12
- package/dist/types/src/errors.d.ts.map +1 -1
- package/dist/types/src/execution-graph.d.ts.map +1 -1
- package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.d.ts.map +1 -1
- package/dist/types/src/extraction/extraction.d.ts +461 -455
- package/dist/types/src/extraction/extraction.d.ts.map +1 -1
- package/dist/types/src/extraction/quotes.d.ts.map +1 -1
- package/dist/types/src/functions/services.d.ts +7 -29
- package/dist/types/src/functions/services.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +0 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/session/artifact-diff.d.ts.map +1 -1
- package/dist/types/src/session/error-handling.d.ts.map +1 -1
- package/dist/types/src/session/format.d.ts +6 -3
- package/dist/types/src/session/format.d.ts.map +1 -1
- package/dist/types/src/session/index.d.ts +1 -1
- package/dist/types/src/session/{session.d.ts → request.d.ts} +25 -33
- package/dist/types/src/session/request.d.ts.map +1 -0
- package/dist/types/src/session/toolkit.d.ts +5 -7
- package/dist/types/src/session/toolkit.d.ts.map +1 -1
- package/dist/types/src/templates/system.d.ts +1 -1
- package/dist/types/src/templates/system.d.ts.map +1 -1
- package/dist/types/src/tracing.d.ts +64 -95
- package/dist/types/src/tracing.d.ts.map +1 -1
- package/dist/types/src/types/artifact.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +21 -38
- package/src/conversation/context.ts +1 -1
- package/src/conversation/index.ts +1 -1
- package/src/conversation/session.ts +334 -0
- package/src/execution-graph.ts +15 -5
- package/src/extraction/extraction.ts +1 -1
- package/src/functions/services.ts +12 -127
- package/src/functions.conversations.json +1 -1
- package/src/index.ts +0 -1
- package/src/session/format.ts +14 -9
- package/src/session/index.ts +1 -1
- package/src/session/request.conversations.json +1 -0
- package/src/session/{session.ts → request.ts} +44 -51
- package/src/session/toolkit.ts +18 -15
- package/src/templates/instructions/system.tpl +11 -0
- package/src/templates/system.ts +1 -1
- package/src/tracing.ts +13 -69
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs +0 -10
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +0 -7
- package/dist/lib/neutral/chunk-UAWIXKF6.mjs +0 -1875
- package/dist/lib/neutral/chunk-UAWIXKF6.mjs.map +0 -7
- package/dist/lib/neutral/testing/index.mjs +0 -114
- package/dist/lib/neutral/testing/index.mjs.map +0 -7
- package/dist/types/src/conversation/conversation.d.ts +0 -68
- package/dist/types/src/conversation/conversation.d.ts.map +0 -1
- package/dist/types/src/conversation/conversation.test.d.ts +0 -2
- package/dist/types/src/conversation/conversation.test.d.ts.map +0 -1
- package/dist/types/src/functions.test.d.ts +0 -2
- package/dist/types/src/functions.test.d.ts.map +0 -1
- package/dist/types/src/service/AgentService.d.ts +0 -61
- package/dist/types/src/service/AgentService.d.ts.map +0 -1
- package/dist/types/src/service/AgentService.test.d.ts +0 -2
- package/dist/types/src/service/AgentService.test.d.ts.map +0 -1
- package/dist/types/src/service/agent-process.d.ts +0 -17
- package/dist/types/src/service/agent-process.d.ts.map +0 -1
- package/dist/types/src/service/index.d.ts +0 -3
- package/dist/types/src/service/index.d.ts.map +0 -1
- package/dist/types/src/session/format.test.d.ts +0 -2
- package/dist/types/src/session/format.test.d.ts.map +0 -1
- package/dist/types/src/session/session.d.ts.map +0 -1
- package/dist/types/src/session/session.test.d.ts +0 -2
- package/dist/types/src/session/session.test.d.ts.map +0 -1
- package/dist/types/src/testing/index.d.ts +0 -2
- package/dist/types/src/testing/index.d.ts.map +0 -1
- package/dist/types/src/testing/layer.d.ts +0 -35
- package/dist/types/src/testing/layer.d.ts.map +0 -1
- package/src/conversation/conversation.test.ts +0 -58
- package/src/conversation/conversation.ts +0 -275
- package/src/functions.test.ts +0 -82
- package/src/service/AgentService.conversations.json +0 -1
- package/src/service/AgentService.test.ts +0 -169
- package/src/service/AgentService.ts +0 -165
- package/src/service/agent-process.ts +0 -359
- package/src/service/index.ts +0 -6
- package/src/session/format.test.ts +0 -132
- package/src/session/session.conversations.json +0 -1
- package/src/session/session.test.ts +0 -190
- package/src/testing/index.ts +0 -5
- package/src/testing/layer.ts +0 -259
|
@@ -1 +1 @@
|
|
|
1
|
-
{"conversations":[{"parameters":{"model":"@anthropic/claude-opus-4-6","stream":true,"tools":[{"name":"read-name","description":"Reads the name of an organization.","inputSchema":{"type":"object","required":["org"],"properties":{"org":{"type":"string","description":"The ID of the referenced object. Formats accepted:\n- DXN (dxn:echo:@:01KG7R1ZXWFMWQ4DA1Q6TN1DG4). DXNs can be prepended with an @ symbol for compatibility with in-text references.\n- space ID, object ID tuple (spaceID:objectID)\n- Only object ID that is assumed to be in the current space (01KG7R1ZXWFMWQ4DA1Q6TN1DG4)","examples":["dxn:echo:@:01KG7R1ZXWFMWQ4DA1Q6TN1DG4","@dxn:echo:@:01KG7R1ZXWFMWQ4DA1Q6TN1DG4","BM3FSHFOMJCHCG5QW7JTVKGYABD2GAA7G:01KG7R1ZXWFMWQ4DA1Q6TN1DG4","01KG7R1ZXWFMWQ4DA1Q6TN1DG4"]}},"additionalProperties":false}}]},"prompt":{"content":[{"role":"user","content":"What is the name of the organization? 01JGFJJZ00G0WKQSJGMAKCNT89","options":{"anthropic":{"cacheControl":{"ttl":"5m","type":"ephemeral"}}}}]},"response":[{"type":"response-metadata","id":"
|
|
1
|
+
{"conversations":[{"parameters":{"model":"@anthropic/claude-opus-4-6","stream":true,"tools":[{"name":"read-name","description":"Reads the name of an organization.","inputSchema":{"type":"object","required":["org"],"properties":{"org":{"type":"string","description":"The ID of the referenced object. Formats accepted:\n- DXN (dxn:echo:@:01KG7R1ZXWFMWQ4DA1Q6TN1DG4). DXNs can be prepended with an @ symbol for compatibility with in-text references.\n- space ID, object ID tuple (spaceID:objectID)\n- Only object ID that is assumed to be in the current space (01KG7R1ZXWFMWQ4DA1Q6TN1DG4)","examples":["dxn:echo:@:01KG7R1ZXWFMWQ4DA1Q6TN1DG4","@dxn:echo:@:01KG7R1ZXWFMWQ4DA1Q6TN1DG4","BM3FSHFOMJCHCG5QW7JTVKGYABD2GAA7G:01KG7R1ZXWFMWQ4DA1Q6TN1DG4","01KG7R1ZXWFMWQ4DA1Q6TN1DG4"]}},"additionalProperties":false}}]},"prompt":{"content":[{"role":"user","content":"What is the name of the organization? 01JGFJJZ00G0WKQSJGMAKCNT89","options":{"anthropic":{"cacheControl":{"ttl":"5m","type":"ephemeral"}}}}]},"response":[{"type":"response-metadata","id":"msg_01RTYeojYbdVe9QGkcMvKbER","modelId":"claude-opus-4-6","timestamp":"1970-01-01T00:00:00.000Z","metadata":{}},{"type":"reasoning-start","id":"0","metadata":{}},{"type":"reasoning-delta","id":"0","delta":"The","metadata":{}},{"type":"reasoning-delta","id":"0","delta":" user wants to know the name of an organization with ID 01JGFJJZ00G0WKQSJGMAKCNT89.","metadata":{}},{"type":"reasoning-delta","id":"0","delta":"","metadata":{"anthropic":{"type":"thinking","signature":"EpECClkIDRgCKkBhbbtJF+Q+wsAR8giXTK13Eui/M8yFfrB46Vzozj6aWeupuZy0FCx6VSI4FmNelVTGMCsbT5apFxxgVf6A7FAJMg9jbGF1ZGUtb3B1cy00LTY4ABIMHOEtEgcKz5Wb+gpbGgxPG+AOzUXWigifeyUiML7FnkmDoz8pWD5P9R4Wul/DeoJE41ntyU/B/abCz0pQx4PHE8N4i5aoFBhUuQE5hSpmlXcA03Cj9t8LvHSOwMobEUZcnKTZn9x1upUfts+Ez+NsQBXY//niKxqt/E7yE5TKHwDO/nuZ2rteTus79EjTEkPaEUcXQso8YAbQknG7ldRd1Nd2X4D2X+bBJH2AVG7SKLSFW3QAGAE="}}},{"type":"reasoning-end","id":"0","metadata":{}},{"type":"tool-params-start","id":"toolu_01KM7uhfLgRWepvTtotjHME2","name":"read-name","providerExecuted":false,"metadata":{}},{"type":"tool-params-delta","id":"toolu_01KM7uhfLgRWepvTtotjHME2","delta":"","metadata":{}},{"type":"tool-params-delta","id":"toolu_01KM7uhfLgRWepvTtotjHME2","delta":"{\"org\": \"01","metadata":{}},{"type":"tool-params-delta","id":"toolu_01KM7uhfLgRWepvTtotjHME2","delta":"JGFJJZ0","metadata":{}},{"type":"tool-params-delta","id":"toolu_01KM7uhfLgRWepvTtotjHME2","delta":"0G0W","metadata":{}},{"type":"tool-params-delta","id":"toolu_01KM7uhfLgRWepvTtotjHME2","delta":"KQSJGMAKCN","metadata":{}},{"type":"tool-params-delta","id":"toolu_01KM7uhfLgRWepvTtotjHME2","delta":"T89\"}","metadata":{}},{"type":"tool-params-end","id":"toolu_01KM7uhfLgRWepvTtotjHME2","metadata":{}},{"type":"finish","reason":"tool-calls","usage":{"inputTokens":883,"outputTokens":122,"totalTokens":1005},"metadata":{"anthropic":{"usage":{"cache_creation":{"ephemeral_1h_input_tokens":0,"ephemeral_5m_input_tokens":0},"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"input_tokens":883,"output_tokens":9,"server_tool_use":null,"service_tier":"standard"}}}}]},{"parameters":{"model":"@anthropic/claude-opus-4-6","stream":true,"tools":[{"name":"read-name","description":"Reads the name of an organization.","inputSchema":{"type":"object","required":["org"],"properties":{"org":{"type":"string","description":"The ID of the referenced object. Formats accepted:\n- DXN (dxn:echo:@:01KG7R1ZXWFMWQ4DA1Q6TN1DG4). DXNs can be prepended with an @ symbol for compatibility with in-text references.\n- space ID, object ID tuple (spaceID:objectID)\n- Only object ID that is assumed to be in the current space (01KG7R1ZXWFMWQ4DA1Q6TN1DG4)","examples":["dxn:echo:@:01KG7R1ZXWFMWQ4DA1Q6TN1DG4","@dxn:echo:@:01KG7R1ZXWFMWQ4DA1Q6TN1DG4","BM3FSHFOMJCHCG5QW7JTVKGYABD2GAA7G:01KG7R1ZXWFMWQ4DA1Q6TN1DG4","01KG7R1ZXWFMWQ4DA1Q6TN1DG4"]}},"additionalProperties":false}}]},"prompt":{"content":[{"role":"user","content":"What is the name of the organization? 01JGFJJZ00G0WKQSJGMAKCNT89","options":{}},{"role":"assistant","content":[{"type":"reasoning","text":"The user wants to know the name of an organization with ID 01JGFJJZ00G0WKQSJGMAKCNT89.","options":{}},{"type":"tool-call","id":"toolu_01KM7uhfLgRWepvTtotjHME2","name":"read-name","params":{"org":"01JGFJJZ00G0WKQSJGMAKCNT89"},"providerExecuted":false,"options":{}}],"options":{}},{"role":"tool","content":[{"type":"tool-result","id":"toolu_01KM7uhfLgRWepvTtotjHME2","name":"read-name","isFailure":false,"result":"BlueYard","providerExecuted":false,"options":{}}],"options":{"anthropic":{"cacheControl":{"ttl":"5m","type":"ephemeral"}}}}]},"response":[{"type":"response-metadata","id":"msg_016RCVnGrLXVf4ba4KznSHyr","modelId":"claude-opus-4-6","timestamp":"1970-01-01T00:00:00.000Z","metadata":{}},{"type":"reasoning-start","id":"0","metadata":{}},{"type":"reasoning-delta","id":"0","delta":"The","metadata":{}},{"type":"reasoning-delta","id":"0","delta":" name of the organization is \"BlueYard\".","metadata":{}},{"type":"reasoning-delta","id":"0","delta":"","metadata":{"anthropic":{"type":"thinking","signature":"EuYBClkIDRgCKkA0n2vPrvDwpmiAgWX5raN/PW8EkSgAqlMsO4gsgxIXidyUWiozI8lhzJTYOm5D3BOTMcW+mcfUvAw1rtDVianiMg9jbGF1ZGUtb3B1cy00LTY4ABIMiAi8SSliRognm8yNGgx+gpH0kejwSoiouLAiMBy9umHrGuQCJ92KaaBqRAq50lt7WXRaCyO3vuheveWN1JDryUFhh7GUZ/pogH0m+Co7lZSQmO4ybaE4MmyYbu7S3e/upJcsrQIiMB7LByFcpfSrjsF/VSIPprW5kMMafV1yQ6U2uI+dhUTohKMYAQ=="}}},{"type":"reasoning-end","id":"0","metadata":{}},{"type":"text-start","id":"1","metadata":{}},{"type":"text-delta","id":"1","delta":"The name of the organization with ID `01JGFJJZ00G0WKQSJGMAKCNT89` is","metadata":{}},{"type":"text-delta","id":"1","delta":" **BlueYard**.","metadata":{}},{"type":"text-end","id":"1","metadata":{}},{"type":"finish","reason":"stop","usage":{"inputTokens":973,"outputTokens":66,"totalTokens":1039},"metadata":{"anthropic":{"usage":{"cache_creation":{"ephemeral_1h_input_tokens":0,"ephemeral_5m_input_tokens":0},"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"input_tokens":973,"output_tokens":8,"server_tool_use":null,"service_tier":"standard"}}}}]}]}
|
package/src/index.ts
CHANGED
package/src/session/format.ts
CHANGED
|
@@ -6,9 +6,10 @@ import * as Effect from 'effect/Effect';
|
|
|
6
6
|
import * as Function from 'effect/Function';
|
|
7
7
|
import * as Option from 'effect/Option';
|
|
8
8
|
|
|
9
|
-
import { Template } from '@dxos/
|
|
10
|
-
import { Obj } from '@dxos/echo';
|
|
9
|
+
import { type FunctionNotFoundError, type Operation, type OperationRegistry, Template } from '@dxos/compute';
|
|
10
|
+
import { type Database, Obj } from '@dxos/echo';
|
|
11
11
|
import { ObjectVersion } from '@dxos/echo-db';
|
|
12
|
+
import type { ObjectNotFoundError } from '@dxos/echo/Err';
|
|
12
13
|
import { type ObjectId } from '@dxos/keys';
|
|
13
14
|
import { log } from '@dxos/log';
|
|
14
15
|
import { type ContentBlock, Message } from '@dxos/types';
|
|
@@ -16,7 +17,7 @@ import { trim } from '@dxos/util';
|
|
|
16
17
|
|
|
17
18
|
import { AiAssistantError } from '../errors';
|
|
18
19
|
import { ArtifactDiffResolver } from './artifact-diff';
|
|
19
|
-
import { type
|
|
20
|
+
import { type AiRequestRunError, type AiRequestRunProps } from './request';
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* Formats the system prompt.
|
|
@@ -26,7 +27,11 @@ export const formatSystemPrompt = ({
|
|
|
26
27
|
system,
|
|
27
28
|
blueprints = [],
|
|
28
29
|
objects = [],
|
|
29
|
-
}: Pick<
|
|
30
|
+
}: Pick<AiRequestRunProps, 'system' | 'blueprints' | 'objects'>): Effect.Effect<
|
|
31
|
+
string,
|
|
32
|
+
FunctionNotFoundError | ObjectNotFoundError,
|
|
33
|
+
Database.Service | OperationRegistry.Service | Operation.Service
|
|
34
|
+
> =>
|
|
30
35
|
Effect.gen(function* () {
|
|
31
36
|
const blueprintDefs = yield* Function.pipe(
|
|
32
37
|
blueprints,
|
|
@@ -64,7 +69,7 @@ export const formatSystemPrompt = ({
|
|
|
64
69
|
Effect.succeed([system, blueprintDefs, objectDefs].filter((def): def is string => def !== undefined)),
|
|
65
70
|
Effect.map((parts) => parts.join('\n\n')),
|
|
66
71
|
);
|
|
67
|
-
});
|
|
72
|
+
}).pipe(Effect.withSpan('formatSystemPrompt'));
|
|
68
73
|
|
|
69
74
|
/**
|
|
70
75
|
* Formats the user prompt.
|
|
@@ -74,7 +79,7 @@ export const formatSystemPrompt = ({
|
|
|
74
79
|
export const formatUserPrompt = ({
|
|
75
80
|
prompt,
|
|
76
81
|
history = [],
|
|
77
|
-
}: Pick<
|
|
82
|
+
}: Pick<AiRequestRunProps, 'prompt' | 'history'>): Effect.Effect<Message.Message, AiRequestRunError> =>
|
|
78
83
|
Effect.gen(function* () {
|
|
79
84
|
const blocks: ContentBlock.Any[] = [];
|
|
80
85
|
|
|
@@ -108,9 +113,9 @@ export const formatUserPrompt = ({
|
|
|
108
113
|
return Obj.make(Message.Message, {
|
|
109
114
|
created: new Date().toISOString(),
|
|
110
115
|
sender: { role: 'user' },
|
|
111
|
-
blocks: [...blocks, { _tag: 'text', text: prompt }],
|
|
116
|
+
blocks: typeof prompt === 'string' ? [...blocks, { _tag: 'text', text: prompt }] : [...blocks, ...prompt],
|
|
112
117
|
});
|
|
113
|
-
});
|
|
118
|
+
}).pipe(Effect.withSpan('formatUserPrompt'));
|
|
114
119
|
|
|
115
120
|
const gatherObjectVersions = (messages: Message.Message[]): Map<ObjectId, ObjectVersion> => {
|
|
116
121
|
const artifactIds = new Map<ObjectId, ObjectVersion>();
|
|
@@ -131,7 +136,7 @@ const createArtifactUpdateBlock = (
|
|
|
131
136
|
return {
|
|
132
137
|
_tag: 'text',
|
|
133
138
|
// TODO(dmaretskyi): Does this need to be a special content-block?
|
|
134
|
-
disposition: '
|
|
139
|
+
disposition: 'synthetic',
|
|
135
140
|
text: trim`
|
|
136
141
|
The following artifacts have been updated since the last message:
|
|
137
142
|
${[...artifactDiff.entries()]
|
package/src/session/index.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"conversations":[{"parameters":{"model":"@anthropic/claude-opus-4-6","stream":true,"tools":[]},"prompt":{"content":[{"role":"user","content":"Hello world!","options":{"anthropic":{"cacheControl":{"ttl":"5m","type":"ephemeral"}}}}]},"response":[{"type":"response-metadata","id":"msg_01P4EFfYrn2XLAaSd6uaAwEe","modelId":"claude-opus-4-6","timestamp":"1970-01-01T00:00:00.000Z","metadata":{}},{"type":"reasoning-start","id":"0","metadata":{}},{"type":"reasoning-delta","id":"0","delta":"The","metadata":{}},{"type":"reasoning-delta","id":"0","delta":" user is saying \"Hello world!\" - a classic greeting. I'll respond in a friendly way.","metadata":{}},{"type":"reasoning-delta","id":"0","delta":"","metadata":{}},{"type":"reasoning-delta","id":"0","delta":"","metadata":{"anthropic":{"type":"thinking","signature":"EpICClkIDRgCKkD/kOgik1cgXVWa8rx+X6LFo9HvEBwZ7hEthnH1/FoiWiE//6BCJe4yobp2eUQ59wsNovlHzvu42pvDz+HrqdXfMg9jbGF1ZGUtb3B1cy00LTY4ABIMVgmAeJGtdlGLI9xhGgzKg78+pGfELSb0yJQiMI/HgJQKbergs7rT4xclgyLM9N/xxHsDdCAY9KUaeEIC3RZR84UAmT5sbfJNA1iviCpnQXuNeYdJDLcmfTityQm+c0fKlzUJ4glWpeLGfc4UiSqUbMk224KJ9U49hylck4vS+bx9qQDztEhnLfyRjuNm2v1p7e3UDxT0AeouZWl9O6mgWbezLG+B06hL9nm7PG8vd4jj8Gwo3RgB"}}},{"type":"reasoning-end","id":"0","metadata":{}},{"type":"text-start","id":"1","metadata":{}},{"type":"text-delta","id":"1","delta":"Hello! 👋 Welcome! How can I help you today? Whether you have","metadata":{}},{"type":"text-delta","id":"1","delta":" questions, need assistance with something, or just want to chat, I'm here for you. 😊","metadata":{}},{"type":"text-end","id":"1","metadata":{}},{"type":"finish","reason":"stop","usage":{"inputTokens":10,"outputTokens":80,"totalTokens":90},"metadata":{"anthropic":{"usage":{"cache_creation":{"ephemeral_1h_input_tokens":0,"ephemeral_5m_input_tokens":0},"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"input_tokens":10,"output_tokens":9,"server_tool_use":null,"service_tier":"standard"}}}}]},{"parameters":{"model":"@anthropic/claude-opus-4-6","stream":true,"tools":[{"name":"Calculator","description":"Basic calculator tool","inputSchema":{"type":"object","required":["input"],"properties":{"input":{"type":"string","description":"The calculation to perform."}},"additionalProperties":false}}]},"prompt":{"content":[{"role":"user","content":"What is 10 + 30?","options":{"anthropic":{"cacheControl":{"ttl":"5m","type":"ephemeral"}}}}]},"response":[{"type":"response-metadata","id":"msg_01Tiw1p1D6XEuQVk2bAxrGTn","modelId":"claude-opus-4-6","timestamp":"1970-01-01T00:00:00.000Z","metadata":{}},{"type":"reasoning-start","id":"0","metadata":{}},{"type":"reasoning-delta","id":"0","delta":"The","metadata":{}},{"type":"reasoning-delta","id":"0","delta":" user wants to calculate 10 + 30.","metadata":{}},{"type":"reasoning-delta","id":"0","delta":"","metadata":{"anthropic":{"type":"thinking","signature":"Et8BClkIDRgCKkB/0K0xQQQoenGVXh0VGAdSnkIX3gjXTelz+K0GBhpvk5FcfTPrgKU5HivTbsmhgLGs2LUMRc2mO/YcVzMMzqJqMg9jbGF1ZGUtb3B1cy00LTY4ABIMjxj4INjd+yZEsnEgGgwh2O9IY8I3CzpgM7siMCmsq9Vx4CquyYUx5D16IaDEyJSziOp/Lmzv45pGPfal+63iVnH2fPCHdd147EFgbCo0U0V5wQb1Ys9h6NU53sdkaZ8heyTJ3ZHIPZ1U3X0BmRKC40w34VJ9o8TCbQZwFjY6l5PRPxgB"}}},{"type":"reasoning-end","id":"0","metadata":{}},{"type":"tool-params-start","id":"toolu_01MjKitXaVxMmP53UKeVQDnY","name":"Calculator","providerExecuted":false,"metadata":{}},{"type":"tool-params-delta","id":"toolu_01MjKitXaVxMmP53UKeVQDnY","delta":"","metadata":{}},{"type":"tool-params-delta","id":"toolu_01MjKitXaVxMmP53UKeVQDnY","delta":"{\"inpu","metadata":{}},{"type":"tool-params-delta","id":"toolu_01MjKitXaVxMmP53UKeVQDnY","delta":"t\": ","metadata":{}},{"type":"tool-params-delta","id":"toolu_01MjKitXaVxMmP53UKeVQDnY","delta":"\"10 + ","metadata":{}},{"type":"tool-params-delta","id":"toolu_01MjKitXaVxMmP53UKeVQDnY","delta":"30\"}","metadata":{}},{"type":"tool-params-end","id":"toolu_01MjKitXaVxMmP53UKeVQDnY","metadata":{}},{"type":"finish","reason":"tool-calls","usage":{"inputTokens":578,"outputTokens":83,"totalTokens":661},"metadata":{"anthropic":{"usage":{"cache_creation":{"ephemeral_1h_input_tokens":0,"ephemeral_5m_input_tokens":0},"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"input_tokens":578,"output_tokens":9,"server_tool_use":null,"service_tier":"standard"}}}}]},{"parameters":{"model":"@anthropic/claude-opus-4-6","stream":true,"tools":[{"name":"Calculator","description":"Basic calculator tool","inputSchema":{"type":"object","required":["input"],"properties":{"input":{"type":"string","description":"The calculation to perform."}},"additionalProperties":false}}]},"prompt":{"content":[{"role":"user","content":"What is 10 + 30?","options":{}},{"role":"assistant","content":[{"type":"reasoning","text":"The user wants to calculate 10 + 30.","options":{}},{"type":"tool-call","id":"toolu_01MjKitXaVxMmP53UKeVQDnY","name":"Calculator","params":{"input":"10 + 30"},"providerExecuted":false,"options":{}}],"options":{}},{"role":"tool","content":[{"type":"tool-result","id":"toolu_01MjKitXaVxMmP53UKeVQDnY","name":"Calculator","isFailure":false,"result":{"result":40},"providerExecuted":false,"options":{}}],"options":{"anthropic":{"cacheControl":{"ttl":"5m","type":"ephemeral"}}}}]},"response":[{"type":"response-metadata","id":"msg_016uWLkUCfQZ6mGvDGXoKvSe","modelId":"claude-opus-4-6","timestamp":"1970-01-01T00:00:00.000Z","metadata":{}},{"type":"text-start","id":"0","metadata":{}},{"type":"text-delta","id":"0","delta":"10","metadata":{}},{"type":"text-delta","id":"0","delta":" + 30 = **40**.","metadata":{}},{"type":"text-end","id":"0","metadata":{}},{"type":"finish","reason":"stop","usage":{"inputTokens":650,"outputTokens":13,"totalTokens":663},"metadata":{"anthropic":{"usage":{"cache_creation":{"ephemeral_1h_input_tokens":0,"ephemeral_5m_input_tokens":0},"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"input_tokens":650,"output_tokens":1,"server_tool_use":null,"service_tier":"standard"}}}}]},{"parameters":{"model":"@anthropic/claude-opus-4-6","stream":true,"tools":[{"name":"Calculator","description":"Basic calculator tool","inputSchema":{"type":"object","required":["input"],"properties":{"input":{"type":"string","description":"The calculation to perform."}},"additionalProperties":false}}]},"prompt":{"content":[{"role":"user","content":"I am testing error handling in tool paramter parsing. I want you to call the calculator tool but omit the input parameter to intentionally differ from the tool schema.","options":{"anthropic":{"cacheControl":{"ttl":"5m","type":"ephemeral"}}}}]},"response":[{"type":"response-metadata","id":"msg_01XDAKUT19TrSEueFFq4KJNN","modelId":"claude-opus-4-6","timestamp":"1970-01-01T00:00:00.000Z","metadata":{}},{"type":"reasoning-start","id":"0","metadata":{}},{"type":"reasoning-delta","id":"0","delta":"The user is asking me to intentionally call the Calculator tool without providing the required \"","metadata":{}},{"type":"reasoning-delta","id":"0","delta":"input\" parameter to test error handling. They want to see what happens when a required parameter is omitted.\n\nI should be","metadata":{}},{"type":"reasoning-delta","id":"0","delta":" transparent about this. The \"input\" parameter is marked as \"required\" in the schema","metadata":{}},{"type":"reasoning-delta","id":"0","delta":". Let me attempt the call as the user requests, omitting the required","metadata":{}},{"type":"reasoning-delta","id":"0","delta":" parameter, to help them test error handling.","metadata":{}},{"type":"reasoning-delta","id":"0","delta":"","metadata":{"anthropic":{"type":"thinking","signature":"EtsEClkIDRgCKkAX2ymsRtz1YoTibcGufK2UrveSRjyGaR8voyX9fdgYa1R/D34pdZw5MFbt5ju52GDm9S8sRTeM71WxMuzN+nC0Mg9jbGF1ZGUtb3B1cy00LTY4ABIM3UiIvuTf53XoYDhAGgwUgDabFIahkO3RmhQiMEo9KTbcz0KD+SM3wYYuJrPB6N1DE1bihQPTIcbsrPnTljVmYBpTcEAR+u7qaTVkbCqvA7gcGvE9JjfVi8j6ChFOQUJW7S3evbtkfr47FmEKgkNdKtabAe/b3nefFYIF6Hojn+LfQdFRnRHfB6iOoXT2/CUWCs1Isv0ETjgAFvKteDJB0biUC81luyCg00egHkySOFGA0Frf7BnDEg3MwXz1opK1D6+HDF6dCkHMDOtL0dkTslV7rZej/iEJigvHbVzoCZ47DWVFitZ/DUqpIn54Z1TPH+m+EyLPCws4yUgzIUy7z/JH51xAb/u1hteAhROcXKS+OrIbGrTIVBVlwUaXxKKL8pT5F30iHdGKifso1HDdoR1Gm1qwoUtONJh0SvyW6ti3zjDMHN4jAG3YsvfXYn0rGGJ/Is2hKmvz+ETEB+9hYTPhDjdpf1VMpn7YYoicUIua3FTYGXvs78cIEqYzbanebT0L88VRo/ZkB+rxRsf6EcAYQjeHX+motmzL7Xo9hKHZCMTuZLJbLd84XcNmnb/Vfrfz3jw/Znu9MW0ed2DyLyqu465mmEOjNteRq0wF/USjFB8F1p0CF/P3kjL5KbbqUK5NTqi/KoZt5MWcsp7lwzdZYdffINteTJ83R6ExGAE="}}},{"type":"reasoning-end","id":"0","metadata":{}},{"type":"text-start","id":"1","metadata":{}},{"type":"text-delta","id":"1","delta":"I understand you want to test error handling by intent","metadata":{}},{"type":"text-delta","id":"1","delta":"ionally making a malformed tool call. I'll attempt to call the Calculator tool without the required","metadata":{}},{"type":"text-delta","id":"1","delta":" `input` parameter as you've requested:","metadata":{}},{"type":"text-end","id":"1","metadata":{}},{"type":"tool-params-start","id":"toolu_01EN5ueREDjY2Dkn4DtQT98p","name":"Calculator","providerExecuted":false,"metadata":{}},{"type":"tool-params-delta","id":"toolu_01EN5ueREDjY2Dkn4DtQT98p","delta":"","metadata":{}},{"type":"tool-params-end","id":"toolu_01EN5ueREDjY2Dkn4DtQT98p","metadata":{}}]},{"parameters":{"model":"@anthropic/claude-opus-4-6","stream":true,"tools":[{"name":"Calculator","description":"Basic calculator tool","inputSchema":{"type":"object","required":["input"],"properties":{"input":{"type":"string","description":"The calculation to perform."}},"additionalProperties":false}}]},"prompt":{"content":[{"role":"user","content":"I am testing error handling in tool paramter parsing. I want you to call the calculator tool but omit the input parameter to intentionally differ from the tool schema.","options":{}},{"role":"assistant","content":[{"type":"reasoning","text":"The user is asking me to intentionally call the Calculator tool without providing the required \"input\" parameter to test error handling. They want to see what happens when a required parameter is omitted.\n\nI should be transparent about this. The \"input\" parameter is marked as \"required\" in the schema. Let me attempt the call as the user requests, omitting the required parameter, to help them test error handling.","options":{}},{"type":"text","text":"I understand you want to test error handling by intentionally making a malformed tool call. I'll attempt to call the Calculator tool without the required `input` parameter as you've requested:","options":{}},{"type":"tool-call","id":"toolu_01EN5ueREDjY2Dkn4DtQT98p","name":"Calculator","params":{},"providerExecuted":false,"options":{}}],"options":{}},{"role":"tool","content":[{"type":"tool-result","id":"toolu_01EN5ueREDjY2Dkn4DtQT98p","name":"Calculator","isFailure":true,"result":"MalformedOutput: { \"module\": \"Toolkit\", \"method\": \"Calculator.handle\", \"description\": \"Failed to decode tool call parameters for tool 'Calculator' from:\\n'{}'\", \"cause\": { readonly input: string }\n└─ [\"input\"]\n └─ is missing }\ncaused by:\nParseError: { readonly input: string }\n└─ [\"input\"]\n └─ is missing","providerExecuted":false,"options":{}}],"options":{"anthropic":{"cacheControl":{"ttl":"5m","type":"ephemeral"}}}}]},"response":[{"type":"response-metadata","id":"msg_01H2AnoBfNtCYSMVrB9EofxM","modelId":"claude-opus-4-6","timestamp":"1970-01-01T00:00:00.000Z","metadata":{}},{"type":"reasoning-start","id":"0","metadata":{}},{"type":"reasoning-delta","id":"0","delta":"The error","metadata":{}},{"type":"reasoning-delta","id":"0","delta":" was returned as expected. Let me explain what happened.","metadata":{}},{"type":"reasoning-delta","id":"0","delta":"","metadata":{"anthropic":{"type":"thinking","signature":"EvwBClkIDRgCKkCwoArrVhufw9O5jGNvlEhPLfP86nuapk2Sn3w7HQPwA6x/ZDavxvxNApMetymuM474yxHB+NZANvov3igozby0Mg9jbGF1ZGUtb3B1cy00LTY4ABIMO0f4i8xYIEfyqjvbGgyTlNkCKKfVpWC42MkiMDyCKZwXLycBfZPby82k9IK+I/jyDYQ1tl32IaSDXneYK9iFqZf0hwUZW/qcivZKWSpRp1Kx07laulxgxFuOuSq4eatbyLPKbwFnPHJhD537B6Q8sU5vq6IhwtasW0ahelaItDeaDp1h/QNeP8gjaqyG2o98UnYi6BaAOLQT9NW2q6fEGAE="}}},{"type":"reasoning-end","id":"0","metadata":{}},{"type":"text-start","id":"1","metadata":{}},{"type":"text-delta","id":"1","delta":"As expected, the call failed and returned a **parse error**. Here's a","metadata":{}},{"type":"text-delta","id":"1","delta":" breakdown of what happened:\n\n1. **What I did:** Called the `Calculator` tool with an","metadata":{}},{"type":"text-delta","id":"1","delta":" empty parameter set `{}`, omitting the required `input` parameter.\n2. **Error","metadata":{}},{"type":"text-delta","id":"1","delta":" returned:** `MalformedOutput` — The system detected that the tool call parameters","metadata":{}},{"type":"text-delta","id":"1","delta":" failed to decode because the required `input` field (of type `string`) **","metadata":{}},{"type":"text-delta","id":"1","delta":"is missing**.\n3. **Error chain:** The root cause is a `ParseError` confirming that the schema validation","metadata":{}},{"type":"text-delta","id":"1","delta":" caught the missing required field at path `[\"input\"]`.\n\nThis","metadata":{}},{"type":"text-delta","id":"1","delta":" shows that the tool parameter parsing correctly validates against the defined JSON","metadata":{}},{"type":"text-delta","id":"1","delta":" schema and rejects calls that don't include all required parameters. The error","metadata":{}},{"type":"text-delta","id":"1","delta":" message is quite descriptive, pointing to exactly which","metadata":{}},{"type":"text-delta","id":"1","delta":" field is missing and what type it expected. \n\nWould","metadata":{}},{"type":"text-delta","id":"1","delta":" you like to test any other error handling scenarios?","metadata":{}},{"type":"text-end","id":"1","metadata":{}},{"type":"finish","reason":"stop","usage":{"inputTokens":809,"outputTokens":222,"totalTokens":1031},"metadata":{"anthropic":{"usage":{"cache_creation":{"ephemeral_1h_input_tokens":0,"ephemeral_5m_input_tokens":0},"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"input_tokens":809,"output_tokens":9,"server_tool_use":null,"service_tier":"standard"}}}}]},{"parameters":{"model":"@anthropic/claude-opus-4-6","stream":false,"tools":[]},"prompt":{"content":[{"role":"system","content":"<instructions>\n You are an agent that summarizes conversations.\n You will be given a conversation and you will need to summarize it to compact context.\n Your summary will be used by AI model to continue the conversation without seeing the original messages.\n Remove unnecessary details and focus on the most important information.\n Keep user requests, method of action, and progress.\n Keep the important objects and references in original format.\n It is very important you maintain unchanged ECHO DXNs and IDs of the objects.\n Output only the summary.\n</instructions>\n\n<example_output>\n Processing a flight booking confirmation email. The user requested a round-trip flight from Warsaw to Barcelona for March 15–22, 2026.\n\n Action taken:\n - Found existing booking object `dxn:echo:@:01KHZWKQ9HPJYG147HV7CP5ARX` (type `dxn:echo:@:01KHXAMH4F3V94RCYC7P7M2H0C` / `com.example.type.flight-booking`) matching confirmation code ABC123.\n - Updated the booking status from \"pending\" to \"confirmed\".\n - Added flight details: Outbound WAW→BCN Mar 15 08:30, Return BCN→WAW Mar 22 14:15, carrier LOT Polish Airlines.\n - Stored passenger info and seat assignments in notes.\n\n Booking details preserved: Confirmation ABC123, total 1,240 PLN, booked 2026-02-18, airline LOT Polish Airlines, flight numbers LO391/LO392.\n\n Status enum mapping for the booking schema: pending=Awaiting payment, confirmed=Booked, cancelled=Cancelled, completed=Flown.\n</example_output>\n\nTASK: Reply with the summary of the prior conversation.","options":{}},{"role":"user","content":"How many apples are in the basket?","options":{}},{"role":"assistant","content":"There are 10 apples in the basket.","options":{}},{"role":"user","content":"<instructions>\n You are an agent that summarizes conversations.\n You will be given a conversation and you will need to summarize it to compact context.\n Your summary will be used by AI model to continue the conversation without seeing the original messages.\n Remove unnecessary details and focus on the most important information.\n Keep user requests, method of action, and progress.\n Keep the important objects and references in original format.\n It is very important you maintain unchanged ECHO DXNs and IDs of the objects.\n Output only the summary.\n</instructions>\n\n<example_output>\n Processing a flight booking confirmation email. The user requested a round-trip flight from Warsaw to Barcelona for March 15–22, 2026.\n\n Action taken:\n - Found existing booking object `dxn:echo:@:01KHZWKQ9HPJYG147HV7CP5ARX` (type `dxn:echo:@:01KHXAMH4F3V94RCYC7P7M2H0C` / `com.example.type.flight-booking`) matching confirmation code ABC123.\n - Updated the booking status from \"pending\" to \"confirmed\".\n - Added flight details: Outbound WAW→BCN Mar 15 08:30, Return BCN→WAW Mar 22 14:15, carrier LOT Polish Airlines.\n - Stored passenger info and seat assignments in notes.\n\n Booking details preserved: Confirmation ABC123, total 1,240 PLN, booked 2026-02-18, airline LOT Polish Airlines, flight numbers LO391/LO392.\n\n Status enum mapping for the booking schema: pending=Awaiting payment, confirmed=Booked, cancelled=Cancelled, completed=Flown.\n</example_output>\n\nTASK: Reply with the summary of the prior conversation.","options":{}}]},"response":[{"type":"response-metadata","id":"msg_013JQyMpNyup8yd9gfQtz1sK","modelId":"claude-opus-4-6","timestamp":"1970-01-01T00:00:00.000Z","metadata":{}},{"type":"reasoning","text":"The conversation is very simple - the user asked how many apples are in the basket, and the assistant answered 10. There are no ECHO DXNs, no complex objects, and no real context to preserve. This appears to be a trivial exchange with no prior context or tools involved.","metadata":{"anthropic":{"type":"thinking","signature":"EsoDClkIDRgCKkATKz5csAkAGkfvuEctWM4RDkW59XDzgRDBqVJSoUkrn7sH98NL6X4FerfTUJbq3YrYUxUwj2IjzXTI27XlVqc6Mg9jbGF1ZGUtb3B1cy00LTY4ABIMT/tDfruFSjlciBFYGgyTdl8IxDG9mzlTn5UiMFMOqm36jmi4HNgGu6HR4mwonVPi8KhcOF7flqctd56f4V11qOMTiaX/P9f1rZpB0yqeAlZX160VMP2VXB7IlmZWKlJZBAI3gMIs3ef7s1b+mKSSJf20F4wpg1ECrPdsnnIciHQVKxCc3qoTNnGuwff7C4U5O5s9SDNVhEMNdW8fSy5PAkFPPP/XH7Seac6RzDAIT4aJvRA2UwhqjvDwJszwZQl6Xb7Ng1fsGlAu2ywWBjRzKuoJDJCBySfrxGfjl5cH/Jrg80f9Pp2QHJgIYoTNNtQtB7GS3i1btjNp/N/TsKMf3so5iK2FQ6qtl5Ot9H9qjbYhTRq23zKQnkUkav27evOpE5kSOittzJ3MdblXMXhO09SvJ69n6la0MSIDm50XVFuLDe6819UeGI4LE5S0TQj8bM43n0gk+Z9omi6UAw8JjltCKkaBp5ws6pOozbQYAQ=="}}},{"type":"text","text":"The user asked how many apples are in the basket. The assistant responded that there are 10 apples in the basket. No additional context, objects, or references were involved.","metadata":{}},{"type":"finish","reason":"stop","usage":{"inputTokens":896,"outputTokens":119,"totalTokens":1015,"cachedInputTokens":0},"metadata":{"anthropic":{"usage":{"cache_creation":{"ephemeral_1h_input_tokens":0,"ephemeral_5m_input_tokens":0},"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"input_tokens":896,"output_tokens":119,"server_tool_use":null,"service_tier":"standard"}}}}]},{"parameters":{"model":"@anthropic/claude-opus-4-6","stream":true,"tools":[]},"prompt":{"content":[{"role":"assistant","content":"This is the continuation of a conversation that was compacted to preserve context-window space. Summary of what happened in this conversation previously: <summary>The user asked how many apples are in the basket. The assistant responded that there are 10 apples in the basket. No additional context, objects, or references were involved.</summary>","options":{}},{"role":"user","content":"What did we talk about?","options":{"anthropic":{"cacheControl":{"ttl":"5m","type":"ephemeral"}}}}]},"response":[{"type":"response-metadata","id":"msg_01BWTgasX7BDFvGG5Zp7YLjq","modelId":"claude-opus-4-6","timestamp":"1970-01-01T00:00:00.000Z","metadata":{}},{"type":"reasoning-start","id":"0","metadata":{}},{"type":"reasoning-delta","id":"0","delta":"The user is asking me to recall what we talked about. Based on the summary provided, we discussed","metadata":{}},{"type":"reasoning-delta","id":"0","delta":" how many apples are in a basket, and I told them there are 10 apples in the basket.","metadata":{}},{"type":"reasoning-delta","id":"0","delta":"","metadata":{"anthropic":{"type":"thinking","signature":"EvECClkIDRgCKkASmeuhdK5nBIprAsBq/0ChahRLAcN/Jh26xQdhMZjSsojjx5UoHW21RiuAHCzVLIvt0E/4fNvj7qhOZXzyhNpPMg9jbGF1ZGUtb3B1cy00LTY4ABIMKSjzFmDf3YdferaTGgwKZDXHIy/bxUiq+BQiMHKqTYVUgDcsD1R9OJWF/fKpB2ko0dBkdb/dd5spULoBmqZvFxmOUAvQz+U0OUEToSrFAWa0zySqK5E/R1ZZ0p75Vf28ONof2AMWDCuNT6A35i8ieabC8YHTh3lwgQyaoljpHVkY4uRKqYzUv7t0XBTeAr3Aduq7U+Lmta2+P7Y/oovoOhtfOjADeywq9/PrpCJONwMSU+jctKGfHaln6aoRn1XnIBAiCiUABYCeS9CzXbVTVAOZBQxgmz2Jw5rJfe/EUQfplrcqa3rXDlUjZ6/DTf/YBLIDeCeZ2gpZbnSTIP+7v9mRiAvWlDQfGqM+2KJ/2EorqdD+GAE="}}},{"type":"reasoning-end","id":"0","metadata":{}},{"type":"text-start","id":"1","metadata":{}},{"type":"text-delta","id":"1","delta":"Based","metadata":{}},{"type":"text-delta","id":"1","delta":" on our previous conversation, you asked me how many apples are in a basket, and I told you there are **10 apples** in the basket.","metadata":{}},{"type":"text-delta","id":"1","delta":" That's all we discussed!","metadata":{}},{"type":"text-end","id":"1","metadata":{}},{"type":"finish","reason":"stop","usage":{"inputTokens":98,"outputTokens":103,"totalTokens":201},"metadata":{"anthropic":{"usage":{"cache_creation":{"ephemeral_1h_input_tokens":0,"ephemeral_5m_input_tokens":0},"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"input_tokens":98,"output_tokens":28,"server_tool_use":null,"service_tier":"standard"}}}}]}]}
|
|
@@ -4,8 +4,6 @@
|
|
|
4
4
|
|
|
5
5
|
import type * as AiError from '@effect/ai/AiError';
|
|
6
6
|
import * as LanguageModel from '@effect/ai/LanguageModel';
|
|
7
|
-
import type * as Tool from '@effect/ai/Tool';
|
|
8
|
-
import type * as Toolkit from '@effect/ai/Toolkit';
|
|
9
7
|
import * as Array from 'effect/Array';
|
|
10
8
|
import * as Chunk from 'effect/Chunk';
|
|
11
9
|
import * as Effect from 'effect/Effect';
|
|
@@ -19,14 +17,14 @@ import {
|
|
|
19
17
|
AiSummarizer,
|
|
20
18
|
type AiToolNotFoundError,
|
|
21
19
|
callTool,
|
|
20
|
+
type OpaqueToolkit,
|
|
22
21
|
type PromptPreprocessingError,
|
|
23
22
|
type ToolExecutionService,
|
|
24
23
|
type ToolResolverService,
|
|
25
24
|
withoutToolCallParising,
|
|
26
25
|
} from '@dxos/ai';
|
|
27
|
-
import { type Blueprint } from '@dxos/
|
|
28
|
-
import { Obj } from '@dxos/echo';
|
|
29
|
-
import { type FunctionInvocationService, Trace, TracingService } from '@dxos/functions';
|
|
26
|
+
import { type Blueprint, Trace, Operation, OperationRegistry } from '@dxos/compute';
|
|
27
|
+
import { Database, Obj } from '@dxos/echo';
|
|
30
28
|
import { log } from '@dxos/log';
|
|
31
29
|
import { ContentBlock, Message } from '@dxos/types';
|
|
32
30
|
|
|
@@ -35,21 +33,18 @@ import { CompleteBlock, PartialBlock } from '../tracing';
|
|
|
35
33
|
import { formatSystemPrompt, formatUserPrompt } from './format';
|
|
36
34
|
import { GenerationObserver } from './observer';
|
|
37
35
|
|
|
38
|
-
export type
|
|
36
|
+
export type AiRequestRunError = AiError.AiError | PromptPreprocessingError | AiToolNotFoundError | AiAssistantError;
|
|
39
37
|
|
|
40
|
-
export type
|
|
38
|
+
export type AiRequestRunRequirements =
|
|
41
39
|
| LanguageModel.LanguageModel
|
|
42
40
|
| ToolExecutionService
|
|
43
41
|
| ToolResolverService
|
|
44
|
-
|
|
|
45
|
-
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
* New code should use Trace.TraceService instead.
|
|
49
|
-
*/
|
|
50
|
-
| TracingService;
|
|
42
|
+
| Database.Service
|
|
43
|
+
| Operation.Service
|
|
44
|
+
| OperationRegistry.Service
|
|
45
|
+
| Trace.TraceService;
|
|
51
46
|
|
|
52
|
-
export type
|
|
47
|
+
export type AiRequestOptions = {
|
|
53
48
|
/**
|
|
54
49
|
* Summarize before executing the prompt if the existing history exceeds this threshold.
|
|
55
50
|
*/
|
|
@@ -64,30 +59,30 @@ export type AiSessionOptions = {
|
|
|
64
59
|
onOutput?: (message: Message.Message) => Effect.Effect<void, never, never>;
|
|
65
60
|
};
|
|
66
61
|
|
|
67
|
-
export type
|
|
68
|
-
prompt: string;
|
|
62
|
+
export type AiRequestRunProps<R = never> = {
|
|
63
|
+
prompt: string | ContentBlock.Any[];
|
|
69
64
|
// TODO(wittjosiah): Rename to systemPrompt.
|
|
70
65
|
system?: string;
|
|
71
66
|
history?: Message.Message[];
|
|
72
67
|
objects?: Obj.Unknown[];
|
|
73
68
|
blueprints?: readonly Blueprint.Blueprint[];
|
|
74
|
-
toolkit?:
|
|
69
|
+
toolkit?: OpaqueToolkit.OpaqueToolkit<R>;
|
|
75
70
|
};
|
|
76
71
|
|
|
77
|
-
export type
|
|
78
|
-
prompt: string;
|
|
72
|
+
export type AiRequestBeginProps = {
|
|
73
|
+
prompt: string | ContentBlock.Any[];
|
|
79
74
|
system?: string;
|
|
80
75
|
history?: Message.Message[];
|
|
81
76
|
objects?: Obj.Unknown[];
|
|
82
77
|
blueprints?: readonly Blueprint.Blueprint[];
|
|
83
78
|
};
|
|
84
79
|
|
|
85
|
-
export type
|
|
80
|
+
export type AiRequestTurnProps<R = never> = {
|
|
86
81
|
system: string;
|
|
87
|
-
toolkit?:
|
|
82
|
+
toolkit?: OpaqueToolkit.OpaqueToolkit<R>;
|
|
88
83
|
};
|
|
89
84
|
|
|
90
|
-
export type
|
|
85
|
+
export type AiRequestTurnResult = {
|
|
91
86
|
messages: Message.Message[];
|
|
92
87
|
done: boolean;
|
|
93
88
|
};
|
|
@@ -102,8 +97,7 @@ export type AiSessionTurnResult = {
|
|
|
102
97
|
* Could be run locally in the app or remotely.
|
|
103
98
|
* Could be personal or shared.
|
|
104
99
|
*/
|
|
105
|
-
|
|
106
|
-
export class AiSession {
|
|
100
|
+
export class AiRequest {
|
|
107
101
|
/** Prevents concurrent execution of session. */
|
|
108
102
|
private readonly _semaphore = Effect.runSync(Effect.makeSemaphore(1));
|
|
109
103
|
|
|
@@ -121,7 +115,7 @@ export class AiSession {
|
|
|
121
115
|
private _ended = 0;
|
|
122
116
|
private _toolCalls = 0;
|
|
123
117
|
|
|
124
|
-
constructor(private readonly _options:
|
|
118
|
+
constructor(private readonly _options: AiRequestOptions = {}) {
|
|
125
119
|
this._observer = _options.observer ?? GenerationObserver.noop();
|
|
126
120
|
this._onOutput = _options.onOutput ?? (() => Effect.void);
|
|
127
121
|
}
|
|
@@ -160,6 +154,7 @@ export class AiSession {
|
|
|
160
154
|
Array.takeWhile((_) => _.sender.role === 'assistant'),
|
|
161
155
|
Array.flatMap((_) => _.blocks.filter(ContentBlock.is('toolCall')).map((block) => ({ block, message: _ }))),
|
|
162
156
|
Array.filter((_) => !_.block.providerExecuted),
|
|
157
|
+
Array.reverse,
|
|
163
158
|
);
|
|
164
159
|
|
|
165
160
|
/**
|
|
@@ -172,7 +167,7 @@ export class AiSession {
|
|
|
172
167
|
history = [],
|
|
173
168
|
blueprints = [],
|
|
174
169
|
objects = [],
|
|
175
|
-
}:
|
|
170
|
+
}: AiRequestBeginProps): Effect.Effect<void, AiRequestRunError, AiRequestRunRequirements> =>
|
|
176
171
|
Effect.gen(this, function* () {
|
|
177
172
|
this._started = Date.now();
|
|
178
173
|
this._history = [...history];
|
|
@@ -193,18 +188,18 @@ export class AiSession {
|
|
|
193
188
|
}
|
|
194
189
|
|
|
195
190
|
yield* this._submitMessage(yield* formatUserPrompt({ prompt, history }));
|
|
196
|
-
});
|
|
191
|
+
}).pipe(Effect.withSpan('AiRequest.begin'));
|
|
197
192
|
|
|
198
193
|
/**
|
|
199
194
|
* Execute a single turn: one LLM generation followed by tool execution.
|
|
200
195
|
* The toolkit and system prompt can be updated between turns to reflect context changes (e.g. dynamically enabled blueprints).
|
|
201
196
|
*/
|
|
202
|
-
runAgentTurn = <
|
|
197
|
+
runAgentTurn = <const R = never>({
|
|
203
198
|
system,
|
|
204
|
-
toolkit,
|
|
205
|
-
}:
|
|
199
|
+
toolkit: opaqueToolkit,
|
|
200
|
+
}: AiRequestTurnProps<R>): Effect.Effect<AiRequestTurnResult, AiRequestRunError, AiRequestRunRequirements | R> =>
|
|
206
201
|
Effect.gen(this, function* () {
|
|
207
|
-
log('request', {
|
|
202
|
+
log.info('request', {
|
|
208
203
|
system: { snippet: createSnippet(system), length: system.length },
|
|
209
204
|
pending: this._pending.length,
|
|
210
205
|
history: this._history.length,
|
|
@@ -215,8 +210,10 @@ export class AiSession {
|
|
|
215
210
|
cacheControl: 'ephemeral',
|
|
216
211
|
});
|
|
217
212
|
|
|
213
|
+
const toolkit = opaqueToolkit ? yield* opaqueToolkit.handlers : undefined;
|
|
214
|
+
|
|
218
215
|
const observer = this._observer;
|
|
219
|
-
let currentMessageId: Obj.ID | null = null;
|
|
216
|
+
let currentMessageId: Obj.ID | null = null;
|
|
220
217
|
|
|
221
218
|
const messages = yield* LanguageModel.streamText({
|
|
222
219
|
prompt,
|
|
@@ -263,6 +260,7 @@ export class AiSession {
|
|
|
263
260
|
Stream.runCollect,
|
|
264
261
|
Effect.map(Chunk.toArray),
|
|
265
262
|
);
|
|
263
|
+
log.info('messages', { messages });
|
|
266
264
|
|
|
267
265
|
const toolCalls = this.getToolCalls();
|
|
268
266
|
|
|
@@ -274,29 +272,23 @@ export class AiSession {
|
|
|
274
272
|
}
|
|
275
273
|
|
|
276
274
|
return { messages, done: false };
|
|
277
|
-
});
|
|
275
|
+
}).pipe(Effect.withSpan('AiRequest.runAgentTurn'));
|
|
278
276
|
|
|
279
|
-
runTools = <
|
|
277
|
+
runTools = <const R = never>({
|
|
278
|
+
toolkit: opaqueToolkit,
|
|
279
|
+
}: {
|
|
280
|
+
toolkit?: OpaqueToolkit.OpaqueToolkit<R>;
|
|
281
|
+
}): Effect.Effect<void, AiRequestRunError, AiRequestRunRequirements | R> =>
|
|
280
282
|
Effect.gen(this, function* () {
|
|
283
|
+
const toolkit = opaqueToolkit ? yield* opaqueToolkit.handlers : undefined;
|
|
281
284
|
const toolCalls = this.getToolCalls();
|
|
282
|
-
// TODO(burdon): Retry errors? Write result when each completes individually?
|
|
283
285
|
const toolResults = yield* Effect.forEach(toolCalls, ({ block, message }) => {
|
|
284
286
|
if (!toolkit) {
|
|
285
287
|
throw new Error('No toolkit provided');
|
|
286
288
|
}
|
|
287
|
-
return callTool(toolkit, block)
|
|
288
|
-
Effect.provide(
|
|
289
|
-
TracingService.layerSubframe((context) => ({
|
|
290
|
-
...context,
|
|
291
|
-
parentMessage: message.id,
|
|
292
|
-
toolCallId: block.toolCallId,
|
|
293
|
-
})),
|
|
294
|
-
),
|
|
295
|
-
);
|
|
289
|
+
return callTool(toolkit, block);
|
|
296
290
|
});
|
|
297
291
|
|
|
298
|
-
// TODO(wittjosiah): Sometimes tool error results are added to the queue before the tool agent statuses.
|
|
299
|
-
// TODO(dmaretskyi): Stream tool results one by one.
|
|
300
292
|
yield* this._submitMessage(
|
|
301
293
|
Obj.make(Message.Message, {
|
|
302
294
|
created: new Date().toISOString(),
|
|
@@ -306,18 +298,19 @@ export class AiSession {
|
|
|
306
298
|
);
|
|
307
299
|
|
|
308
300
|
this._toolCalls += toolResults.length;
|
|
309
|
-
});
|
|
301
|
+
}).pipe(Effect.withSpan('AiRequest.runTools'));
|
|
302
|
+
|
|
310
303
|
/**
|
|
311
304
|
* Run a full conversation turn loop. Equivalent to calling `begin()` then `runTurn()` in a loop.
|
|
312
305
|
*/
|
|
313
|
-
run = <
|
|
306
|
+
run = <const R = never>({
|
|
314
307
|
prompt,
|
|
315
308
|
system: systemTemplate,
|
|
316
309
|
history = [],
|
|
317
310
|
objects = [],
|
|
318
311
|
blueprints = [],
|
|
319
312
|
toolkit,
|
|
320
|
-
}:
|
|
313
|
+
}: AiRequestRunProps<R>): Effect.Effect<Message.Message[], AiRequestRunError, AiRequestRunRequirements | R> =>
|
|
321
314
|
Effect.gen(this, function* () {
|
|
322
315
|
yield* this.begin({ prompt, system: systemTemplate, history, objects, blueprints });
|
|
323
316
|
|
|
@@ -333,7 +326,7 @@ export class AiSession {
|
|
|
333
326
|
|
|
334
327
|
log('done', { pending: this._pending.length, duration: this.duration, tools: this._toolCalls });
|
|
335
328
|
return this._pending;
|
|
336
|
-
}).pipe(this._semaphore.withPermits(1), Effect.withSpan('
|
|
329
|
+
}).pipe(this._semaphore.withPermits(1), Effect.withSpan('AiRequest.run'));
|
|
337
330
|
}
|
|
338
331
|
|
|
339
332
|
const createSnippet = (text: string, len = 32) =>
|
package/src/session/toolkit.ts
CHANGED
|
@@ -2,21 +2,21 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import type * as Tool from '@effect/ai/Tool';
|
|
6
5
|
import * as Toolkit from '@effect/ai/Toolkit';
|
|
7
6
|
import * as Effect from 'effect/Effect';
|
|
7
|
+
import * as Layer from 'effect/Layer';
|
|
8
8
|
|
|
9
|
-
import { type AiToolNotFoundError,
|
|
10
|
-
import { type Blueprint } from '@dxos/
|
|
9
|
+
import { type AiToolNotFoundError, OpaqueToolkit, ToolExecutionService, ToolResolverService } from '@dxos/ai';
|
|
10
|
+
import { type Blueprint } from '@dxos/compute';
|
|
11
11
|
import { isTruthy } from '@dxos/util';
|
|
12
12
|
|
|
13
13
|
export type CreateToolkitProps = {
|
|
14
|
-
toolkit?:
|
|
14
|
+
toolkit?: OpaqueToolkit.Any;
|
|
15
15
|
blueprints?: readonly Blueprint.Blueprint[];
|
|
16
16
|
/**
|
|
17
17
|
* Self-contained with handlers toolkits.
|
|
18
18
|
*/
|
|
19
|
-
|
|
19
|
+
opaqueToolkits?: readonly OpaqueToolkit.Any[];
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
/**
|
|
@@ -25,20 +25,23 @@ export type CreateToolkitProps = {
|
|
|
25
25
|
export const createToolkit = ({
|
|
26
26
|
toolkit: toolkitProp,
|
|
27
27
|
blueprints = [],
|
|
28
|
-
|
|
28
|
+
opaqueToolkits = [],
|
|
29
29
|
}: CreateToolkitProps): Effect.Effect<
|
|
30
|
-
|
|
30
|
+
OpaqueToolkit.OpaqueToolkit,
|
|
31
31
|
AiToolNotFoundError,
|
|
32
|
-
ToolResolverService | ToolExecutionService
|
|
32
|
+
ToolResolverService | ToolExecutionService
|
|
33
33
|
> =>
|
|
34
34
|
Effect.gen(function* () {
|
|
35
35
|
const blueprintToolkit = yield* ToolResolverService.resolveToolkit(blueprints.flatMap(({ tools }) => tools));
|
|
36
36
|
const blueprintToolHandler = yield* blueprintToolkit.toContext(ToolExecutionService.handlersFor(blueprintToolkit));
|
|
37
|
-
const
|
|
37
|
+
const opaqueToolkit = OpaqueToolkit.merge(...opaqueToolkits);
|
|
38
38
|
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
const toolkitDefs = [toolkitProp?.toolkit, blueprintToolkit, opaqueToolkit.toolkit].filter(isTruthy);
|
|
40
|
+
const mergedToolkit = Toolkit.merge(...toolkitDefs);
|
|
41
|
+
const combinedHandlerLayer = Layer.mergeAll(
|
|
42
|
+
Layer.succeedContext(blueprintToolHandler),
|
|
43
|
+
toolkitProp?.layer ?? OpaqueToolkit.empty.layer,
|
|
44
|
+
opaqueToolkit.layer,
|
|
45
|
+
);
|
|
46
|
+
return OpaqueToolkit.make(mergedToolkit, combinedHandlerLayer as any) as OpaqueToolkit.OpaqueToolkit;
|
|
47
|
+
}) as Effect.Effect<OpaqueToolkit.OpaqueToolkit, AiToolNotFoundError, ToolResolverService | ToolExecutionService>;
|
|
@@ -56,8 +56,10 @@
|
|
|
56
56
|
|
|
57
57
|
## Response format
|
|
58
58
|
|
|
59
|
+
- NEVER output narration text outside `<status>` tags or the final user-facing answer. Any progress update, transition sentence, or "let me…" lead-in MUST be wrapped in `<status>...</status>`. Violating this is an error.
|
|
59
60
|
- When updating the user about the progress of the work you are doing, put the update in a <status> XML tag.
|
|
60
61
|
- Only when you need to show the result to the user or ask a question use a text block without status tags.
|
|
62
|
+
- After a `</status>` tag, the next output must be either another `<status>` tag, a tool call, or the final user-facing answer — never a transition sentence.
|
|
61
63
|
|
|
62
64
|
<example>
|
|
63
65
|
// reasoning...
|
|
@@ -80,6 +82,15 @@ I found 2 emails from Depot. Let me load their details:
|
|
|
80
82
|
I found **2 emails from Depot**:
|
|
81
83
|
</incorrect_example>
|
|
82
84
|
|
|
85
|
+
Do not do (transition sentence after a status tag, before tool calls):
|
|
86
|
+
|
|
87
|
+
<incorrect_example>
|
|
88
|
+
<status>Doing X</status>
|
|
89
|
+
Let me start by doing X:
|
|
90
|
+
// tool call
|
|
91
|
+
</incorrect_example>
|
|
92
|
+
|
|
93
|
+
- NEVER write a lead-in sentence before a tool call. Use a `<status>` tag instead.
|
|
83
94
|
- Avoid using plain text to tell the user what you are about to do; instead, use status blocks.
|
|
84
95
|
- WRONG: Let me get...
|
|
85
96
|
- CORRECT: <status>Getting...</status>
|
package/src/templates/system.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import defaultsDeep from 'lodash.defaultsdeep';
|
|
6
6
|
|
|
7
7
|
import { type ModelCapabilities } from '@dxos/ai';
|
|
8
|
-
import { Template } from '@dxos/
|
|
8
|
+
import { Template } from '@dxos/compute';
|
|
9
9
|
|
|
10
10
|
import FORMAT from './instructions/format.tpl?raw';
|
|
11
11
|
import SYSTEM from './instructions/system.tpl?raw';
|