@dxos/assistant 0.8.2-main.5885341 → 0.8.2-main.5ca3450
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-DEIGOD4U.mjs → chunk-OLO6SVOL.mjs} +21 -21
- package/dist/lib/browser/chunk-OLO6SVOL.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +14 -14
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +23 -27
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node/{chunk-7VH7NMIM.cjs → chunk-CI5Q7FBG.cjs} +6 -6
- package/dist/lib/node/chunk-CI5Q7FBG.cjs.map +7 -0
- package/dist/lib/node/index.cjs +34 -34
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +13 -18
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/lib/node-esm/{chunk-7JI4MDGL.mjs → chunk-Y3SYOFFJ.mjs} +21 -21
- package/dist/lib/node-esm/chunk-Y3SYOFFJ.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +14 -14
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +23 -27
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/ai-service/parser.d.ts.map +1 -1
- package/dist/types/src/ai-service/stream.d.ts.map +1 -1
- package/dist/types/src/ai-service/testing/test-stream.d.ts.map +1 -1
- package/dist/types/src/ai-service/types.d.ts +130 -130
- package/dist/types/src/ai-service/types.d.ts.map +1 -1
- package/dist/types/src/ai-service/util/sse.d.ts.map +1 -1
- package/dist/types/src/conversation/conversation.d.ts.map +1 -1
- package/dist/types/src/conversation/types.d.ts +9 -9
- package/dist/types/src/conversation/types.d.ts.map +1 -1
- package/dist/types/src/cypher/echo-data-source.d.ts.map +1 -1
- package/dist/types/src/cypher/execution-plan.d.ts.map +1 -1
- package/dist/types/src/cypher/parser.d.ts.map +1 -1
- package/dist/types/src/cypher/query-executor.d.ts.map +1 -1
- package/dist/types/src/cypher/schema.d.ts.map +1 -1
- package/dist/types/src/session/session.d.ts +3 -3
- package/dist/types/src/session/session.d.ts.map +1 -1
- package/dist/types/src/testing/logger.d.ts.map +1 -1
- package/dist/types/src/testing/ollama.d.ts.map +1 -1
- package/dist/types/src/testing/query-promts.d.ts +3 -3
- package/dist/types/src/testing/query-promts.d.ts.map +1 -1
- package/dist/types/src/testing/test-data.d.ts +4 -4
- package/dist/types/src/testing/test-data.d.ts.map +1 -1
- package/dist/types/src/testing/test-schema.d.ts +25 -23
- package/dist/types/src/testing/test-schema.d.ts.map +1 -1
- package/dist/types/src/util/trim.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +14 -13
- package/src/ai-service/client.test.ts +5 -5
- package/src/ai-service/ollama-client.ts +7 -7
- package/src/ai-service/types.ts +14 -14
- package/src/conversation/conversation.test.ts +3 -3
- package/src/conversation/types.ts +10 -10
- package/src/cypher/echo-data-source.ts +7 -5
- package/src/session/session.test.ts +22 -16
- package/src/session/session.ts +14 -14
- package/src/testing/artifacts.test.ts +22 -22
- package/src/testing/query-promts.ts +5 -5
- package/src/testing/test-data.ts +4 -4
- package/src/testing/test-schema.ts +27 -28
- package/dist/lib/browser/chunk-DEIGOD4U.mjs.map +0 -7
- package/dist/lib/node/chunk-7VH7NMIM.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-7JI4MDGL.mjs.map +0 -7
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
import { Schema
|
|
2
|
-
|
|
3
|
-
export declare const Contact:
|
|
4
|
-
id:
|
|
5
|
-
name:
|
|
6
|
-
email:
|
|
1
|
+
import { Schema } from 'effect';
|
|
2
|
+
/** @deprecated */
|
|
3
|
+
export declare const Contact: Schema.mutable<Schema.Struct<{
|
|
4
|
+
id: import("@dxos/echo-schema").ObjectIdClass;
|
|
5
|
+
name: Schema.SchemaClass<string, string, never>;
|
|
6
|
+
email: Schema.optional<typeof Schema.String>;
|
|
7
7
|
}>>;
|
|
8
|
-
export interface Contact extends
|
|
8
|
+
export interface Contact extends Schema.Schema.Type<typeof Contact> {
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
/** @deprecated */
|
|
11
|
+
export declare const Project: Schema.mutable<Schema.Struct<{
|
|
12
|
+
id: import("@dxos/echo-schema").ObjectIdClass;
|
|
13
|
+
name: Schema.SchemaClass<string, string, never>;
|
|
14
|
+
description: Schema.optional<typeof Schema.String>;
|
|
14
15
|
}>>;
|
|
15
|
-
export interface Project extends
|
|
16
|
+
export interface Project extends Schema.Schema.Type<typeof Project> {
|
|
16
17
|
}
|
|
17
|
-
export declare const Task:
|
|
18
|
-
id:
|
|
19
|
-
name:
|
|
20
|
-
description:
|
|
18
|
+
export declare const Task: Schema.mutable<Schema.Struct<{
|
|
19
|
+
id: import("@dxos/echo-schema").ObjectIdClass;
|
|
20
|
+
name: Schema.SchemaClass<string, string, never>;
|
|
21
|
+
description: Schema.optional<typeof Schema.String>;
|
|
21
22
|
project: import("@dxos/echo-schema").Ref$<{
|
|
22
23
|
name: string;
|
|
23
24
|
description?: string | undefined;
|
|
@@ -29,22 +30,23 @@ export declare const Task: S.mutable<S.Struct<{
|
|
|
29
30
|
email?: string | undefined;
|
|
30
31
|
}>;
|
|
31
32
|
}>>;
|
|
32
|
-
export interface Task extends
|
|
33
|
+
export interface Task extends Schema.Schema.Type<typeof Task> {
|
|
33
34
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
/** @deprecated */
|
|
36
|
+
export declare const Organization: Schema.mutable<Schema.Struct<{
|
|
37
|
+
id: import("@dxos/echo-schema").ObjectIdClass;
|
|
38
|
+
name: Schema.SchemaClass<string, string, never>;
|
|
39
|
+
projects: Schema.Array$<import("@dxos/echo-schema").Ref$<{
|
|
38
40
|
name: string;
|
|
39
41
|
description?: string | undefined;
|
|
40
42
|
id: string;
|
|
41
43
|
}>>;
|
|
42
|
-
employees:
|
|
44
|
+
employees: Schema.Array$<import("@dxos/echo-schema").Ref$<{
|
|
43
45
|
name: string;
|
|
44
46
|
id: string;
|
|
45
47
|
email?: string | undefined;
|
|
46
48
|
}>>;
|
|
47
49
|
}>>;
|
|
48
|
-
export interface Organization extends
|
|
50
|
+
export interface Organization extends Schema.Schema.Type<typeof Organization> {
|
|
49
51
|
}
|
|
50
52
|
//# sourceMappingURL=test-schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-schema.d.ts","sourceRoot":"","sources":["../../../../src/testing/test-schema.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"test-schema.d.ts","sourceRoot":"","sources":["../../../../src/testing/test-schema.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAMhC,kBAAkB;AAClB,eAAO,MAAM,OAAO;;;;GAahB,CAAC;AACL,MAAM,WAAW,OAAQ,SAAQ,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,OAAO,CAAC;CAAG;AAEtE,kBAAkB;AAClB,eAAO,MAAM,OAAO;;;;GAahB,CAAC;AACL,MAAM,WAAW,OAAQ,SAAQ,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,OAAO,CAAC;CAAG;AAEtE,eAAO,MAAM,IAAI;;;;;;;;;;;;;;GAeb,CAAC;AACL,MAAM,WAAW,IAAK,SAAQ,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC;CAAG;AAEhE,kBAAkB;AAClB,eAAO,MAAM,YAAY;;;;;;;;;;;;;GAcrB,CAAC;AACL,MAAM,WAAW,YAAa,SAAQ,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,YAAY,CAAC;CAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trim.d.ts","sourceRoot":"","sources":["../../../../src/util/trim.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,eAAO,MAAM,IAAI,
|
|
1
|
+
{"version":3,"file":"trim.d.ts","sourceRoot":"","sources":["../../../../src/util/trim.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,eAAO,MAAM,IAAI,GAAI,SAAS,oBAAoB,EAAE,GAAG,QAAQ,GAAG,EAAE,WAMnE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"5.
|
|
1
|
+
{"version":"5.8.3"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/assistant",
|
|
3
|
-
"version": "0.8.2-main.
|
|
3
|
+
"version": "0.8.2-main.5ca3450",
|
|
4
4
|
"description": "Natural language interface to DXOS",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -40,18 +40,19 @@
|
|
|
40
40
|
"parjs": "^1.3.9",
|
|
41
41
|
"parsimmon": "^1.18.1",
|
|
42
42
|
"ulidx": "^2.3.0",
|
|
43
|
-
"@dxos/artifact": "0.8.2-main.
|
|
44
|
-
"@dxos/
|
|
45
|
-
"@dxos/
|
|
46
|
-
"@dxos/
|
|
47
|
-
"@dxos/echo
|
|
48
|
-
"@dxos/
|
|
49
|
-
"@dxos/
|
|
50
|
-
"@dxos/
|
|
51
|
-
"@dxos/
|
|
52
|
-
"@dxos/keys": "0.8.2-main.
|
|
53
|
-
"@dxos/
|
|
54
|
-
"@dxos/
|
|
43
|
+
"@dxos/artifact": "0.8.2-main.5ca3450",
|
|
44
|
+
"@dxos/context": "0.8.2-main.5ca3450",
|
|
45
|
+
"@dxos/debug": "0.8.2-main.5ca3450",
|
|
46
|
+
"@dxos/async": "0.8.2-main.5ca3450",
|
|
47
|
+
"@dxos/echo": "0.8.2-main.5ca3450",
|
|
48
|
+
"@dxos/echo-schema": "0.8.2-main.5ca3450",
|
|
49
|
+
"@dxos/echo-db": "0.8.2-main.5ca3450",
|
|
50
|
+
"@dxos/invariant": "0.8.2-main.5ca3450",
|
|
51
|
+
"@dxos/live-object": "0.8.2-main.5ca3450",
|
|
52
|
+
"@dxos/keys": "0.8.2-main.5ca3450",
|
|
53
|
+
"@dxos/log": "0.8.2-main.5ca3450",
|
|
54
|
+
"@dxos/node-std": "0.8.2-main.5ca3450",
|
|
55
|
+
"@dxos/util": "0.8.2-main.5ca3450"
|
|
55
56
|
},
|
|
56
57
|
"devDependencies": {
|
|
57
58
|
"@types/parsimmon": "^1.10.9",
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Schema
|
|
5
|
+
import { Schema } from 'effect';
|
|
6
6
|
import { test, describe } from 'vitest';
|
|
7
7
|
|
|
8
8
|
import { defineTool, Message, ToolResult, type Tool } from '@dxos/artifact';
|
|
@@ -58,8 +58,8 @@ describe.skip('AI Service Client', () => {
|
|
|
58
58
|
name: 'custodian',
|
|
59
59
|
description: 'Custodian can tell you the password if you say the magic word',
|
|
60
60
|
parameters: toJsonSchema(
|
|
61
|
-
|
|
62
|
-
magicWord:
|
|
61
|
+
Schema.Struct({
|
|
62
|
+
magicWord: Schema.String.annotations({ description: 'The magic word. Should be exactly "pretty please"' }),
|
|
63
63
|
}),
|
|
64
64
|
),
|
|
65
65
|
};
|
|
@@ -194,8 +194,8 @@ describe.skip('Ollama Client', () => {
|
|
|
194
194
|
defineTool('test', {
|
|
195
195
|
name: 'encrypt',
|
|
196
196
|
description: 'Encrypt a message',
|
|
197
|
-
schema:
|
|
198
|
-
message:
|
|
197
|
+
schema: Schema.Struct({
|
|
198
|
+
message: Schema.String.annotations({ description: 'The message to encrypt' }),
|
|
199
199
|
}),
|
|
200
200
|
execute: async ({ message }) => ToolResult.Success(message.split('').reverse().join('')),
|
|
201
201
|
}),
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Schema
|
|
5
|
+
import { Schema } from 'effect';
|
|
6
6
|
|
|
7
7
|
import { type MessageContentBlock, defineTool, type Tool, ToolResult } from '@dxos/artifact';
|
|
8
8
|
import { ObjectId } from '@dxos/echo-schema';
|
|
@@ -388,8 +388,8 @@ const WELL_KNOWN_TOOLS: Record<string, Tool> = {
|
|
|
388
388
|
[ToolTypes.TextToImage]: defineTool('system', {
|
|
389
389
|
name: 'text-to-image',
|
|
390
390
|
description: 'Generate an image from a text prompt',
|
|
391
|
-
schema:
|
|
392
|
-
prompt:
|
|
391
|
+
schema: Schema.Struct({
|
|
392
|
+
prompt: Schema.String.annotations({ description: 'The text prompt describing the image to generate' }),
|
|
393
393
|
}),
|
|
394
394
|
execute: async ({ prompt }) => {
|
|
395
395
|
const image = await fetch(SAMPLE_IMAGE_URL).then(async (res) => Buffer.from(await res.arrayBuffer()));
|
|
@@ -467,15 +467,15 @@ class OllamaDecoderStream extends TransformStream<string, OllamaResponseData> {
|
|
|
467
467
|
}
|
|
468
468
|
}
|
|
469
469
|
|
|
470
|
-
class ModelDoesNotSupportToolsError extends
|
|
470
|
+
class ModelDoesNotSupportToolsError extends Schema.TaggedError<ModelDoesNotSupportToolsError>()(
|
|
471
471
|
'ModelDoesNotSupportToolsError',
|
|
472
472
|
{
|
|
473
|
-
model:
|
|
473
|
+
model: Schema.String,
|
|
474
474
|
},
|
|
475
475
|
) {}
|
|
476
476
|
|
|
477
|
-
class ModelNotFoundError extends
|
|
478
|
-
model:
|
|
477
|
+
class ModelNotFoundError extends Schema.TaggedError<ModelNotFoundError>()('ModelNotFoundError', {
|
|
478
|
+
model: Schema.String,
|
|
479
479
|
}) {}
|
|
480
480
|
|
|
481
481
|
const parseOllamaError = (error: string): Error => {
|
package/src/ai-service/types.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Schema
|
|
5
|
+
import { Schema } from 'effect';
|
|
6
6
|
|
|
7
7
|
import { Tool, Message, type MessageContentBlock } from '@dxos/artifact';
|
|
8
8
|
import { type ObjectId } from '@dxos/echo-schema';
|
|
@@ -11,9 +11,9 @@ import { DEFAULT_EDGE_MODELS, DEFAULT_OLLAMA_MODELS } from './defs';
|
|
|
11
11
|
|
|
12
12
|
export const createArtifactElement = (id: ObjectId) => `<artifact id=${id} />`;
|
|
13
13
|
|
|
14
|
-
export const LLMModel =
|
|
14
|
+
export const LLMModel = Schema.Literal(...DEFAULT_EDGE_MODELS, ...DEFAULT_OLLAMA_MODELS);
|
|
15
15
|
|
|
16
|
-
export type LLMModel =
|
|
16
|
+
export type LLMModel = Schema.Schema.Type<typeof LLMModel>;
|
|
17
17
|
|
|
18
18
|
export const ToolTypes = Object.freeze({
|
|
19
19
|
// TODO(dmaretskyi): Not implemented yet.
|
|
@@ -24,47 +24,47 @@ export const ToolTypes = Object.freeze({
|
|
|
24
24
|
/**
|
|
25
25
|
* Client GPT request.
|
|
26
26
|
*/
|
|
27
|
-
export const GenerateRequest =
|
|
27
|
+
export const GenerateRequest = Schema.Struct({
|
|
28
28
|
/**
|
|
29
29
|
* Preferred model or system default.
|
|
30
30
|
*/
|
|
31
|
-
model:
|
|
31
|
+
model: Schema.optional(LLMModel),
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
34
|
* Tools available for the LLM.
|
|
35
35
|
*/
|
|
36
|
-
tools:
|
|
36
|
+
tools: Schema.optional(Schema.Array(Tool).pipe(Schema.mutable)),
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
39
|
* System instructions to the LLM.
|
|
40
40
|
*/
|
|
41
|
-
systemPrompt:
|
|
41
|
+
systemPrompt: Schema.optional(Schema.String),
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
44
|
* History of messages to include in the context window.
|
|
45
45
|
*/
|
|
46
46
|
// TODO(burdon): Rename messages.
|
|
47
|
-
history:
|
|
47
|
+
history: Schema.optional(Schema.Array(Message)),
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
50
|
* Current request.
|
|
51
51
|
*/
|
|
52
|
-
prompt:
|
|
52
|
+
prompt: Schema.optional(Message),
|
|
53
53
|
});
|
|
54
|
-
export type GenerateRequest =
|
|
54
|
+
export type GenerateRequest = Schema.Schema.Type<typeof GenerateRequest>;
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
57
|
* Non-streaming response.
|
|
58
58
|
*/
|
|
59
|
-
export const GenerateResponse =
|
|
60
|
-
messages:
|
|
59
|
+
export const GenerateResponse = Schema.Struct({
|
|
60
|
+
messages: Schema.Array(Message),
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
63
|
* Number of tokens used in the response.
|
|
64
64
|
*/
|
|
65
|
-
tokenCount:
|
|
65
|
+
tokenCount: Schema.optional(Schema.Number),
|
|
66
66
|
});
|
|
67
|
-
export type GenerateResponse =
|
|
67
|
+
export type GenerateResponse = Schema.Schema.Type<typeof GenerateResponse>;
|
|
68
68
|
|
|
69
69
|
/**
|
|
70
70
|
* Server-Sent Events (SSE) stream from the AI service.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Schema
|
|
5
|
+
import { Schema } from 'effect';
|
|
6
6
|
import { describe, test } from 'vitest';
|
|
7
7
|
|
|
8
8
|
import { createUserMessage, defineTool, ToolResult } from '@dxos/artifact';
|
|
@@ -40,8 +40,8 @@ describe.skip('Conversation tests', () => {
|
|
|
40
40
|
const custodian = defineTool('testing', {
|
|
41
41
|
name: 'custodian',
|
|
42
42
|
description: 'Custodian can tell you the password if you say the magic word',
|
|
43
|
-
schema:
|
|
44
|
-
magicWord:
|
|
43
|
+
schema: Schema.Struct({
|
|
44
|
+
magicWord: Schema.String.annotations({ description: 'The magic word. Should be exactly "pretty please"' }),
|
|
45
45
|
}),
|
|
46
46
|
execute: async ({ magicWord }) => {
|
|
47
47
|
if (magicWord === 'pretty please') {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Schema
|
|
5
|
+
import { Schema } from 'effect';
|
|
6
6
|
|
|
7
7
|
import { type Message, type MessageContentBlock } from '@dxos/artifact';
|
|
8
8
|
import { toJsonSchema, JsonSchemaType, ObjectId } from '@dxos/echo-schema';
|
|
@@ -17,11 +17,11 @@ export const createUserMessage = (text: string): Message => ({
|
|
|
17
17
|
/**
|
|
18
18
|
* @deprecated Use {@link LLMTool} instead.
|
|
19
19
|
*/
|
|
20
|
-
export const ToolDefinition =
|
|
21
|
-
name:
|
|
22
|
-
description:
|
|
20
|
+
export const ToolDefinition = Schema.Struct({
|
|
21
|
+
name: Schema.String,
|
|
22
|
+
description: Schema.String,
|
|
23
23
|
parameters: JsonSchemaType,
|
|
24
|
-
execute:
|
|
24
|
+
execute: Schema.Any,
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
/**
|
|
@@ -83,14 +83,14 @@ export const ToolResult = Object.freeze({
|
|
|
83
83
|
Break: (result: unknown): ToolResult => ({ kind: 'break', result }),
|
|
84
84
|
});
|
|
85
85
|
|
|
86
|
-
export type DefineToolParams<Params extends
|
|
86
|
+
export type DefineToolParams<Params extends Schema.Schema.AnyNoContext> = {
|
|
87
87
|
name: string;
|
|
88
88
|
description: string;
|
|
89
89
|
schema: Params;
|
|
90
|
-
execute: (params:
|
|
90
|
+
execute: (params: Schema.Schema.Type<Params>, context: ToolExecutionContext) => Promise<ToolResult>;
|
|
91
91
|
};
|
|
92
92
|
|
|
93
|
-
export const defineTool = <Params extends
|
|
93
|
+
export const defineTool = <Params extends Schema.Schema.AnyNoContext>({
|
|
94
94
|
name,
|
|
95
95
|
description,
|
|
96
96
|
schema,
|
|
@@ -101,7 +101,7 @@ export const defineTool = <Params extends S.Schema.AnyNoContext>({
|
|
|
101
101
|
description,
|
|
102
102
|
parameters: toFunctionParameterSchema(schema),
|
|
103
103
|
execute: (params, context) => {
|
|
104
|
-
const sanitized =
|
|
104
|
+
const sanitized = Schema.decodeSync(schema)(params);
|
|
105
105
|
return execute(sanitized, context);
|
|
106
106
|
},
|
|
107
107
|
};
|
|
@@ -110,7 +110,7 @@ export const defineTool = <Params extends S.Schema.AnyNoContext>({
|
|
|
110
110
|
/**
|
|
111
111
|
* Adapts schems to be able to pass to AI providers.
|
|
112
112
|
*/
|
|
113
|
-
const toFunctionParameterSchema = (schema:
|
|
113
|
+
const toFunctionParameterSchema = (schema: Schema.Schema.All) => {
|
|
114
114
|
const jsonSchema = toJsonSchema(schema);
|
|
115
115
|
log('tool schema', { jsonSchema });
|
|
116
116
|
delete jsonSchema.anyOf;
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { type Schema } from 'effect';
|
|
6
|
+
|
|
5
7
|
import { raise } from '@dxos/debug';
|
|
6
|
-
import { type EchoDatabase, Filter, type
|
|
7
|
-
import { getSchema, getSchemaTypename,
|
|
8
|
+
import { type EchoDatabase, Filter, type AnyLiveObject } from '@dxos/echo-db';
|
|
9
|
+
import { getSchema, getSchemaTypename, StoredSchema, toJsonSchema } from '@dxos/echo-schema';
|
|
8
10
|
import { log } from '@dxos/log';
|
|
9
11
|
|
|
10
12
|
import type { DataSource, Node, Relationship } from './query-executor';
|
|
@@ -62,7 +64,7 @@ export class EchoDataSource implements DataSource {
|
|
|
62
64
|
).flat();
|
|
63
65
|
}
|
|
64
66
|
|
|
65
|
-
private async _getAllSchema(): Promise<
|
|
67
|
+
private async _getAllSchema(): Promise<Schema.Schema.AnyNoContext[]> {
|
|
66
68
|
return [
|
|
67
69
|
...(await this._db.schemaRegistry.query().run()),
|
|
68
70
|
// TODO(dmaretskyi): Remove once we can serialize recursive schema.
|
|
@@ -70,7 +72,7 @@ export class EchoDataSource implements DataSource {
|
|
|
70
72
|
].filter((schema) => getSchemaTypename(schema) !== StoredSchema.typename);
|
|
71
73
|
}
|
|
72
74
|
|
|
73
|
-
private _objectToNode(object:
|
|
75
|
+
private _objectToNode(object: AnyLiveObject<any>): Node {
|
|
74
76
|
const { id, ...properties } = object;
|
|
75
77
|
return {
|
|
76
78
|
id,
|
|
@@ -80,7 +82,7 @@ export class EchoDataSource implements DataSource {
|
|
|
80
82
|
};
|
|
81
83
|
}
|
|
82
84
|
|
|
83
|
-
private async _projectRefRelationship(object:
|
|
85
|
+
private async _projectRefRelationship(object: AnyLiveObject<any>, prop: string): Promise<Relationship[]> {
|
|
84
86
|
if (!object[prop]) {
|
|
85
87
|
return [];
|
|
86
88
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Schema
|
|
5
|
+
import { Schema } from 'effect';
|
|
6
6
|
import { inspect } from 'node:util';
|
|
7
7
|
import { describe, test } from 'vitest';
|
|
8
8
|
|
|
@@ -15,7 +15,8 @@ import {
|
|
|
15
15
|
type MessageContentBlock,
|
|
16
16
|
} from '@dxos/artifact';
|
|
17
17
|
import { AIServiceEdgeClient } from '@dxos/assistant';
|
|
18
|
-
import {
|
|
18
|
+
import { Type } from '@dxos/echo';
|
|
19
|
+
import { create, ObjectId } from '@dxos/echo-schema';
|
|
19
20
|
import { DXN } from '@dxos/keys';
|
|
20
21
|
import { log } from '@dxos/log';
|
|
21
22
|
|
|
@@ -23,14 +24,19 @@ import { AISession } from './session';
|
|
|
23
24
|
import { AI_SERVICE_ENDPOINT } from '../testing';
|
|
24
25
|
|
|
25
26
|
// Define a calendar event artifact schema.
|
|
26
|
-
const CalendarEventSchema =
|
|
27
|
-
title:
|
|
28
|
-
startTime:
|
|
29
|
-
endTime:
|
|
30
|
-
description:
|
|
31
|
-
}).pipe(
|
|
27
|
+
const CalendarEventSchema = Schema.Struct({
|
|
28
|
+
title: Schema.String,
|
|
29
|
+
startTime: Schema.String,
|
|
30
|
+
endTime: Schema.String,
|
|
31
|
+
description: Schema.String,
|
|
32
|
+
}).pipe(
|
|
33
|
+
Type.def({
|
|
34
|
+
typename: 'example.com/type/CalendarEvent',
|
|
35
|
+
version: '0.1.0',
|
|
36
|
+
}),
|
|
37
|
+
);
|
|
32
38
|
|
|
33
|
-
type CalendarEvent =
|
|
39
|
+
type CalendarEvent = Schema.Schema.Type<typeof CalendarEventSchema>;
|
|
34
40
|
|
|
35
41
|
// TODO(burdon): Flaky.
|
|
36
42
|
describe.skip('AISession with Ollama', () => {
|
|
@@ -53,7 +59,7 @@ describe.skip('AISession with Ollama', () => {
|
|
|
53
59
|
defineTool('calendar', {
|
|
54
60
|
name: 'query',
|
|
55
61
|
description: 'Query the calendar for events',
|
|
56
|
-
schema:
|
|
62
|
+
schema: Schema.Struct({}),
|
|
57
63
|
execute: async () => {
|
|
58
64
|
return ToolResult.Success(CALENDAR_EVENTS);
|
|
59
65
|
},
|
|
@@ -65,13 +71,13 @@ describe.skip('AISession with Ollama', () => {
|
|
|
65
71
|
id: 'artifact:dxos.org/plugin/table',
|
|
66
72
|
name: 'Table',
|
|
67
73
|
instructions: 'Use this to create and manage tables. Each table has a unique id.',
|
|
68
|
-
schema:
|
|
74
|
+
schema: Schema.Struct({}),
|
|
69
75
|
tools: [
|
|
70
76
|
defineTool('table', {
|
|
71
77
|
name: 'create',
|
|
72
78
|
description: 'Create a table',
|
|
73
|
-
schema:
|
|
74
|
-
data:
|
|
79
|
+
schema: Schema.Struct({
|
|
80
|
+
data: Schema.Array(Schema.Any).annotations({ description: 'Array of data payloads to add as rows' }),
|
|
75
81
|
}),
|
|
76
82
|
execute: async ({ data }) => {
|
|
77
83
|
log('create table', { data });
|
|
@@ -89,12 +95,12 @@ describe.skip('AISession with Ollama', () => {
|
|
|
89
95
|
name: 'Map',
|
|
90
96
|
instructions:
|
|
91
97
|
'Use this to create and manage maps. Maps source data from tables. Table id is required to create a map.',
|
|
92
|
-
schema:
|
|
98
|
+
schema: Schema.Struct({}),
|
|
93
99
|
tools: [
|
|
94
100
|
defineTool('map', {
|
|
95
101
|
name: 'create',
|
|
96
102
|
description: 'Create a map',
|
|
97
|
-
schema:
|
|
103
|
+
schema: Schema.Struct({
|
|
98
104
|
source: ArtifactId.annotations({
|
|
99
105
|
description: 'The table that will be used as the source of the map',
|
|
100
106
|
}),
|
|
@@ -119,7 +125,7 @@ describe.skip('AISession with Ollama', () => {
|
|
|
119
125
|
id: 'artifact:dxos.org/plugin/script',
|
|
120
126
|
name: 'Script',
|
|
121
127
|
instructions: 'Use this to create and manage scripts',
|
|
122
|
-
schema:
|
|
128
|
+
schema: Schema.Struct({}),
|
|
123
129
|
tools: [],
|
|
124
130
|
});
|
|
125
131
|
|
package/src/session/session.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Option, Schema
|
|
5
|
+
import { Option, Schema } from 'effect';
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
8
|
defineTool,
|
|
@@ -287,7 +287,7 @@ export class AISession {
|
|
|
287
287
|
return defineTool('system', {
|
|
288
288
|
name: 'query_artifact_definitions',
|
|
289
289
|
description: 'Query the available artifact definitions',
|
|
290
|
-
schema:
|
|
290
|
+
schema: Schema.Struct({}),
|
|
291
291
|
execute: async () => {
|
|
292
292
|
return ToolResult.Success({
|
|
293
293
|
artifactDefinitions: artifacts.map((artifact) => ({
|
|
@@ -308,8 +308,8 @@ export class AISession {
|
|
|
308
308
|
name: 'require_artifact_definitions',
|
|
309
309
|
description:
|
|
310
310
|
'Require the use of specific artifact definitions. This will allow the model to interact with artifact definitions and use their tools.',
|
|
311
|
-
schema:
|
|
312
|
-
artifactDefinitionIds:
|
|
311
|
+
schema: Schema.Struct({
|
|
312
|
+
artifactDefinitionIds: Schema.Array(Schema.String).annotations({
|
|
313
313
|
description: 'The ids of the artifact definitions to require',
|
|
314
314
|
examples: [['artifact:dxos.org/example/Test']],
|
|
315
315
|
}),
|
|
@@ -336,20 +336,20 @@ export class AISession {
|
|
|
336
336
|
name: 'create_plan',
|
|
337
337
|
description:
|
|
338
338
|
'Create a plan. Make sure that each step is independent and can be executed solely on the data returned by the previous step. The steps only share the data that is specified in the plan.',
|
|
339
|
-
schema:
|
|
340
|
-
goal:
|
|
341
|
-
steps:
|
|
342
|
-
|
|
343
|
-
action:
|
|
339
|
+
schema: Schema.Struct({
|
|
340
|
+
goal: Schema.String.annotations({ description: 'The goal that the plan will achieve.' }),
|
|
341
|
+
steps: Schema.Array(
|
|
342
|
+
Schema.Struct({
|
|
343
|
+
action: Schema.String.annotations({
|
|
344
344
|
description: 'Complete, detailed action to perform.',
|
|
345
345
|
}),
|
|
346
|
-
input:
|
|
346
|
+
input: Schema.String.annotations({
|
|
347
347
|
description: 'The required input data for this step. First step must not require any data.',
|
|
348
348
|
}),
|
|
349
|
-
output:
|
|
349
|
+
output: Schema.String.annotations({
|
|
350
350
|
description: 'The output data from this step. This is passed to the next step as input.',
|
|
351
351
|
}),
|
|
352
|
-
requiredArtifactIds:
|
|
352
|
+
requiredArtifactIds: Schema.Array(Schema.String).annotations({
|
|
353
353
|
description: 'The ids of the artifacts required to perform this step.',
|
|
354
354
|
examples: [['artifact:dxos.org/example/Test']],
|
|
355
355
|
}),
|
|
@@ -473,7 +473,7 @@ const createBaseInstructions = ({
|
|
|
473
473
|
${availableArtifacts.length > 0 ? `Artifacts already in context: ${availableArtifacts.join('\n')}` : ''}
|
|
474
474
|
`;
|
|
475
475
|
|
|
476
|
-
export class AIServiecOverloadedError extends
|
|
476
|
+
export class AIServiecOverloadedError extends Schema.TaggedError<AIServiecOverloadedError>()(
|
|
477
477
|
'AIServiecOverloadedError',
|
|
478
478
|
{},
|
|
479
479
|
) {}
|
|
@@ -483,7 +483,7 @@ const gatherObjectVersions = (messages: Message[]): Map<ObjectId, ObjectVersion>
|
|
|
483
483
|
for (const message of messages) {
|
|
484
484
|
for (const block of message.content) {
|
|
485
485
|
if (block.type === 'json' && block.disposition === VersionPin.DISPOSITION) {
|
|
486
|
-
const pin = VersionPin.pipe(
|
|
486
|
+
const pin = VersionPin.pipe(Schema.decodeOption)(JSON.parse(block.json)).pipe(Option.getOrUndefined);
|
|
487
487
|
if (!pin) {
|
|
488
488
|
continue;
|
|
489
489
|
}
|