@dxos/assistant 0.7.4-df37807
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/LICENSE +8 -0
- package/README.md +24 -0
- package/dist/lib/browser/chunk-AKP45LQH.mjs +1394 -0
- package/dist/lib/browser/chunk-AKP45LQH.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +71 -0
- package/dist/lib/browser/index.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -0
- package/dist/lib/browser/testing/index.mjs +601 -0
- package/dist/lib/browser/testing/index.mjs.map +7 -0
- package/dist/lib/node/chunk-G6CGWEMO.cjs +1418 -0
- package/dist/lib/node/chunk-G6CGWEMO.cjs.map +7 -0
- package/dist/lib/node/index.cjs +93 -0
- package/dist/lib/node/index.cjs.map +7 -0
- package/dist/lib/node/meta.json +1 -0
- package/dist/lib/node/testing/index.cjs +619 -0
- package/dist/lib/node/testing/index.cjs.map +7 -0
- package/dist/lib/node-esm/chunk-WUPUPEFB.mjs +1396 -0
- package/dist/lib/node-esm/chunk-WUPUPEFB.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +72 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/lib/node-esm/testing/index.mjs +602 -0
- package/dist/lib/node-esm/testing/index.mjs.map +7 -0
- package/dist/types/src/ai-service/client.d.ts +48 -0
- package/dist/types/src/ai-service/client.d.ts.map +1 -0
- package/dist/types/src/ai-service/client.test.d.ts +2 -0
- package/dist/types/src/ai-service/client.test.d.ts.map +1 -0
- package/dist/types/src/ai-service/index.d.ts +3 -0
- package/dist/types/src/ai-service/index.d.ts.map +1 -0
- package/dist/types/src/ai-service/schema.d.ts +296 -0
- package/dist/types/src/ai-service/schema.d.ts.map +1 -0
- package/dist/types/src/ai-service/sse.d.ts +34 -0
- package/dist/types/src/ai-service/sse.d.ts.map +1 -0
- package/dist/types/src/bin/chat.d.ts +2 -0
- package/dist/types/src/bin/chat.d.ts.map +1 -0
- package/dist/types/src/conversation/conversation.d.ts +23 -0
- package/dist/types/src/conversation/conversation.d.ts.map +1 -0
- package/dist/types/src/conversation/conversation.test.d.ts +2 -0
- package/dist/types/src/conversation/conversation.test.d.ts.map +1 -0
- package/dist/types/src/conversation/index.d.ts +3 -0
- package/dist/types/src/conversation/index.d.ts.map +1 -0
- package/dist/types/src/conversation/types.d.ts +48 -0
- package/dist/types/src/conversation/types.d.ts.map +1 -0
- package/dist/types/src/cypher/ast.d.ts +56 -0
- package/dist/types/src/cypher/ast.d.ts.map +1 -0
- package/dist/types/src/cypher/combinators.d.ts +14 -0
- package/dist/types/src/cypher/combinators.d.ts.map +1 -0
- package/dist/types/src/cypher/combinators.test.d.ts +2 -0
- package/dist/types/src/cypher/combinators.test.d.ts.map +1 -0
- package/dist/types/src/cypher/echo-data-source.d.ts +16 -0
- package/dist/types/src/cypher/echo-data-source.d.ts.map +1 -0
- package/dist/types/src/cypher/execution-plan.d.ts +49 -0
- package/dist/types/src/cypher/execution-plan.d.ts.map +1 -0
- package/dist/types/src/cypher/execution-plan.test.d.ts +2 -0
- package/dist/types/src/cypher/execution-plan.test.d.ts.map +1 -0
- package/dist/types/src/cypher/index.d.ts +5 -0
- package/dist/types/src/cypher/index.d.ts.map +1 -0
- package/dist/types/src/cypher/parjs.d.ts +4 -0
- package/dist/types/src/cypher/parjs.d.ts.map +1 -0
- package/dist/types/src/cypher/parser.d.ts +6 -0
- package/dist/types/src/cypher/parser.d.ts.map +1 -0
- package/dist/types/src/cypher/query-executor.d.ts +26 -0
- package/dist/types/src/cypher/query-executor.d.ts.map +1 -0
- package/dist/types/src/cypher/query-executor.test.d.ts +2 -0
- package/dist/types/src/cypher/query-executor.test.d.ts.map +1 -0
- package/dist/types/src/cypher/schema.d.ts +12 -0
- package/dist/types/src/cypher/schema.d.ts.map +1 -0
- package/dist/types/src/cypher/schema.test.d.ts +2 -0
- package/dist/types/src/cypher/schema.test.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +4 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/sanity.test.d.ts +2 -0
- package/dist/types/src/sanity.test.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +5 -0
- package/dist/types/src/testing/index.d.ts.map +1 -0
- package/dist/types/src/testing/logger.d.ts +12 -0
- package/dist/types/src/testing/logger.d.ts.map +1 -0
- package/dist/types/src/testing/object-extraction.test.d.ts +1 -0
- package/dist/types/src/testing/object-extraction.test.d.ts.map +1 -0
- package/dist/types/src/testing/query-promts.d.ts +5 -0
- package/dist/types/src/testing/query-promts.d.ts.map +1 -0
- package/dist/types/src/testing/query.test.d.ts +2 -0
- package/dist/types/src/testing/query.test.d.ts.map +1 -0
- package/dist/types/src/testing/test-data.d.ts +29 -0
- package/dist/types/src/testing/test-data.d.ts.map +1 -0
- package/dist/types/src/testing/test-schema.d.ts +50 -0
- package/dist/types/src/testing/test-schema.d.ts.map +1 -0
- package/dist/types/src/util/index.d.ts +2 -0
- package/dist/types/src/util/index.d.ts.map +1 -0
- package/dist/types/src/util/trim.d.ts +5 -0
- package/dist/types/src/util/trim.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +64 -0
- package/src/ai-service/client.test.ts +162 -0
- package/src/ai-service/client.ts +243 -0
- package/src/ai-service/index.ts +6 -0
- package/src/ai-service/schema.ts +260 -0
- package/src/ai-service/sse.ts +336 -0
- package/src/bin/chat.ts +79 -0
- package/src/conversation/conversation.test.ts +74 -0
- package/src/conversation/conversation.ts +134 -0
- package/src/conversation/index.ts +6 -0
- package/src/conversation/types.ts +90 -0
- package/src/cypher/ast.ts +75 -0
- package/src/cypher/combinators.test.ts +137 -0
- package/src/cypher/combinators.ts +149 -0
- package/src/cypher/echo-data-source.ts +105 -0
- package/src/cypher/execution-plan.test.ts +42 -0
- package/src/cypher/execution-plan.ts +208 -0
- package/src/cypher/index.ts +8 -0
- package/src/cypher/parjs-shims.d.ts +6 -0
- package/src/cypher/parjs.ts +10 -0
- package/src/cypher/parser.ts +19 -0
- package/src/cypher/query-executor.test.ts +47 -0
- package/src/cypher/query-executor.ts +145 -0
- package/src/cypher/schema.test.ts +17 -0
- package/src/cypher/schema.ts +82 -0
- package/src/index.ts +7 -0
- package/src/sanity.test.ts +9 -0
- package/src/testing/index.ts +8 -0
- package/src/testing/logger.ts +128 -0
- package/src/testing/object-extraction.test.ts +71 -0
- package/src/testing/query-promts.ts +75 -0
- package/src/testing/query.test.ts +90 -0
- package/src/testing/test-data.ts +366 -0
- package/src/testing/test-schema.ts +80 -0
- package/src/util/index.ts +5 -0
- package/src/util/trim.ts +15 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { JsonPath } from '@dxos/echo-schema';
|
|
2
|
+
import type { ParsedQuery } from './parser';
|
|
3
|
+
export type VariableName = string & {
|
|
4
|
+
__VariableName: never;
|
|
5
|
+
};
|
|
6
|
+
export type ExecutionPlanStep = {
|
|
7
|
+
type: 'NodeScan';
|
|
8
|
+
label: string;
|
|
9
|
+
into: VariableName;
|
|
10
|
+
} | {
|
|
11
|
+
type: 'FilterByLabel';
|
|
12
|
+
variable: VariableName;
|
|
13
|
+
label: string;
|
|
14
|
+
} | {
|
|
15
|
+
type: 'FilterByProperty';
|
|
16
|
+
variable: VariableName;
|
|
17
|
+
property: JsonPath;
|
|
18
|
+
value: unknown;
|
|
19
|
+
} | {
|
|
20
|
+
/**
|
|
21
|
+
* Scans (anchor)-[relationshipInto:label]->(nodeInto).
|
|
22
|
+
*/
|
|
23
|
+
type: 'RelationshipScan';
|
|
24
|
+
label: string;
|
|
25
|
+
anchor: VariableName;
|
|
26
|
+
relationshipInto: VariableName;
|
|
27
|
+
nodeInto: VariableName;
|
|
28
|
+
/**
|
|
29
|
+
* `in`: (anchor)<-[relationshipInto:label]-(nodeInto)
|
|
30
|
+
* `out`: (anchor)-[relationshipInto:label]->(nodeInto)
|
|
31
|
+
* `both`: (anchor)-[relationshipInto:label]-(nodeInto)
|
|
32
|
+
*/
|
|
33
|
+
direction: 'in' | 'out' | 'both';
|
|
34
|
+
} | {
|
|
35
|
+
type: 'ProduceResults';
|
|
36
|
+
fields: {
|
|
37
|
+
name: string;
|
|
38
|
+
variable: VariableName;
|
|
39
|
+
path: JsonPath;
|
|
40
|
+
}[];
|
|
41
|
+
};
|
|
42
|
+
export type ExecutionPlan = {
|
|
43
|
+
steps: ExecutionPlanStep[];
|
|
44
|
+
output: {
|
|
45
|
+
fields: string[];
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
export declare const createExecutionPlan: (query: ParsedQuery) => ExecutionPlan;
|
|
49
|
+
//# sourceMappingURL=execution-plan.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execution-plan.d.ts","sourceRoot":"","sources":["../../../../src/cypher/execution-plan.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAKlD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG;IAAE,cAAc,EAAE,KAAK,CAAA;CAAE,CAAC;AAE9D,MAAM,MAAM,iBAAiB,GACzB;IACE,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,YAAY,CAAC;CACpB,GACD;IACE,IAAI,EAAE,eAAe,CAAC;IACtB,QAAQ,EAAE,YAAY,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;CACf,GACD;IACE,IAAI,EAAE,kBAAkB,CAAC;IACzB,QAAQ,EAAE,YAAY,CAAC;IACvB,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,EAAE,OAAO,CAAC;CAChB,GACD;IACE;;OAEG;IACH,IAAI,EAAE,kBAAkB,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,YAAY,CAAC;IACrB,gBAAgB,EAAE,YAAY,CAAC;IAC/B,QAAQ,EAAE,YAAY,CAAC;IAEvB;;;;OAIG;IACH,SAAS,EAAE,IAAI,GAAG,KAAK,GAAG,MAAM,CAAC;CAClC,GACD;IACE,IAAI,EAAE,gBAAgB,CAAC;IACvB,MAAM,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,YAAY,CAAC;QACvB,IAAI,EAAE,QAAQ,CAAC;KAChB,EAAE,CAAC;CACL,CAAC;AAEN,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,EAAE,iBAAiB,EAAE,CAAC;IAC3B,MAAM,EAAE;QACN,MAAM,EAAE,MAAM,EAAE,CAAC;KAClB,CAAC;CACH,CAAC;AAEF,eAAO,MAAM,mBAAmB,UAAW,WAAW,KAAG,aAExD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execution-plan.test.d.ts","sourceRoot":"","sources":["../../../../src/cypher/execution-plan.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/cypher/index.ts"],"names":[],"mappings":"AAIA,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parjs.d.ts","sourceRoot":"","sources":["../../../../src/cypher/parjs.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAEjD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAErC,OAAO,EAAE,KAAK,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../../../src/cypher/parser.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAGzC,MAAM,MAAM,WAAW,GAAG;IACxB,GAAG,EAAE,WAAW,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,gBAAgB,UAAW,MAAM,KAAG,WAOhD,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ExecutionPlan } from './execution-plan';
|
|
2
|
+
export interface DataSource {
|
|
3
|
+
getNodes: (params: {
|
|
4
|
+
label?: string;
|
|
5
|
+
}) => Promise<Node[]>;
|
|
6
|
+
getRelationships: (params: {
|
|
7
|
+
label?: string;
|
|
8
|
+
}) => Promise<Relationship[]>;
|
|
9
|
+
}
|
|
10
|
+
export type Node = {
|
|
11
|
+
id: string;
|
|
12
|
+
kind: 'node';
|
|
13
|
+
label: string;
|
|
14
|
+
properties: Record<string, unknown>;
|
|
15
|
+
};
|
|
16
|
+
export type Relationship = {
|
|
17
|
+
id: string;
|
|
18
|
+
kind: 'relationship';
|
|
19
|
+
label: string;
|
|
20
|
+
properties: Record<string, unknown>;
|
|
21
|
+
source: Node;
|
|
22
|
+
target: Node;
|
|
23
|
+
};
|
|
24
|
+
export declare const executeQueryPlan: (dataSource: DataSource, plan: ExecutionPlan) => Promise<Record<string, unknown>[]>;
|
|
25
|
+
export declare const executeQuery: (dataSource: DataSource, query: string) => Promise<Record<string, unknown>[]>;
|
|
26
|
+
//# sourceMappingURL=query-executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-executor.d.ts","sourceRoot":"","sources":["../../../../src/cypher/query-executor.ts"],"names":[],"mappings":"AAQA,OAAO,EAAuB,KAAK,aAAa,EAAqB,MAAM,kBAAkB,CAAC;AAG9F,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,CAAC,MAAM,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IAC1D,gBAAgB,EAAE,CAAC,MAAM,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC;CAC3E;AAED,MAAM,MAAM,IAAI,GAAG;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,cAAc,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,MAAM,EAAE,IAAI,CAAC;IACb,MAAM,EAAE,IAAI,CAAC;CACd,CAAC;AAEF,eAAO,MAAM,gBAAgB,eACf,UAAU,QAChB,aAAa,KAClB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAsFnC,CAAC;AAEF,eAAO,MAAM,YAAY,eAAgB,UAAU,SAAS,MAAM,KAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAGrG,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-executor.test.d.ts","sourceRoot":"","sources":["../../../../src/cypher/query-executor.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type JsonSchemaType } from '@dxos/echo-schema';
|
|
2
|
+
/**
|
|
3
|
+
* Formats ECHO schema to be consumed by LLM.
|
|
4
|
+
* Schema is formatted in cypher format.
|
|
5
|
+
* Objects are represented as nodes.
|
|
6
|
+
* References are represented as relationships.
|
|
7
|
+
*/
|
|
8
|
+
export declare const formatJsonSchemaForLLM: (schemaTypes: JsonSchemaType[]) => string[];
|
|
9
|
+
export declare const formatNodeLabel: (typename: string) => string;
|
|
10
|
+
export declare const formatInferredRelationshipLabel: (typename: string, property: string) => string;
|
|
11
|
+
export declare const isReference: (schema: JsonSchemaType) => boolean;
|
|
12
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../src/cypher/schema.ts"],"names":[],"mappings":"AAKA,OAAO,EAA2B,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAKjF;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,gBAAiB,cAAc,EAAE,KAAG,MAAM,EAK5E,CAAC;AAkDF,eAAO,MAAM,eAAe,aAAc,MAAM,WAE/C,CAAC;AAEF,eAAO,MAAM,+BAA+B,aAAc,MAAM,YAAY,MAAM,WAGjF,CAAC;AAEF,eAAO,MAAM,WAAW,WAAY,cAAc,YACoE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.test.d.ts","sourceRoot":"","sources":["../../../../src/cypher/schema.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanity.test.d.ts","sourceRoot":"","sources":["../../../src/sanity.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/testing/index.ts"],"names":[],"mappings":"AAIA,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ImageSource } from '../ai-service';
|
|
2
|
+
import type { ConversationEvent } from '../conversation';
|
|
3
|
+
export declare const createLogger: ({ stream, filter, onImage, }?: {
|
|
4
|
+
stream?: boolean;
|
|
5
|
+
filter?: (event: ConversationEvent) => boolean;
|
|
6
|
+
onImage?: (img: {
|
|
7
|
+
id: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
source: ImageSource;
|
|
10
|
+
}) => void;
|
|
11
|
+
}) => (event: ConversationEvent) => void;
|
|
12
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../../src/testing/logger.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAuB,MAAM,eAAe,CAAC;AACtE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,eAAO,MAAM,YAAY,kCAItB;IACD,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,OAAO,CAAC;IAC/C,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,WAAW,CAAA;KAAE,KAAK,IAAI,CAAC;CACpF,aAIgB,iBAAiB,SA4GjC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=object-extraction.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object-extraction.test.d.ts","sourceRoot":"","sources":["../../../../src/testing/object-extraction.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Schema as S } from '@effect/schema';
|
|
2
|
+
import { type DataSource } from '../cypher';
|
|
3
|
+
export declare const createCypherTool: (dataSource: DataSource, schemaTypes?: S.Schema.Any[]) => import("../conversation").LLMToolDefinition;
|
|
4
|
+
export declare const createSystemPrompt: (schemaTypes: S.Schema.Any[]) => string;
|
|
5
|
+
//# sourceMappingURL=query-promts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-promts.d.ts","sourceRoot":"","sources":["../../../../src/testing/query-promts.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,gBAAgB,CAAC;AAM7C,OAAO,EAAwC,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AAGlF,eAAO,MAAM,gBAAgB,eAAgB,UAAU,gBAAe,CAAC,CAAC,MAAM,CAAC,GAAG,EAAE,gDA0ChF,CAAC;AAEL,eAAO,MAAM,kBAAkB,gBAAiB,CAAC,CAAC,MAAM,CAAC,GAAG,EAAE,WAiB7D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.test.d.ts","sourceRoot":"","sources":["../../../../src/testing/query.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type Schema as S } from '@effect/schema';
|
|
2
|
+
import { type JsonSchemaType } from '@dxos/echo-schema';
|
|
3
|
+
import { type DataSource, type Node, type Relationship } from '../cypher';
|
|
4
|
+
import type { EchoDatabase } from '@dxos/echo-db';
|
|
5
|
+
export declare const seedTestData: (db: EchoDatabase) => void;
|
|
6
|
+
export declare const createTestData: () => MockDataSource;
|
|
7
|
+
export declare class MockDataSource implements DataSource {
|
|
8
|
+
objects: Record<string, {
|
|
9
|
+
schema: S.Schema.All;
|
|
10
|
+
typeDxn: string;
|
|
11
|
+
id: string;
|
|
12
|
+
data: unknown;
|
|
13
|
+
}>;
|
|
14
|
+
schema: Record<string, {
|
|
15
|
+
json: JsonSchemaType;
|
|
16
|
+
instance: S.Schema.All;
|
|
17
|
+
}>;
|
|
18
|
+
nodes: Node[];
|
|
19
|
+
relationships: Relationship[];
|
|
20
|
+
getNodes({ label }: {
|
|
21
|
+
label?: string;
|
|
22
|
+
}): Promise<Node[]>;
|
|
23
|
+
getRelationships({ label }: {
|
|
24
|
+
label?: string;
|
|
25
|
+
}): Promise<Relationship[]>;
|
|
26
|
+
add<S extends S.Schema.All>(schema: S, data: S.Schema.Type<S>): S.Schema.Type<S>;
|
|
27
|
+
computeGraph(): void;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=test-data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-data.d.ts","sourceRoot":"","sources":["../../../../src/testing/test-data.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,MAAM,IAAI,CAAC,EAAE,MAAM,gBAAgB,CAAC;AAGlD,OAAO,EAAmD,KAAK,cAAc,EAAY,MAAM,mBAAmB,CAAC;AAInH,OAAO,EACL,KAAK,UAAU,EACf,KAAK,IAAI,EACT,KAAK,YAAY,EAGlB,MAAM,WAAW,CAAC;AAEnB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD,eAAO,MAAM,YAAY,OAAQ,YAAY,SAoH5C,CAAC;AAGF,eAAO,MAAM,cAAc,QAAO,cAuGjC,CAAC;AAEF,qBAAa,cAAe,YAAW,UAAU;IAC/C,OAAO,EAAE,MAAM,CACb,MAAM,EACN;QACE,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;QACrB,OAAO,EAAE,MAAM,CAAC;QAChB,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,OAAO,CAAC;KACf,CACF,CAAM;IAEP,MAAM,EAAE,MAAM,CACZ,MAAM,EACN;QACE,IAAI,EAAE,cAAc,CAAC;QACrB,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;KACxB,CACF,CAAM;IAEP,KAAK,EAAE,IAAI,EAAE,CAAM;IACnB,aAAa,EAAE,YAAY,EAAE,CAAM;IAE7B,QAAQ,CAAC,EAAE,KAAK,EAAE,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE;IAItC,gBAAgB,CAAC,EAAE,KAAK,EAAE,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE;IAIpD,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IAsB7D,YAAY;CAoEb"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Schema as S } from '@effect/schema';
|
|
2
|
+
export declare const ObjectId: S.SchemaClass<string, string, never>;
|
|
3
|
+
export declare const Contact: S.mutable<S.Struct<{
|
|
4
|
+
id: S.SchemaClass<string, string, never>;
|
|
5
|
+
name: S.SchemaClass<string, string, never>;
|
|
6
|
+
email: S.optional<typeof S.String>;
|
|
7
|
+
}>>;
|
|
8
|
+
export interface Contact extends S.Schema.Type<typeof Contact> {
|
|
9
|
+
}
|
|
10
|
+
export declare const Project: S.mutable<S.Struct<{
|
|
11
|
+
id: S.SchemaClass<string, string, never>;
|
|
12
|
+
name: S.SchemaClass<string, string, never>;
|
|
13
|
+
description: S.optional<typeof S.String>;
|
|
14
|
+
}>>;
|
|
15
|
+
export interface Project extends S.Schema.Type<typeof Project> {
|
|
16
|
+
}
|
|
17
|
+
export declare const Task: S.mutable<S.Struct<{
|
|
18
|
+
id: S.SchemaClass<string, string, never>;
|
|
19
|
+
name: S.SchemaClass<string, string, never>;
|
|
20
|
+
description: S.optional<typeof S.String>;
|
|
21
|
+
project: import("@dxos/echo-schema").Ref$<{
|
|
22
|
+
id: string;
|
|
23
|
+
name: string;
|
|
24
|
+
description?: string | undefined;
|
|
25
|
+
}>;
|
|
26
|
+
assignee: import("@dxos/echo-schema").Ref$<{
|
|
27
|
+
id: string;
|
|
28
|
+
name: string;
|
|
29
|
+
email?: string | undefined;
|
|
30
|
+
}>;
|
|
31
|
+
}>>;
|
|
32
|
+
export interface Task extends S.Schema.Type<typeof Task> {
|
|
33
|
+
}
|
|
34
|
+
export declare const Org: S.mutable<S.Struct<{
|
|
35
|
+
id: S.SchemaClass<string, string, never>;
|
|
36
|
+
name: S.SchemaClass<string, string, never>;
|
|
37
|
+
projects: S.Array$<import("@dxos/echo-schema").Ref$<{
|
|
38
|
+
id: string;
|
|
39
|
+
name: string;
|
|
40
|
+
description?: string | undefined;
|
|
41
|
+
}>>;
|
|
42
|
+
employees: S.Array$<import("@dxos/echo-schema").Ref$<{
|
|
43
|
+
id: string;
|
|
44
|
+
name: string;
|
|
45
|
+
email?: string | undefined;
|
|
46
|
+
}>>;
|
|
47
|
+
}>>;
|
|
48
|
+
export interface Org extends S.Schema.Type<typeof Org> {
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=test-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-schema.d.ts","sourceRoot":"","sources":["../../../../src/testing/test-schema.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,gBAAgB,CAAC;AAQ7C,eAAO,MAAM,QAAQ,sCAAyE,CAAC;AAE/F,eAAO,MAAM,OAAO;;;;GAahB,CAAC;AACL,MAAM,WAAW,OAAQ,SAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,OAAO,CAAC;CAAG;AAEjE,eAAO,MAAM,OAAO;;;;GAahB,CAAC;AACL,MAAM,WAAW,OAAQ,SAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,OAAO,CAAC;CAAG;AAEjE,eAAO,MAAM,IAAI;;;;;;;;;;;;;;GAeb,CAAC;AACL,MAAM,WAAW,IAAK,SAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC;CAAG;AAE3D,eAAO,MAAM,GAAG;;;;;;;;;;;;;GAcZ,CAAC;AACL,MAAM,WAAW,GAAI,SAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,GAAG,CAAC;CAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/util/index.ts"],"names":[],"mappings":"AAIA,cAAc,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trim.d.ts","sourceRoot":"","sources":["../../../../src/util/trim.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,eAAO,MAAM,IAAI,YAAa,oBAAoB,aAAa,GAAG,EAAE,WAMnE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":"5.7.2"}
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dxos/assistant",
|
|
3
|
+
"version": "0.7.4-df37807",
|
|
4
|
+
"description": "Natural language interface to DXOS",
|
|
5
|
+
"homepage": "https://dxos.org",
|
|
6
|
+
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"author": "info@dxos.org",
|
|
9
|
+
"sideEffects": true,
|
|
10
|
+
"type": "module",
|
|
11
|
+
"imports": {
|
|
12
|
+
"#parjs": {
|
|
13
|
+
"browser": "./vendor/parjs-browser.mjs",
|
|
14
|
+
"default": "./vendor/parjs-default.mjs"
|
|
15
|
+
},
|
|
16
|
+
"#parjs/combinators": {
|
|
17
|
+
"browser": "./vendor/parjs-combinators-browser.mjs",
|
|
18
|
+
"default": "./vendor/parjs-combinators-default.mjs"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/types/src/index.d.ts",
|
|
24
|
+
"browser": "./dist/lib/browser/index.mjs",
|
|
25
|
+
"node": "./dist/lib/node-esm/index.mjs"
|
|
26
|
+
},
|
|
27
|
+
"./testing": {
|
|
28
|
+
"types": "./dist/types/src/testing/index.d.ts",
|
|
29
|
+
"browser": "./dist/lib/browser/testing/index.mjs",
|
|
30
|
+
"node": "./dist/lib/node-esm/testing/index.mjs"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"types": "dist/types/src/index.d.ts",
|
|
34
|
+
"files": [
|
|
35
|
+
"dist",
|
|
36
|
+
"src"
|
|
37
|
+
],
|
|
38
|
+
"scripts": {
|
|
39
|
+
"run:chat": "tsx src/bin/chat.ts"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@dxos/async": "workspace:*",
|
|
43
|
+
"@dxos/context": "workspace:*",
|
|
44
|
+
"@dxos/debug": "workspace:*",
|
|
45
|
+
"@dxos/echo-db": "workspace:*",
|
|
46
|
+
"@dxos/echo-schema": "workspace:*",
|
|
47
|
+
"@dxos/invariant": "workspace:*",
|
|
48
|
+
"@dxos/keys": "workspace:*",
|
|
49
|
+
"@dxos/live-object": "workspace:*",
|
|
50
|
+
"@dxos/log": "workspace:*",
|
|
51
|
+
"@dxos/node-std": "workspace:*",
|
|
52
|
+
"@dxos/util": "workspace:*",
|
|
53
|
+
"@effect/schema": "^0.75.5",
|
|
54
|
+
"parjs": "^1.3.9",
|
|
55
|
+
"ulidx": "^2.3.0"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"inquirer": "^12.0.0"
|
|
59
|
+
},
|
|
60
|
+
"publishConfig": {
|
|
61
|
+
"access": "restricted"
|
|
62
|
+
},
|
|
63
|
+
"beast": {}
|
|
64
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Schema as S } from '@effect/schema';
|
|
6
|
+
import { test, describe } from 'vitest';
|
|
7
|
+
|
|
8
|
+
import { toJsonSchema } from '@dxos/echo-schema';
|
|
9
|
+
import { invariant } from '@dxos/invariant';
|
|
10
|
+
import { SpaceId } from '@dxos/keys';
|
|
11
|
+
import { log } from '@dxos/log';
|
|
12
|
+
|
|
13
|
+
import { AIServiceClientImpl } from './client';
|
|
14
|
+
import { ObjectId, ToolTypes, type LLMTool } from './schema';
|
|
15
|
+
|
|
16
|
+
const ENDPOINT = 'http://localhost:8787';
|
|
17
|
+
|
|
18
|
+
describe('AI Service Client', () => {
|
|
19
|
+
test('client generation', async () => {
|
|
20
|
+
const client = new AIServiceClientImpl({
|
|
21
|
+
endpoint: ENDPOINT,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const spaceId = SpaceId.random();
|
|
25
|
+
const threadId = ObjectId.random();
|
|
26
|
+
|
|
27
|
+
await client.insertMessages([
|
|
28
|
+
{
|
|
29
|
+
id: ObjectId.random(),
|
|
30
|
+
spaceId,
|
|
31
|
+
threadId,
|
|
32
|
+
role: 'user',
|
|
33
|
+
content: [{ type: 'text', text: 'Hello' }],
|
|
34
|
+
},
|
|
35
|
+
]);
|
|
36
|
+
|
|
37
|
+
const stream = await client.generate({
|
|
38
|
+
model: '@anthropic/claude-3-5-haiku-20241022',
|
|
39
|
+
spaceId,
|
|
40
|
+
threadId,
|
|
41
|
+
systemPrompt: 'You are a poet',
|
|
42
|
+
tools: [],
|
|
43
|
+
});
|
|
44
|
+
for await (const event of stream) {
|
|
45
|
+
log.info('event', event);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
log.info('full message', {
|
|
49
|
+
message: await stream.complete(),
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('tool calls', async () => {
|
|
54
|
+
const client = new AIServiceClientImpl({
|
|
55
|
+
endpoint: ENDPOINT,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const custodian: LLMTool = {
|
|
59
|
+
name: 'custodian',
|
|
60
|
+
description: 'Custodian can tell you the password if you say the magic word',
|
|
61
|
+
parameters: toJsonSchema(
|
|
62
|
+
S.Struct({
|
|
63
|
+
magicWord: S.String.annotations({ description: 'The magic word. Should be exactly "pretty please"' }),
|
|
64
|
+
}),
|
|
65
|
+
),
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const spaceId = SpaceId.random();
|
|
69
|
+
const threadId = ObjectId.random();
|
|
70
|
+
|
|
71
|
+
await client.insertMessages([
|
|
72
|
+
{
|
|
73
|
+
id: ObjectId.random(),
|
|
74
|
+
spaceId,
|
|
75
|
+
threadId,
|
|
76
|
+
role: 'user',
|
|
77
|
+
content: [{ type: 'text', text: 'What is the password? Ask the custodian' }],
|
|
78
|
+
},
|
|
79
|
+
]);
|
|
80
|
+
|
|
81
|
+
const stream = await client.generate({
|
|
82
|
+
model: '@anthropic/claude-3-5-haiku-20241022',
|
|
83
|
+
spaceId,
|
|
84
|
+
threadId,
|
|
85
|
+
systemPrompt: 'You are a helpful assistant.',
|
|
86
|
+
tools: [custodian],
|
|
87
|
+
});
|
|
88
|
+
for await (const event of stream) {
|
|
89
|
+
log.info('event', event);
|
|
90
|
+
}
|
|
91
|
+
const [message] = await stream.complete();
|
|
92
|
+
log.info('full message', {
|
|
93
|
+
message,
|
|
94
|
+
});
|
|
95
|
+
await client.insertMessages([message]);
|
|
96
|
+
|
|
97
|
+
const toolUse = message.content.find(({ type }) => type === 'tool_use')!;
|
|
98
|
+
invariant(toolUse.type === 'tool_use');
|
|
99
|
+
await client.insertMessages([
|
|
100
|
+
{
|
|
101
|
+
id: ObjectId.random(),
|
|
102
|
+
spaceId,
|
|
103
|
+
threadId,
|
|
104
|
+
role: 'user',
|
|
105
|
+
content: [{ type: 'tool_result', toolUseId: toolUse.id, content: 'password="The sky is gray"' }],
|
|
106
|
+
},
|
|
107
|
+
]);
|
|
108
|
+
|
|
109
|
+
const stream2 = await client.generate({
|
|
110
|
+
model: '@anthropic/claude-3-5-haiku-20241022',
|
|
111
|
+
spaceId,
|
|
112
|
+
threadId,
|
|
113
|
+
systemPrompt: 'You are a helpful assistant.',
|
|
114
|
+
tools: [custodian],
|
|
115
|
+
});
|
|
116
|
+
for await (const event of stream2) {
|
|
117
|
+
log.info('event', event);
|
|
118
|
+
}
|
|
119
|
+
const [message2] = await stream2.complete();
|
|
120
|
+
log.info('full message', {
|
|
121
|
+
message: message2,
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test.only('image generation', async () => {
|
|
126
|
+
const client = new AIServiceClientImpl({
|
|
127
|
+
endpoint: ENDPOINT,
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const spaceId = SpaceId.random();
|
|
131
|
+
const threadId = ObjectId.random();
|
|
132
|
+
|
|
133
|
+
await client.insertMessages([
|
|
134
|
+
{
|
|
135
|
+
id: ObjectId.random(),
|
|
136
|
+
spaceId,
|
|
137
|
+
threadId,
|
|
138
|
+
role: 'user',
|
|
139
|
+
content: [{ type: 'text', text: 'Generate an image of a cat' }],
|
|
140
|
+
},
|
|
141
|
+
]);
|
|
142
|
+
|
|
143
|
+
const stream = await client.generate({
|
|
144
|
+
model: '@anthropic/claude-3-5-sonnet-20241022',
|
|
145
|
+
spaceId,
|
|
146
|
+
threadId,
|
|
147
|
+
tools: [
|
|
148
|
+
{
|
|
149
|
+
name: 'text-to-image',
|
|
150
|
+
type: ToolTypes.TextToImage,
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
});
|
|
154
|
+
for await (const event of stream) {
|
|
155
|
+
log.info('event', event);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
log.info('full message', {
|
|
159
|
+
message: await stream.complete(),
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
});
|