@dxos/assistant 0.8.2-main.2f9c567 → 0.8.2-main.5885341
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-OLO6SVOL.mjs → chunk-DEIGOD4U.mjs} +21 -21
- package/dist/lib/browser/chunk-DEIGOD4U.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 +27 -23
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node/{chunk-CI5Q7FBG.cjs → chunk-7VH7NMIM.cjs} +6 -6
- package/dist/lib/node/chunk-7VH7NMIM.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 +18 -13
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/lib/node-esm/{chunk-Y3SYOFFJ.mjs → chunk-7JI4MDGL.mjs} +21 -21
- package/dist/lib/node-esm/chunk-7JI4MDGL.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 +27 -23
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- 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/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/session/session.d.ts +3 -3
- package/dist/types/src/session/session.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 +23 -25
- package/dist/types/src/testing/test-schema.d.ts.map +1 -1
- package/package.json +13 -14
- 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 +5 -7
- package/src/session/session.test.ts +16 -22
- 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 +28 -27
- package/dist/lib/browser/chunk-OLO6SVOL.mjs.map +0 -7
- package/dist/lib/node/chunk-CI5Q7FBG.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-Y3SYOFFJ.mjs.map +0 -7
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Schema } from 'effect';
|
|
5
|
+
import { Schema as S } 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
|
+
S.Struct({
|
|
62
|
+
magicWord: S.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: S.Struct({
|
|
198
|
+
message: S.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 } from 'effect';
|
|
5
|
+
import { Schema as S } 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: S.Struct({
|
|
392
|
+
prompt: S.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 S.TaggedError<ModelDoesNotSupportToolsError>()(
|
|
471
471
|
'ModelDoesNotSupportToolsError',
|
|
472
472
|
{
|
|
473
|
-
model:
|
|
473
|
+
model: S.String,
|
|
474
474
|
},
|
|
475
475
|
) {}
|
|
476
476
|
|
|
477
|
-
class ModelNotFoundError extends
|
|
478
|
-
model:
|
|
477
|
+
class ModelNotFoundError extends S.TaggedError<ModelNotFoundError>()('ModelNotFoundError', {
|
|
478
|
+
model: S.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 } from 'effect';
|
|
5
|
+
import { Schema as S } 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 = S.Literal(...DEFAULT_EDGE_MODELS, ...DEFAULT_OLLAMA_MODELS);
|
|
15
15
|
|
|
16
|
-
export type LLMModel =
|
|
16
|
+
export type LLMModel = S.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 = S.Struct({
|
|
28
28
|
/**
|
|
29
29
|
* Preferred model or system default.
|
|
30
30
|
*/
|
|
31
|
-
model:
|
|
31
|
+
model: S.optional(LLMModel),
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
34
|
* Tools available for the LLM.
|
|
35
35
|
*/
|
|
36
|
-
tools:
|
|
36
|
+
tools: S.optional(S.Array(Tool).pipe(S.mutable)),
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
39
|
* System instructions to the LLM.
|
|
40
40
|
*/
|
|
41
|
-
systemPrompt:
|
|
41
|
+
systemPrompt: S.optional(S.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: S.optional(S.Array(Message)),
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
50
|
* Current request.
|
|
51
51
|
*/
|
|
52
|
-
prompt:
|
|
52
|
+
prompt: S.optional(Message),
|
|
53
53
|
});
|
|
54
|
-
export type GenerateRequest =
|
|
54
|
+
export type GenerateRequest = S.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 = S.Struct({
|
|
60
|
+
messages: S.Array(Message),
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
63
|
* Number of tokens used in the response.
|
|
64
64
|
*/
|
|
65
|
-
tokenCount:
|
|
65
|
+
tokenCount: S.optional(S.Number),
|
|
66
66
|
});
|
|
67
|
-
export type GenerateResponse =
|
|
67
|
+
export type GenerateResponse = S.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 } from 'effect';
|
|
5
|
+
import { Schema as S } 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: S.Struct({
|
|
44
|
+
magicWord: S.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 } from 'effect';
|
|
5
|
+
import { Schema as S } 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 = S.Struct({
|
|
21
|
+
name: S.String,
|
|
22
|
+
description: S.String,
|
|
23
23
|
parameters: JsonSchemaType,
|
|
24
|
-
execute:
|
|
24
|
+
execute: S.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 S.Schema.AnyNoContext> = {
|
|
87
87
|
name: string;
|
|
88
88
|
description: string;
|
|
89
89
|
schema: Params;
|
|
90
|
-
execute: (params:
|
|
90
|
+
execute: (params: S.Schema.Type<Params>, context: ToolExecutionContext) => Promise<ToolResult>;
|
|
91
91
|
};
|
|
92
92
|
|
|
93
|
-
export const defineTool = <Params extends
|
|
93
|
+
export const defineTool = <Params extends S.Schema.AnyNoContext>({
|
|
94
94
|
name,
|
|
95
95
|
description,
|
|
96
96
|
schema,
|
|
@@ -101,7 +101,7 @@ export const defineTool = <Params extends Schema.Schema.AnyNoContext>({
|
|
|
101
101
|
description,
|
|
102
102
|
parameters: toFunctionParameterSchema(schema),
|
|
103
103
|
execute: (params, context) => {
|
|
104
|
-
const sanitized =
|
|
104
|
+
const sanitized = S.decodeSync(schema)(params);
|
|
105
105
|
return execute(sanitized, context);
|
|
106
106
|
},
|
|
107
107
|
};
|
|
@@ -110,7 +110,7 @@ export const defineTool = <Params extends Schema.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: S.Schema.All) => {
|
|
114
114
|
const jsonSchema = toJsonSchema(schema);
|
|
115
115
|
log('tool schema', { jsonSchema });
|
|
116
116
|
delete jsonSchema.anyOf;
|
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type Schema } from 'effect';
|
|
6
|
-
|
|
7
5
|
import { raise } from '@dxos/debug';
|
|
8
|
-
import { type EchoDatabase, Filter, type
|
|
9
|
-
import { getSchema, getSchemaTypename, StoredSchema, toJsonSchema } from '@dxos/echo-schema';
|
|
6
|
+
import { type EchoDatabase, Filter, type ReactiveEchoObject } from '@dxos/echo-db';
|
|
7
|
+
import { getSchema, getSchemaTypename, type S, StoredSchema, toJsonSchema } from '@dxos/echo-schema';
|
|
10
8
|
import { log } from '@dxos/log';
|
|
11
9
|
|
|
12
10
|
import type { DataSource, Node, Relationship } from './query-executor';
|
|
@@ -64,7 +62,7 @@ export class EchoDataSource implements DataSource {
|
|
|
64
62
|
).flat();
|
|
65
63
|
}
|
|
66
64
|
|
|
67
|
-
private async _getAllSchema(): Promise<
|
|
65
|
+
private async _getAllSchema(): Promise<S.Schema.AnyNoContext[]> {
|
|
68
66
|
return [
|
|
69
67
|
...(await this._db.schemaRegistry.query().run()),
|
|
70
68
|
// TODO(dmaretskyi): Remove once we can serialize recursive schema.
|
|
@@ -72,7 +70,7 @@ export class EchoDataSource implements DataSource {
|
|
|
72
70
|
].filter((schema) => getSchemaTypename(schema) !== StoredSchema.typename);
|
|
73
71
|
}
|
|
74
72
|
|
|
75
|
-
private _objectToNode(object:
|
|
73
|
+
private _objectToNode(object: ReactiveEchoObject<any>): Node {
|
|
76
74
|
const { id, ...properties } = object;
|
|
77
75
|
return {
|
|
78
76
|
id,
|
|
@@ -82,7 +80,7 @@ export class EchoDataSource implements DataSource {
|
|
|
82
80
|
};
|
|
83
81
|
}
|
|
84
82
|
|
|
85
|
-
private async _projectRefRelationship(object:
|
|
83
|
+
private async _projectRefRelationship(object: ReactiveEchoObject<any>, prop: string): Promise<Relationship[]> {
|
|
86
84
|
if (!object[prop]) {
|
|
87
85
|
return [];
|
|
88
86
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Schema } from 'effect';
|
|
5
|
+
import { Schema as S } from 'effect';
|
|
6
6
|
import { inspect } from 'node:util';
|
|
7
7
|
import { describe, test } from 'vitest';
|
|
8
8
|
|
|
@@ -15,8 +15,7 @@ import {
|
|
|
15
15
|
type MessageContentBlock,
|
|
16
16
|
} from '@dxos/artifact';
|
|
17
17
|
import { AIServiceEdgeClient } from '@dxos/assistant';
|
|
18
|
-
import {
|
|
19
|
-
import { create, ObjectId } from '@dxos/echo-schema';
|
|
18
|
+
import { create, EchoObject, ObjectId } from '@dxos/echo-schema';
|
|
20
19
|
import { DXN } from '@dxos/keys';
|
|
21
20
|
import { log } from '@dxos/log';
|
|
22
21
|
|
|
@@ -24,19 +23,14 @@ import { AISession } from './session';
|
|
|
24
23
|
import { AI_SERVICE_ENDPOINT } from '../testing';
|
|
25
24
|
|
|
26
25
|
// Define a calendar event artifact schema.
|
|
27
|
-
const CalendarEventSchema =
|
|
28
|
-
title:
|
|
29
|
-
startTime:
|
|
30
|
-
endTime:
|
|
31
|
-
description:
|
|
32
|
-
}).pipe(
|
|
33
|
-
Type.def({
|
|
34
|
-
typename: 'example.com/type/CalendarEvent',
|
|
35
|
-
version: '0.1.0',
|
|
36
|
-
}),
|
|
37
|
-
);
|
|
26
|
+
const CalendarEventSchema = S.Struct({
|
|
27
|
+
title: S.String,
|
|
28
|
+
startTime: S.String,
|
|
29
|
+
endTime: S.String,
|
|
30
|
+
description: S.String,
|
|
31
|
+
}).pipe(EchoObject({ typename: 'example.com/type/CalendarEvent', version: '0.1.0' }));
|
|
38
32
|
|
|
39
|
-
type CalendarEvent =
|
|
33
|
+
type CalendarEvent = S.Schema.Type<typeof CalendarEventSchema>;
|
|
40
34
|
|
|
41
35
|
// TODO(burdon): Flaky.
|
|
42
36
|
describe.skip('AISession with Ollama', () => {
|
|
@@ -59,7 +53,7 @@ describe.skip('AISession with Ollama', () => {
|
|
|
59
53
|
defineTool('calendar', {
|
|
60
54
|
name: 'query',
|
|
61
55
|
description: 'Query the calendar for events',
|
|
62
|
-
schema:
|
|
56
|
+
schema: S.Struct({}),
|
|
63
57
|
execute: async () => {
|
|
64
58
|
return ToolResult.Success(CALENDAR_EVENTS);
|
|
65
59
|
},
|
|
@@ -71,13 +65,13 @@ describe.skip('AISession with Ollama', () => {
|
|
|
71
65
|
id: 'artifact:dxos.org/plugin/table',
|
|
72
66
|
name: 'Table',
|
|
73
67
|
instructions: 'Use this to create and manage tables. Each table has a unique id.',
|
|
74
|
-
schema:
|
|
68
|
+
schema: S.Struct({}),
|
|
75
69
|
tools: [
|
|
76
70
|
defineTool('table', {
|
|
77
71
|
name: 'create',
|
|
78
72
|
description: 'Create a table',
|
|
79
|
-
schema:
|
|
80
|
-
data:
|
|
73
|
+
schema: S.Struct({
|
|
74
|
+
data: S.Array(S.Any).annotations({ description: 'Array of data payloads to add as rows' }),
|
|
81
75
|
}),
|
|
82
76
|
execute: async ({ data }) => {
|
|
83
77
|
log('create table', { data });
|
|
@@ -95,12 +89,12 @@ describe.skip('AISession with Ollama', () => {
|
|
|
95
89
|
name: 'Map',
|
|
96
90
|
instructions:
|
|
97
91
|
'Use this to create and manage maps. Maps source data from tables. Table id is required to create a map.',
|
|
98
|
-
schema:
|
|
92
|
+
schema: S.Struct({}),
|
|
99
93
|
tools: [
|
|
100
94
|
defineTool('map', {
|
|
101
95
|
name: 'create',
|
|
102
96
|
description: 'Create a map',
|
|
103
|
-
schema:
|
|
97
|
+
schema: S.Struct({
|
|
104
98
|
source: ArtifactId.annotations({
|
|
105
99
|
description: 'The table that will be used as the source of the map',
|
|
106
100
|
}),
|
|
@@ -125,7 +119,7 @@ describe.skip('AISession with Ollama', () => {
|
|
|
125
119
|
id: 'artifact:dxos.org/plugin/script',
|
|
126
120
|
name: 'Script',
|
|
127
121
|
instructions: 'Use this to create and manage scripts',
|
|
128
|
-
schema:
|
|
122
|
+
schema: S.Struct({}),
|
|
129
123
|
tools: [],
|
|
130
124
|
});
|
|
131
125
|
|
package/src/session/session.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Option, Schema } from 'effect';
|
|
5
|
+
import { Option, Schema as S } 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: S.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: S.Struct({
|
|
312
|
+
artifactDefinitionIds: S.Array(S.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: S.Struct({
|
|
340
|
+
goal: S.String.annotations({ description: 'The goal that the plan will achieve.' }),
|
|
341
|
+
steps: S.Array(
|
|
342
|
+
S.Struct({
|
|
343
|
+
action: S.String.annotations({
|
|
344
344
|
description: 'Complete, detailed action to perform.',
|
|
345
345
|
}),
|
|
346
|
-
input:
|
|
346
|
+
input: S.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: S.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: S.Array(S.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 S.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(S.decodeOption)(JSON.parse(block.json)).pipe(Option.getOrUndefined);
|
|
487
487
|
if (!pin) {
|
|
488
488
|
continue;
|
|
489
489
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
/*
|
|
6
|
-
import { Schema } from '@effect/schema';
|
|
6
|
+
import { Schema as S } from '@effect/schema';
|
|
7
7
|
import { describe, test } from 'vitest';
|
|
8
8
|
|
|
9
9
|
import { ObjectId, toJsonSchema } from '@dxos/echo-schema';
|
|
@@ -15,26 +15,26 @@ import { AIServiceEdgeClient, Tool } from '../ai-service';
|
|
|
15
15
|
import { defineTool, ToolResult } from '../conversation';
|
|
16
16
|
|
|
17
17
|
// TODO(dmaretskyi): Effect schema.
|
|
18
|
-
const ArtifactDef =
|
|
19
|
-
typename:
|
|
20
|
-
description:
|
|
21
|
-
schema:
|
|
22
|
-
actions:
|
|
23
|
-
}).pipe(
|
|
18
|
+
const ArtifactDef = S.Struct({
|
|
19
|
+
typename: S.String,
|
|
20
|
+
description: S.String,
|
|
21
|
+
schema: S.Any,
|
|
22
|
+
actions: S.Array(Tool),
|
|
23
|
+
}).pipe(S.mutable);
|
|
24
24
|
|
|
25
|
-
type ArtifactDef =
|
|
25
|
+
type ArtifactDef = S.Schema.Type<typeof ArtifactDef>;
|
|
26
26
|
|
|
27
|
-
const ListItem =
|
|
28
|
-
name:
|
|
27
|
+
const ListItem = S.Struct({
|
|
28
|
+
name: S.String,
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
-
const ListSchema =
|
|
31
|
+
const ListSchema = S.Struct({
|
|
32
32
|
id: ObjectId,
|
|
33
|
-
title:
|
|
34
|
-
items:
|
|
35
|
-
}).pipe(
|
|
33
|
+
title: S.String,
|
|
34
|
+
items: S.Array(ListItem).pipe(S.mutable),
|
|
35
|
+
}).pipe(S.mutable);
|
|
36
36
|
|
|
37
|
-
type ListSchema =
|
|
37
|
+
type ListSchema = S.Schema.Type<typeof ListSchema>;
|
|
38
38
|
|
|
39
39
|
const list: ArtifactDef = {
|
|
40
40
|
typename: 'example.com/type/List',
|
|
@@ -44,7 +44,7 @@ const list: ArtifactDef = {
|
|
|
44
44
|
defineTool('list', {
|
|
45
45
|
name: 'query',
|
|
46
46
|
description: 'Query all lists',
|
|
47
|
-
schema:
|
|
47
|
+
schema: S.Struct({}),
|
|
48
48
|
execute: async ({}, context) => {
|
|
49
49
|
return ToolResult.Success(LISTS[id]);
|
|
50
50
|
},
|
|
@@ -52,7 +52,7 @@ const list: ArtifactDef = {
|
|
|
52
52
|
defineTool('list', {
|
|
53
53
|
name: 'inspect',
|
|
54
54
|
description: 'Get contents of the list',
|
|
55
|
-
schema:
|
|
55
|
+
schema: S.Struct({
|
|
56
56
|
id: ObjectId.annotations({ description: 'The list to inspect' }),
|
|
57
57
|
}),
|
|
58
58
|
execute: async ({ id }, context) => {
|
|
@@ -62,9 +62,9 @@ const list: ArtifactDef = {
|
|
|
62
62
|
defineTool('list', {
|
|
63
63
|
name: 'create',
|
|
64
64
|
description: 'Add one or more items to an existing list',
|
|
65
|
-
schema:
|
|
65
|
+
schema: S.Struct({
|
|
66
66
|
id: ObjectId.annotations({ description: 'The list to add items to' }),
|
|
67
|
-
items:
|
|
67
|
+
items: S.Array(ListItem).annotations({ description: 'The items to add to the list' }),
|
|
68
68
|
}),
|
|
69
69
|
execute: async ({ id, items }, context) => {
|
|
70
70
|
LISTS[id].items.push(...items);
|
|
@@ -81,7 +81,7 @@ const artifacts = [list];
|
|
|
81
81
|
const getArtifactDefinitions = defineTool('system', {
|
|
82
82
|
name: 'getArtifactDefinitions',
|
|
83
83
|
description: 'Queries the definitions and metadata of artifacts defined in the system',
|
|
84
|
-
schema:
|
|
84
|
+
schema: S.Any,
|
|
85
85
|
execute: async (_, context) => {
|
|
86
86
|
return ToolResult.Success(
|
|
87
87
|
artifacts.map((artifact) => ({
|
|
@@ -116,8 +116,8 @@ describe('Artifacts', () => {
|
|
|
116
116
|
name: 'custodian',
|
|
117
117
|
description: 'Custodian can tell you the password if you say the magic word',
|
|
118
118
|
parameters: toJsonSchema(
|
|
119
|
-
|
|
120
|
-
magicWord:
|
|
119
|
+
S.Struct({
|
|
120
|
+
magicWord: S.String.annotations({ description: 'The magic word. Should be exactly "pretty please"' }),
|
|
121
121
|
}),
|
|
122
122
|
),
|
|
123
123
|
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Schema } from 'effect';
|
|
5
|
+
import { Schema as S } from 'effect';
|
|
6
6
|
|
|
7
7
|
import { defineTool, ToolResult } from '@dxos/artifact';
|
|
8
8
|
import { toJsonSchema } from '@dxos/echo-schema';
|
|
@@ -11,14 +11,14 @@ import { log } from '@dxos/log';
|
|
|
11
11
|
import { executeQuery, formatJsonSchemaForLLM, type DataSource } from '../cypher';
|
|
12
12
|
import { trim } from '../util';
|
|
13
13
|
|
|
14
|
-
export const createCypherTool = (dataSource: DataSource, schemaTypes:
|
|
14
|
+
export const createCypherTool = (dataSource: DataSource, schemaTypes: S.Schema.Any[] = []) =>
|
|
15
15
|
defineTool('dxos.org/echo', {
|
|
16
16
|
name: 'query',
|
|
17
17
|
description:
|
|
18
18
|
'Query the ECHO graph database in cypher query language. Returns data from the database.' +
|
|
19
19
|
(schemaTypes.length > 0 ? `\n\n${createSystemPrompt(schemaTypes)}` : ''),
|
|
20
|
-
schema:
|
|
21
|
-
query:
|
|
20
|
+
schema: S.Struct({
|
|
21
|
+
query: S.String.annotations({
|
|
22
22
|
description: `
|
|
23
23
|
A valid cypher query string to execute.
|
|
24
24
|
Query must have one MATCH clause.
|
|
@@ -55,7 +55,7 @@ export const createCypherTool = (dataSource: DataSource, schemaTypes: Schema.Sch
|
|
|
55
55
|
},
|
|
56
56
|
});
|
|
57
57
|
|
|
58
|
-
export const createSystemPrompt = (schemaTypes:
|
|
58
|
+
export const createSystemPrompt = (schemaTypes: S.Schema.Any[]) => trim`
|
|
59
59
|
You have access to ECHO graph database. You can query the database to get data to satisfy user prompts.
|
|
60
60
|
|
|
61
61
|
Database schema is defined in pseud-cypher syntax. The schema is:
|
package/src/testing/test-data.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type Schema } from 'effect';
|
|
5
|
+
import { type Schema as S } from 'effect';
|
|
6
6
|
|
|
7
7
|
import { raise } from '@dxos/debug';
|
|
8
8
|
import type { EchoDatabase } from '@dxos/echo-db';
|
|
@@ -254,7 +254,7 @@ export class MockDataSource implements DataSource {
|
|
|
254
254
|
objects: Record<
|
|
255
255
|
string,
|
|
256
256
|
{
|
|
257
|
-
schema:
|
|
257
|
+
schema: S.Schema.All;
|
|
258
258
|
typeDxn: string;
|
|
259
259
|
id: string;
|
|
260
260
|
data: unknown;
|
|
@@ -265,7 +265,7 @@ export class MockDataSource implements DataSource {
|
|
|
265
265
|
string,
|
|
266
266
|
{
|
|
267
267
|
json: JsonSchemaType;
|
|
268
|
-
instance:
|
|
268
|
+
instance: S.Schema.All;
|
|
269
269
|
}
|
|
270
270
|
> = {};
|
|
271
271
|
|
|
@@ -280,7 +280,7 @@ export class MockDataSource implements DataSource {
|
|
|
280
280
|
return this.relationships.filter((relationship) => !label || relationship.label === label);
|
|
281
281
|
}
|
|
282
282
|
|
|
283
|
-
add<S extends
|
|
283
|
+
add<S extends S.Schema.All>(schema: S, data: S.Schema.Type<S>) {
|
|
284
284
|
invariant(typeof data.id === 'string', 'Data must have an id');
|
|
285
285
|
const jsonSchema = toJsonSchema(schema);
|
|
286
286
|
if (!this.schema[jsonSchema.$id!]) {
|