@dxos/assistant 0.7.4-df37807 → 0.7.5-feature-compute.4d9d99a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/{chunk-AKP45LQH.mjs → chunk-LVLSJQB3.mjs} +506 -357
- package/dist/lib/browser/chunk-LVLSJQB3.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +17 -17
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +10 -3
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node/{chunk-G6CGWEMO.cjs → chunk-SHOSAIOD.cjs} +507 -362
- package/dist/lib/node/chunk-SHOSAIOD.cjs.map +7 -0
- package/dist/lib/node/index.cjs +42 -42
- package/dist/lib/node/index.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +18 -12
- package/dist/lib/node/testing/index.cjs.map +4 -4
- package/dist/lib/node-esm/{chunk-WUPUPEFB.mjs → chunk-ZLBTRSUY.mjs} +506 -357
- package/dist/lib/node-esm/chunk-ZLBTRSUY.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +17 -17
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +10 -3
- package/dist/lib/node-esm/testing/index.mjs.map +4 -4
- package/dist/types/src/ai-service/client.d.ts +15 -32
- package/dist/types/src/ai-service/client.d.ts.map +1 -1
- package/dist/types/src/ai-service/index.d.ts +2 -1
- package/dist/types/src/ai-service/index.d.ts.map +1 -1
- package/dist/types/src/ai-service/stream.d.ts +34 -0
- package/dist/types/src/ai-service/stream.d.ts.map +1 -0
- package/dist/types/src/ai-service/stream.test.d.ts +2 -0
- package/dist/types/src/ai-service/stream.test.d.ts.map +1 -0
- package/dist/types/src/ai-service/types/index.d.ts +3 -0
- package/dist/types/src/ai-service/types/index.d.ts.map +1 -0
- package/dist/types/src/ai-service/types/message.d.ts +191 -0
- package/dist/types/src/ai-service/types/message.d.ts.map +1 -0
- package/dist/types/src/ai-service/types/schema.d.ts +175 -0
- package/dist/types/src/ai-service/types/schema.d.ts.map +1 -0
- package/dist/types/src/ai-service/util/index.d.ts +2 -0
- package/dist/types/src/ai-service/util/index.d.ts.map +1 -0
- package/dist/types/src/ai-service/{sse.d.ts → util/sse.d.ts} +5 -0
- package/dist/types/src/ai-service/util/sse.d.ts.map +1 -0
- package/dist/types/src/conversation/conversation.d.ts +54 -4
- package/dist/types/src/conversation/conversation.d.ts.map +1 -1
- package/dist/types/src/conversation/types.d.ts +35 -4
- package/dist/types/src/conversation/types.d.ts.map +1 -1
- package/dist/types/src/cypher/combinators.d.ts.map +1 -1
- package/dist/types/src/cypher/parjs.d.ts +1 -1
- package/dist/types/src/cypher/parjs.d.ts.map +1 -1
- package/dist/types/src/cypher/schema.d.ts.map +1 -1
- package/dist/types/src/testing/artifacts.test.d.ts +1 -0
- package/dist/types/src/testing/artifacts.test.d.ts.map +1 -0
- package/dist/types/src/testing/data.d.ts +2 -0
- package/dist/types/src/testing/data.d.ts.map +1 -0
- package/dist/types/src/testing/defs.d.ts +5 -0
- package/dist/types/src/testing/defs.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +1 -0
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/test-data.d.ts +1 -1
- package/dist/types/src/testing/test-data.d.ts.map +1 -1
- package/package.json +20 -18
- package/src/ai-service/client.test.ts +25 -26
- package/src/ai-service/client.ts +29 -177
- package/src/ai-service/index.ts +2 -1
- package/src/ai-service/stream.test.ts +186 -0
- package/src/ai-service/stream.ts +181 -0
- package/src/ai-service/types/index.ts +6 -0
- package/src/ai-service/types/message.ts +147 -0
- package/src/ai-service/types/schema.ts +128 -0
- package/src/ai-service/util/index.ts +5 -0
- package/src/ai-service/{sse.ts → util/sse.ts} +5 -0
- package/src/bin/chat.ts +6 -9
- package/src/conversation/conversation.test.ts +10 -14
- package/src/conversation/conversation.ts +109 -14
- package/src/conversation/types.ts +47 -6
- package/src/cypher/combinators.test.ts +3 -3
- package/src/cypher/combinators.ts +0 -1
- package/src/cypher/execution-plan.test.ts +5 -3
- package/src/cypher/parjs-shims.d.ts +4 -0
- package/src/cypher/parjs.ts +2 -2
- package/src/cypher/query-executor.test.ts +1 -1
- package/src/cypher/schema.ts +0 -1
- package/src/index.ts +1 -1
- package/src/testing/artifacts.test.ts +182 -0
- package/src/testing/data.ts +13 -0
- package/src/testing/defs.ts +8 -0
- package/src/testing/index.ts +1 -0
- package/src/testing/query.test.ts +9 -9
- package/src/testing/test-data.ts +1 -1
- package/vendor/parjs-browser.mjs +4 -0
- package/vendor/parjs-default.mjs +8 -0
- package/dist/lib/browser/chunk-AKP45LQH.mjs.map +0 -7
- package/dist/lib/node/chunk-G6CGWEMO.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-WUPUPEFB.mjs.map +0 -7
- package/dist/types/src/ai-service/schema.d.ts +0 -296
- package/dist/types/src/ai-service/schema.d.ts.map +0 -1
- package/dist/types/src/ai-service/sse.d.ts.map +0 -1
- package/dist/types/src/sanity.test.d.ts +0 -2
- package/dist/types/src/sanity.test.d.ts.map +0 -1
- package/src/ai-service/schema.ts +0 -260
- package/src/sanity.test.ts +0 -9
package/src/ai-service/schema.ts
DELETED
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { Schema as S } from '@effect/schema';
|
|
6
|
-
import { type Brand } from 'effect';
|
|
7
|
-
import { ulid } from 'ulidx';
|
|
8
|
-
|
|
9
|
-
import { JsonSchemaType } from '@dxos/echo-schema';
|
|
10
|
-
import { SpaceId } from '@dxos/keys';
|
|
11
|
-
|
|
12
|
-
// TODO(dmaretskyi): Extract IDs to protocols.
|
|
13
|
-
export const SpaceIdSchema: S.Schema<SpaceId, string> = S.String.pipe(S.filter(SpaceId.isValid));
|
|
14
|
-
export const ObjectIdBrand: unique symbol = Symbol('@dxos/echo/ObjectId');
|
|
15
|
-
const ObjectIdSchema = S.ULID.pipe(S.brand(ObjectIdBrand));
|
|
16
|
-
|
|
17
|
-
export type ObjectId = typeof ObjectIdSchema.Type;
|
|
18
|
-
export const ObjectId: S.SchemaClass<string & Brand.Brand<typeof ObjectIdBrand>, string> & { random(): ObjectId } =
|
|
19
|
-
class extends ObjectIdSchema {
|
|
20
|
-
static random(): ObjectId {
|
|
21
|
-
return ulid() as ObjectId;
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
// TODO(dmaretskyi): Dedup this schema with the one in dxos/edge.
|
|
26
|
-
|
|
27
|
-
export const Space = S.Struct({
|
|
28
|
-
id: SpaceIdSchema,
|
|
29
|
-
});
|
|
30
|
-
export interface Space extends S.Schema.Type<typeof Space> {}
|
|
31
|
-
|
|
32
|
-
export const Thread = S.Struct({
|
|
33
|
-
id: ObjectId,
|
|
34
|
-
spaceId: SpaceIdSchema,
|
|
35
|
-
});
|
|
36
|
-
export interface Thread extends S.Schema.Type<typeof Thread> {}
|
|
37
|
-
|
|
38
|
-
export const MessageRole = S.String.pipe(S.filter((role) => role === 'user' || role === 'assistant'));
|
|
39
|
-
export type MessageRole = S.Schema.Type<typeof MessageRole>;
|
|
40
|
-
|
|
41
|
-
//
|
|
42
|
-
// Message union
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
export const MessageTextContentBlock = S.Struct({
|
|
46
|
-
type: S.Literal('text'),
|
|
47
|
-
text: S.String,
|
|
48
|
-
}).pipe(S.mutable);
|
|
49
|
-
export type MessageTextContentBlock = S.Schema.Type<typeof MessageTextContentBlock>;
|
|
50
|
-
|
|
51
|
-
export const ImageSource = S.Struct({
|
|
52
|
-
type: S.Literal('base64'),
|
|
53
|
-
media_type: S.Literal('image/jpeg', 'image/png', 'image/gif', 'image/webp'),
|
|
54
|
-
data: S.String,
|
|
55
|
-
}).pipe(S.mutable);
|
|
56
|
-
export type ImageSource = S.Schema.Type<typeof ImageSource>;
|
|
57
|
-
|
|
58
|
-
export const MessageImageContentBlock = S.Struct({
|
|
59
|
-
type: S.Literal('image'),
|
|
60
|
-
id: S.optional(S.String),
|
|
61
|
-
source: S.optional(ImageSource),
|
|
62
|
-
}).pipe(S.mutable);
|
|
63
|
-
export type MessageImageContentBlock = S.Schema.Type<typeof MessageImageContentBlock>;
|
|
64
|
-
|
|
65
|
-
export const MessageToolUseContentBlock = S.Struct({
|
|
66
|
-
type: S.Literal('tool_use'),
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Opaque service-defined ID of the tool invocation.
|
|
70
|
-
* Used to match the tool result block.
|
|
71
|
-
*/
|
|
72
|
-
id: S.String,
|
|
73
|
-
/**
|
|
74
|
-
* Tool name.
|
|
75
|
-
*/
|
|
76
|
-
name: S.String,
|
|
77
|
-
input: S.Unknown,
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Used to accumulate the partial tool input JSON in streaming mode.
|
|
81
|
-
*/
|
|
82
|
-
inputJson: S.optional(S.String),
|
|
83
|
-
}).pipe(S.mutable);
|
|
84
|
-
|
|
85
|
-
export const MessageToolResultContentBlock = S.Struct({
|
|
86
|
-
type: S.Literal('tool_result'),
|
|
87
|
-
toolUseId: S.String,
|
|
88
|
-
content: S.String,
|
|
89
|
-
isError: S.optional(S.Boolean),
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
export const MessageContentBlock = S.Union(
|
|
93
|
-
MessageTextContentBlock,
|
|
94
|
-
MessageImageContentBlock,
|
|
95
|
-
MessageToolUseContentBlock,
|
|
96
|
-
MessageToolResultContentBlock,
|
|
97
|
-
);
|
|
98
|
-
export type MessageContentBlock = S.Schema.Type<typeof MessageContentBlock>;
|
|
99
|
-
|
|
100
|
-
//
|
|
101
|
-
//
|
|
102
|
-
//
|
|
103
|
-
|
|
104
|
-
export const Message = S.Struct({
|
|
105
|
-
id: ObjectId,
|
|
106
|
-
threadId: S.optional(ObjectId),
|
|
107
|
-
spaceId: S.optional(SpaceIdSchema),
|
|
108
|
-
|
|
109
|
-
role: MessageRole,
|
|
110
|
-
|
|
111
|
-
content: S.Array(MessageContentBlock).pipe(S.mutable),
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* ID of the message from the foreign provider.
|
|
115
|
-
*/
|
|
116
|
-
// TODO(dmaretskyi): Should be in meta/keys.
|
|
117
|
-
foreignId: S.optional(S.String),
|
|
118
|
-
|
|
119
|
-
// TODO(dmaretskyi): Figure out how to deal with those.
|
|
120
|
-
// created: S.optional(S.DateFromString),
|
|
121
|
-
// updated: S.optional(S.DateFromString),
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
export interface Message extends S.Schema.Type<typeof Message> {}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Message transformed from the database row.
|
|
128
|
-
*/
|
|
129
|
-
export const MessageFromDb = S.Struct({
|
|
130
|
-
...Message.fields,
|
|
131
|
-
content: S.propertySignature(Message.fields.content.pipe((schema) => S.parseJson(schema))).pipe(
|
|
132
|
-
S.fromKey('contentJson'),
|
|
133
|
-
),
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
//
|
|
137
|
-
//
|
|
138
|
-
//
|
|
139
|
-
|
|
140
|
-
export const LLMModel = S.Literal(
|
|
141
|
-
'@hf/nousresearch/hermes-2-pro-mistral-7b',
|
|
142
|
-
'@anthropic/claude-3-5-sonnet-20241022',
|
|
143
|
-
'@anthropic/claude-3-5-haiku-20241022',
|
|
144
|
-
'@ollama/llama-3-2-3b',
|
|
145
|
-
'@ollama/llama-3-1-nemotron-70b-instruct',
|
|
146
|
-
'@ollama/llama-3-1-nemotron-mini-4b-instruct',
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
export type LLMModel = S.Schema.Type<typeof LLMModel>;
|
|
150
|
-
|
|
151
|
-
export const ToolTypes = Object.freeze({
|
|
152
|
-
// TODO(dmaretskyi): Not implemented yet.
|
|
153
|
-
// DatabaseQuery: 'database_query',
|
|
154
|
-
|
|
155
|
-
TextToImage: 'text_to_image',
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
export const LLMTool = S.Struct({
|
|
159
|
-
name: S.String,
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* If the tool is implemented by the service a type should be provided.
|
|
163
|
-
* For user-implemented tools, this field should be omitted.
|
|
164
|
-
* See {@link ToolTypes} for the list of supported types.
|
|
165
|
-
*/
|
|
166
|
-
type: S.optional(S.String),
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Required for user-implemented tools.
|
|
170
|
-
*/
|
|
171
|
-
description: S.optional(S.String),
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Input schema for the tool in the JSON Schema format.
|
|
175
|
-
* Required for user-implemented tools.
|
|
176
|
-
*/
|
|
177
|
-
parameters: S.optional(JsonSchemaType),
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Tool-specific options.
|
|
181
|
-
*/
|
|
182
|
-
options: S.optional(S.Any),
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Javascript function to execute the tool.
|
|
186
|
-
*/
|
|
187
|
-
execute: S.optional(S.Any),
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
export interface LLMTool extends S.Schema.Type<typeof LLMTool> {}
|
|
191
|
-
|
|
192
|
-
//
|
|
193
|
-
//
|
|
194
|
-
//
|
|
195
|
-
|
|
196
|
-
export const GenerateRequest = S.Struct({
|
|
197
|
-
model: LLMModel,
|
|
198
|
-
|
|
199
|
-
spaceId: SpaceIdSchema,
|
|
200
|
-
threadId: ObjectId,
|
|
201
|
-
/**
|
|
202
|
-
* System instructions to the LLM.
|
|
203
|
-
*/
|
|
204
|
-
// TODO(dmaretskyi): Should this be part of the thread?.
|
|
205
|
-
systemPrompt: S.optional(S.String),
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Tools available for the LLM.
|
|
209
|
-
*/
|
|
210
|
-
tools: S.Array(LLMTool).pipe(S.mutable),
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
export interface GenerateRequest extends S.Schema.Type<typeof GenerateRequest> {}
|
|
214
|
-
|
|
215
|
-
export type LLMStopReason = 'tool_use' | 'end_turn';
|
|
216
|
-
|
|
217
|
-
//
|
|
218
|
-
//
|
|
219
|
-
//
|
|
220
|
-
|
|
221
|
-
// TODO(dmaretskyi): Effect schema.
|
|
222
|
-
// TODO(dmaretskyi): Rename GenerationStreamEvent.
|
|
223
|
-
export type ResultStreamEvent =
|
|
224
|
-
| {
|
|
225
|
-
// TODO(dmaretskyi): Normalize types to our schema.
|
|
226
|
-
type: 'message_start';
|
|
227
|
-
message: Omit<Message, 'spaceId' | 'threadId'>;
|
|
228
|
-
}
|
|
229
|
-
| {
|
|
230
|
-
type: 'message_delta';
|
|
231
|
-
delta: {
|
|
232
|
-
stopReason: LLMStopReason;
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
| {
|
|
236
|
-
type: 'message_stop';
|
|
237
|
-
}
|
|
238
|
-
| {
|
|
239
|
-
type: 'content_block_start';
|
|
240
|
-
index: number;
|
|
241
|
-
content: MessageContentBlock;
|
|
242
|
-
}
|
|
243
|
-
| {
|
|
244
|
-
type: 'content_block_delta';
|
|
245
|
-
index: number;
|
|
246
|
-
delta:
|
|
247
|
-
| {
|
|
248
|
-
type: 'text_delta';
|
|
249
|
-
text: string;
|
|
250
|
-
}
|
|
251
|
-
| {
|
|
252
|
-
partial_json: string;
|
|
253
|
-
|
|
254
|
-
type: 'input_json_delta';
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
| {
|
|
258
|
-
type: 'content_block_stop';
|
|
259
|
-
index: number;
|
|
260
|
-
};
|