@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,48 @@
|
|
|
1
|
+
import type { SpaceId } from '@dxos/keys';
|
|
2
|
+
import { Message, type GenerateRequest, type ObjectId, type ResultStreamEvent, type Space, type Thread } from './schema';
|
|
3
|
+
export type AIServiceClientParams = {
|
|
4
|
+
endpoint: string;
|
|
5
|
+
};
|
|
6
|
+
export interface AIServiceClient {
|
|
7
|
+
getSpace(spaceId: SpaceId): Promise<Space>;
|
|
8
|
+
getThread(spaceId: SpaceId, threadId: string): Promise<Thread>;
|
|
9
|
+
getMessagesInThread(spaceId: SpaceId, threadId: string): Promise<Message[]>;
|
|
10
|
+
insertMessages(messages: Message[]): Promise<void>;
|
|
11
|
+
updateMessage(spaceId: SpaceId, threadId: string, messageId: string, message: Message): Promise<void>;
|
|
12
|
+
generate(request: GenerateRequest): Promise<GenerationStream>;
|
|
13
|
+
}
|
|
14
|
+
export declare class AIServiceClientImpl implements AIServiceClient {
|
|
15
|
+
private readonly _endpoint;
|
|
16
|
+
constructor({ endpoint }: AIServiceClientParams);
|
|
17
|
+
getSpace(spaceId: SpaceId): Promise<Space>;
|
|
18
|
+
getThread(spaceId: SpaceId, threadId: string): Promise<Thread>;
|
|
19
|
+
getMessagesInThread(spaceId: SpaceId, threadId: string): Promise<Message[]>;
|
|
20
|
+
insertMessages(messages: Message[]): Promise<void>;
|
|
21
|
+
updateMessage(spaceId: SpaceId, threadId: string, messageId: string, message: Message): Promise<void>;
|
|
22
|
+
generate(request: GenerateRequest): Promise<GenerationStream>;
|
|
23
|
+
}
|
|
24
|
+
type GenerationParams = {
|
|
25
|
+
spaceId: SpaceId;
|
|
26
|
+
threadId: ObjectId;
|
|
27
|
+
};
|
|
28
|
+
export declare class GenerationStream implements AsyncIterable<ResultStreamEvent> {
|
|
29
|
+
private readonly _params;
|
|
30
|
+
private readonly _getIterator;
|
|
31
|
+
static fromSSEResponse(params: GenerationParams, response: Response): GenerationStream;
|
|
32
|
+
private _previousMessages;
|
|
33
|
+
private _accumulatedMessage?;
|
|
34
|
+
private _done;
|
|
35
|
+
private _iterator?;
|
|
36
|
+
constructor(_params: GenerationParams, _getIterator: () => AsyncIterableIterator<ResultStreamEvent>);
|
|
37
|
+
[Symbol.asyncIterator](): AsyncIterator<ResultStreamEvent>;
|
|
38
|
+
cancel(): void;
|
|
39
|
+
get accumulatedMessages(): Message[];
|
|
40
|
+
/**
|
|
41
|
+
* Returns the complete message list generated by the AI service.
|
|
42
|
+
*/
|
|
43
|
+
complete(): Promise<Message[]>;
|
|
44
|
+
private _createIterator;
|
|
45
|
+
private _processEvent;
|
|
46
|
+
}
|
|
47
|
+
export {};
|
|
48
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../src/ai-service/client.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,OAAO,EACL,OAAO,EACP,KAAK,eAAe,EACpB,KAAK,QAAQ,EACb,KAAK,iBAAiB,EACtB,KAAK,KAAK,EACV,KAAK,MAAM,EACZ,MAAM,UAAU,CAAC;AAIlB,MAAM,MAAM,qBAAqB,GAAG;IAClC,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,WAAW,eAAe;IAC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AC,gBAAgB,CAAC;CAgBpE;AAED,KAAK,gBAAgB,GAAG;IACtB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,QAAQ,CAAC;CACpB,CAAC;AAEF,qBAAa,gBAAiB,YAAW,aAAa,CAAC,iBAAiB,CAAC;IAkDrE,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,YAAY;IAlD/B,MAAM,CAAC,eAAe,CAAC,MAAM,EAAE,gBAAgB,EAAE,QAAQ,EAAE,QAAQ;IA2CnE,OAAO,CAAC,iBAAiB,CAAiB;IAC1C,OAAO,CAAC,mBAAmB,CAAC,CAAsB;IAClD,OAAO,CAAC,KAAK,CAAiB;IAC9B,OAAO,CAAC,SAAS,CAAC,CAA+C;gBAG9C,OAAO,EAAE,gBAAgB,EACzB,YAAY,EAAE,MAAM,qBAAqB,CAAC,iBAAiB,CAAC;IAG/E,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,iBAAiB,CAAC;IAI1D,MAAM;IAIN,IAAI,mBAAmB,IAAI,OAAO,EAAE,CAGnC;IAED;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAKpC,OAAO,CAAC,eAAe;IAUvB,OAAO,CAAC,aAAa;CA4DtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.test.d.ts","sourceRoot":"","sources":["../../../../src/ai-service/client.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ai-service/index.ts"],"names":[],"mappings":"AAIA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { Schema as S } from '@effect/schema';
|
|
2
|
+
import { type Brand } from 'effect';
|
|
3
|
+
import { JsonSchemaType } from '@dxos/echo-schema';
|
|
4
|
+
import { SpaceId } from '@dxos/keys';
|
|
5
|
+
export declare const SpaceIdSchema: S.Schema<SpaceId, string>;
|
|
6
|
+
export declare const ObjectIdBrand: unique symbol;
|
|
7
|
+
declare const ObjectIdSchema: S.brand<typeof S.ULID, typeof ObjectIdBrand>;
|
|
8
|
+
export type ObjectId = typeof ObjectIdSchema.Type;
|
|
9
|
+
export declare const ObjectId: S.SchemaClass<string & Brand.Brand<typeof ObjectIdBrand>, string> & {
|
|
10
|
+
random(): ObjectId;
|
|
11
|
+
};
|
|
12
|
+
export declare const Space: S.Struct<{
|
|
13
|
+
id: S.Schema<SpaceId, string, never>;
|
|
14
|
+
}>;
|
|
15
|
+
export interface Space extends S.Schema.Type<typeof Space> {
|
|
16
|
+
}
|
|
17
|
+
export declare const Thread: S.Struct<{
|
|
18
|
+
id: S.SchemaClass<string & Brand.Brand<typeof ObjectIdBrand>, string, never> & {
|
|
19
|
+
random(): ObjectId;
|
|
20
|
+
};
|
|
21
|
+
spaceId: S.Schema<SpaceId, string, never>;
|
|
22
|
+
}>;
|
|
23
|
+
export interface Thread extends S.Schema.Type<typeof Thread> {
|
|
24
|
+
}
|
|
25
|
+
export declare const MessageRole: S.refine<"user" | "assistant", S.Schema<string, string, never>>;
|
|
26
|
+
export type MessageRole = S.Schema.Type<typeof MessageRole>;
|
|
27
|
+
export declare const MessageTextContentBlock: S.mutable<S.Struct<{
|
|
28
|
+
type: S.Literal<["text"]>;
|
|
29
|
+
text: typeof S.String;
|
|
30
|
+
}>>;
|
|
31
|
+
export type MessageTextContentBlock = S.Schema.Type<typeof MessageTextContentBlock>;
|
|
32
|
+
export declare const ImageSource: S.mutable<S.Struct<{
|
|
33
|
+
type: S.Literal<["base64"]>;
|
|
34
|
+
media_type: S.Literal<["image/jpeg", "image/png", "image/gif", "image/webp"]>;
|
|
35
|
+
data: typeof S.String;
|
|
36
|
+
}>>;
|
|
37
|
+
export type ImageSource = S.Schema.Type<typeof ImageSource>;
|
|
38
|
+
export declare const MessageImageContentBlock: S.mutable<S.Struct<{
|
|
39
|
+
type: S.Literal<["image"]>;
|
|
40
|
+
id: S.optional<typeof S.String>;
|
|
41
|
+
source: S.optional<S.mutable<S.Struct<{
|
|
42
|
+
type: S.Literal<["base64"]>;
|
|
43
|
+
media_type: S.Literal<["image/jpeg", "image/png", "image/gif", "image/webp"]>;
|
|
44
|
+
data: typeof S.String;
|
|
45
|
+
}>>>;
|
|
46
|
+
}>>;
|
|
47
|
+
export type MessageImageContentBlock = S.Schema.Type<typeof MessageImageContentBlock>;
|
|
48
|
+
export declare const MessageToolUseContentBlock: S.mutable<S.Struct<{
|
|
49
|
+
type: S.Literal<["tool_use"]>;
|
|
50
|
+
/**
|
|
51
|
+
* Opaque service-defined ID of the tool invocation.
|
|
52
|
+
* Used to match the tool result block.
|
|
53
|
+
*/
|
|
54
|
+
id: typeof S.String;
|
|
55
|
+
/**
|
|
56
|
+
* Tool name.
|
|
57
|
+
*/
|
|
58
|
+
name: typeof S.String;
|
|
59
|
+
input: typeof S.Unknown;
|
|
60
|
+
/**
|
|
61
|
+
* Used to accumulate the partial tool input JSON in streaming mode.
|
|
62
|
+
*/
|
|
63
|
+
inputJson: S.optional<typeof S.String>;
|
|
64
|
+
}>>;
|
|
65
|
+
export declare const MessageToolResultContentBlock: S.Struct<{
|
|
66
|
+
type: S.Literal<["tool_result"]>;
|
|
67
|
+
toolUseId: typeof S.String;
|
|
68
|
+
content: typeof S.String;
|
|
69
|
+
isError: S.optional<typeof S.Boolean>;
|
|
70
|
+
}>;
|
|
71
|
+
export declare const MessageContentBlock: S.Union<[S.mutable<S.Struct<{
|
|
72
|
+
type: S.Literal<["text"]>;
|
|
73
|
+
text: typeof S.String;
|
|
74
|
+
}>>, S.mutable<S.Struct<{
|
|
75
|
+
type: S.Literal<["image"]>;
|
|
76
|
+
id: S.optional<typeof S.String>;
|
|
77
|
+
source: S.optional<S.mutable<S.Struct<{
|
|
78
|
+
type: S.Literal<["base64"]>;
|
|
79
|
+
media_type: S.Literal<["image/jpeg", "image/png", "image/gif", "image/webp"]>;
|
|
80
|
+
data: typeof S.String;
|
|
81
|
+
}>>>;
|
|
82
|
+
}>>, S.mutable<S.Struct<{
|
|
83
|
+
type: S.Literal<["tool_use"]>;
|
|
84
|
+
/**
|
|
85
|
+
* Opaque service-defined ID of the tool invocation.
|
|
86
|
+
* Used to match the tool result block.
|
|
87
|
+
*/
|
|
88
|
+
id: typeof S.String;
|
|
89
|
+
/**
|
|
90
|
+
* Tool name.
|
|
91
|
+
*/
|
|
92
|
+
name: typeof S.String;
|
|
93
|
+
input: typeof S.Unknown;
|
|
94
|
+
/**
|
|
95
|
+
* Used to accumulate the partial tool input JSON in streaming mode.
|
|
96
|
+
*/
|
|
97
|
+
inputJson: S.optional<typeof S.String>;
|
|
98
|
+
}>>, S.Struct<{
|
|
99
|
+
type: S.Literal<["tool_result"]>;
|
|
100
|
+
toolUseId: typeof S.String;
|
|
101
|
+
content: typeof S.String;
|
|
102
|
+
isError: S.optional<typeof S.Boolean>;
|
|
103
|
+
}>]>;
|
|
104
|
+
export type MessageContentBlock = S.Schema.Type<typeof MessageContentBlock>;
|
|
105
|
+
export declare const Message: S.Struct<{
|
|
106
|
+
id: S.SchemaClass<string & Brand.Brand<typeof ObjectIdBrand>, string, never> & {
|
|
107
|
+
random(): ObjectId;
|
|
108
|
+
};
|
|
109
|
+
threadId: S.optional<S.SchemaClass<string & Brand.Brand<typeof ObjectIdBrand>, string, never> & {
|
|
110
|
+
random(): ObjectId;
|
|
111
|
+
}>;
|
|
112
|
+
spaceId: S.optional<S.Schema<SpaceId, string, never>>;
|
|
113
|
+
role: S.refine<"user" | "assistant", S.Schema<string, string, never>>;
|
|
114
|
+
content: S.mutable<S.Array$<S.Union<[S.mutable<S.Struct<{
|
|
115
|
+
type: S.Literal<["text"]>;
|
|
116
|
+
text: typeof S.String;
|
|
117
|
+
}>>, S.mutable<S.Struct<{
|
|
118
|
+
type: S.Literal<["image"]>;
|
|
119
|
+
id: S.optional<typeof S.String>;
|
|
120
|
+
source: S.optional<S.mutable<S.Struct<{
|
|
121
|
+
type: S.Literal<["base64"]>;
|
|
122
|
+
media_type: S.Literal<["image/jpeg", "image/png", "image/gif", "image/webp"]>;
|
|
123
|
+
data: typeof S.String;
|
|
124
|
+
}>>>;
|
|
125
|
+
}>>, S.mutable<S.Struct<{
|
|
126
|
+
type: S.Literal<["tool_use"]>;
|
|
127
|
+
/**
|
|
128
|
+
* Opaque service-defined ID of the tool invocation.
|
|
129
|
+
* Used to match the tool result block.
|
|
130
|
+
*/
|
|
131
|
+
id: typeof S.String;
|
|
132
|
+
/**
|
|
133
|
+
* Tool name.
|
|
134
|
+
*/
|
|
135
|
+
name: typeof S.String;
|
|
136
|
+
input: typeof S.Unknown;
|
|
137
|
+
/**
|
|
138
|
+
* Used to accumulate the partial tool input JSON in streaming mode.
|
|
139
|
+
*/
|
|
140
|
+
inputJson: S.optional<typeof S.String>;
|
|
141
|
+
}>>, S.Struct<{
|
|
142
|
+
type: S.Literal<["tool_result"]>;
|
|
143
|
+
toolUseId: typeof S.String;
|
|
144
|
+
content: typeof S.String;
|
|
145
|
+
isError: S.optional<typeof S.Boolean>;
|
|
146
|
+
}>]>>>;
|
|
147
|
+
/**
|
|
148
|
+
* ID of the message from the foreign provider.
|
|
149
|
+
*/
|
|
150
|
+
foreignId: S.optional<typeof S.String>;
|
|
151
|
+
}>;
|
|
152
|
+
export interface Message extends S.Schema.Type<typeof Message> {
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Message transformed from the database row.
|
|
156
|
+
*/
|
|
157
|
+
export declare const MessageFromDb: S.Struct<{
|
|
158
|
+
content: S.PropertySignature<":", ({
|
|
159
|
+
type: "text";
|
|
160
|
+
text: string;
|
|
161
|
+
} | {
|
|
162
|
+
id?: string | undefined;
|
|
163
|
+
type: "image";
|
|
164
|
+
source?: {
|
|
165
|
+
type: "base64";
|
|
166
|
+
media_type: "image/jpeg" | "image/png" | "image/gif" | "image/webp";
|
|
167
|
+
data: string;
|
|
168
|
+
} | undefined;
|
|
169
|
+
} | {
|
|
170
|
+
id: string;
|
|
171
|
+
type: "tool_use";
|
|
172
|
+
name: string;
|
|
173
|
+
input: unknown;
|
|
174
|
+
inputJson?: string | undefined;
|
|
175
|
+
} | {
|
|
176
|
+
readonly type: "tool_result";
|
|
177
|
+
readonly toolUseId: string;
|
|
178
|
+
readonly content: string;
|
|
179
|
+
readonly isError?: boolean | undefined;
|
|
180
|
+
})[], "contentJson", ":", string, false, never>;
|
|
181
|
+
id: S.SchemaClass<string & Brand.Brand<typeof ObjectIdBrand>, string, never> & {
|
|
182
|
+
random(): ObjectId;
|
|
183
|
+
};
|
|
184
|
+
threadId: S.optional<S.SchemaClass<string & Brand.Brand<typeof ObjectIdBrand>, string, never> & {
|
|
185
|
+
random(): ObjectId;
|
|
186
|
+
}>;
|
|
187
|
+
spaceId: S.optional<S.Schema<SpaceId, string, never>>;
|
|
188
|
+
role: S.refine<"user" | "assistant", S.Schema<string, string, never>>;
|
|
189
|
+
foreignId: S.optional<typeof S.String>;
|
|
190
|
+
}>;
|
|
191
|
+
export declare const LLMModel: S.Literal<["@hf/nousresearch/hermes-2-pro-mistral-7b", "@anthropic/claude-3-5-sonnet-20241022", "@anthropic/claude-3-5-haiku-20241022", "@ollama/llama-3-2-3b", "@ollama/llama-3-1-nemotron-70b-instruct", "@ollama/llama-3-1-nemotron-mini-4b-instruct"]>;
|
|
192
|
+
export type LLMModel = S.Schema.Type<typeof LLMModel>;
|
|
193
|
+
export declare const ToolTypes: Readonly<{
|
|
194
|
+
TextToImage: "text_to_image";
|
|
195
|
+
}>;
|
|
196
|
+
export declare const LLMTool: S.Struct<{
|
|
197
|
+
name: typeof S.String;
|
|
198
|
+
/**
|
|
199
|
+
* If the tool is implemented by the service a type should be provided.
|
|
200
|
+
* For user-implemented tools, this field should be omitted.
|
|
201
|
+
* See {@link ToolTypes} for the list of supported types.
|
|
202
|
+
*/
|
|
203
|
+
type: S.optional<typeof S.String>;
|
|
204
|
+
/**
|
|
205
|
+
* Required for user-implemented tools.
|
|
206
|
+
*/
|
|
207
|
+
description: S.optional<typeof S.String>;
|
|
208
|
+
/**
|
|
209
|
+
* Input schema for the tool in the JSON Schema format.
|
|
210
|
+
* Required for user-implemented tools.
|
|
211
|
+
*/
|
|
212
|
+
parameters: S.optional<S.Schema<JsonSchemaType, JsonSchemaType, never>>;
|
|
213
|
+
/**
|
|
214
|
+
* Tool-specific options.
|
|
215
|
+
*/
|
|
216
|
+
options: S.optional<typeof S.Any>;
|
|
217
|
+
/**
|
|
218
|
+
* Javascript function to execute the tool.
|
|
219
|
+
*/
|
|
220
|
+
execute: S.optional<typeof S.Any>;
|
|
221
|
+
}>;
|
|
222
|
+
export interface LLMTool extends S.Schema.Type<typeof LLMTool> {
|
|
223
|
+
}
|
|
224
|
+
export declare const GenerateRequest: S.Struct<{
|
|
225
|
+
model: S.Literal<["@hf/nousresearch/hermes-2-pro-mistral-7b", "@anthropic/claude-3-5-sonnet-20241022", "@anthropic/claude-3-5-haiku-20241022", "@ollama/llama-3-2-3b", "@ollama/llama-3-1-nemotron-70b-instruct", "@ollama/llama-3-1-nemotron-mini-4b-instruct"]>;
|
|
226
|
+
spaceId: S.Schema<SpaceId, string, never>;
|
|
227
|
+
threadId: S.SchemaClass<string & Brand.Brand<typeof ObjectIdBrand>, string, never> & {
|
|
228
|
+
random(): ObjectId;
|
|
229
|
+
};
|
|
230
|
+
/**
|
|
231
|
+
* System instructions to the LLM.
|
|
232
|
+
*/
|
|
233
|
+
systemPrompt: S.optional<typeof S.String>;
|
|
234
|
+
/**
|
|
235
|
+
* Tools available for the LLM.
|
|
236
|
+
*/
|
|
237
|
+
tools: S.mutable<S.Array$<S.Struct<{
|
|
238
|
+
name: typeof S.String;
|
|
239
|
+
/**
|
|
240
|
+
* If the tool is implemented by the service a type should be provided.
|
|
241
|
+
* For user-implemented tools, this field should be omitted.
|
|
242
|
+
* See {@link ToolTypes} for the list of supported types.
|
|
243
|
+
*/
|
|
244
|
+
type: S.optional<typeof S.String>;
|
|
245
|
+
/**
|
|
246
|
+
* Required for user-implemented tools.
|
|
247
|
+
*/
|
|
248
|
+
description: S.optional<typeof S.String>;
|
|
249
|
+
/**
|
|
250
|
+
* Input schema for the tool in the JSON Schema format.
|
|
251
|
+
* Required for user-implemented tools.
|
|
252
|
+
*/
|
|
253
|
+
parameters: S.optional<S.Schema<JsonSchemaType, JsonSchemaType, never>>;
|
|
254
|
+
/**
|
|
255
|
+
* Tool-specific options.
|
|
256
|
+
*/
|
|
257
|
+
options: S.optional<typeof S.Any>;
|
|
258
|
+
/**
|
|
259
|
+
* Javascript function to execute the tool.
|
|
260
|
+
*/
|
|
261
|
+
execute: S.optional<typeof S.Any>;
|
|
262
|
+
}>>>;
|
|
263
|
+
}>;
|
|
264
|
+
export interface GenerateRequest extends S.Schema.Type<typeof GenerateRequest> {
|
|
265
|
+
}
|
|
266
|
+
export type LLMStopReason = 'tool_use' | 'end_turn';
|
|
267
|
+
export type ResultStreamEvent = {
|
|
268
|
+
type: 'message_start';
|
|
269
|
+
message: Omit<Message, 'spaceId' | 'threadId'>;
|
|
270
|
+
} | {
|
|
271
|
+
type: 'message_delta';
|
|
272
|
+
delta: {
|
|
273
|
+
stopReason: LLMStopReason;
|
|
274
|
+
};
|
|
275
|
+
} | {
|
|
276
|
+
type: 'message_stop';
|
|
277
|
+
} | {
|
|
278
|
+
type: 'content_block_start';
|
|
279
|
+
index: number;
|
|
280
|
+
content: MessageContentBlock;
|
|
281
|
+
} | {
|
|
282
|
+
type: 'content_block_delta';
|
|
283
|
+
index: number;
|
|
284
|
+
delta: {
|
|
285
|
+
type: 'text_delta';
|
|
286
|
+
text: string;
|
|
287
|
+
} | {
|
|
288
|
+
partial_json: string;
|
|
289
|
+
type: 'input_json_delta';
|
|
290
|
+
};
|
|
291
|
+
} | {
|
|
292
|
+
type: 'content_block_stop';
|
|
293
|
+
index: number;
|
|
294
|
+
};
|
|
295
|
+
export {};
|
|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,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export declare function iterSSEMessages(response: Response, controller: AbortController): AsyncGenerator<ServerSentEvent, void, unknown>;
|
|
2
|
+
export type ServerSentEvent = {
|
|
3
|
+
event: string | null;
|
|
4
|
+
data: string;
|
|
5
|
+
raw: string[];
|
|
6
|
+
};
|
|
7
|
+
/** This is an internal helper function that's just used for testing */
|
|
8
|
+
export declare const _decodeChunks: (chunks: string[]) => string[];
|
|
9
|
+
/**
|
|
10
|
+
* Most browsers don't yet have async iterable support for ReadableStream,
|
|
11
|
+
* and Node has a very different way of reading bytes from its "ReadableStream".
|
|
12
|
+
*
|
|
13
|
+
* This polyfill was pulled from https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490
|
|
14
|
+
*/
|
|
15
|
+
export declare function readableStreamAsyncIterable<T>(stream: any): AsyncIterableIterator<T>;
|
|
16
|
+
export type Bytes = string | ArrayBuffer | Uint8Array | Buffer | null | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* A re-implementation of httpx's `LineDecoder` in Python that handles incrementally
|
|
19
|
+
* reading lines from text.
|
|
20
|
+
*
|
|
21
|
+
* https://github.com/encode/httpx/blob/920333ea98118e9cf617f246905d7b202510941c/httpx/_decoders.py#L258
|
|
22
|
+
*/
|
|
23
|
+
export declare class LineDecoder {
|
|
24
|
+
static NEWLINE_CHARS: Set<string>;
|
|
25
|
+
static NEWLINE_REGEXP: RegExp;
|
|
26
|
+
buffer: string[];
|
|
27
|
+
trailingCR: boolean;
|
|
28
|
+
textDecoder: any;
|
|
29
|
+
constructor();
|
|
30
|
+
decode(chunk: Bytes): string[];
|
|
31
|
+
decodeText(bytes: Bytes): string;
|
|
32
|
+
flush(): string[];
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=sse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../../../src/ai-service/sse.ts"],"names":[],"mappings":"AAKA,wBAAuB,eAAe,CACpC,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,eAAe,GAC1B,cAAc,CAAC,eAAe,EAAE,IAAI,EAAE,OAAO,CAAC,CAyBhD;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,EAAE,CAAC;CACf,CAAC;AA8HF,uEAAuE;AACvE,eAAO,MAAM,aAAa,WAAY,MAAM,EAAE,KAAG,MAAM,EAQtD,CAAC;AAWF;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,GAAG,qBAAqB,CAAC,CAAC,CAAC,CA6BpF;AAED,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG,WAAW,GAAG,UAAU,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;AAElF;;;;;GAKG;AACH,qBAAa,WAAW;IAEtB,MAAM,CAAC,aAAa,cAAyB;IAC7C,MAAM,CAAC,cAAc,SAAkB;IAEvC,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,EAAE,GAAG,CAAC;;IAOjB,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,EAAE;IA0C9B,UAAU,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM;IAuChC,KAAK,IAAI,MAAM,EAAE;CAUlB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../../../src/bin/chat.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type SpaceId } from '@dxos/keys';
|
|
2
|
+
import { ObjectId, type LLMTool } from '../ai-service';
|
|
3
|
+
import { type AIServiceClient, type Message, type ResultStreamEvent, type LLMModel } from '../ai-service';
|
|
4
|
+
export type CreateLLMConversationParams = {
|
|
5
|
+
model: LLMModel;
|
|
6
|
+
/**
|
|
7
|
+
* System prompt that specifies instructions for the LLM.
|
|
8
|
+
*/
|
|
9
|
+
system?: string;
|
|
10
|
+
spaceId: SpaceId;
|
|
11
|
+
threadId: ObjectId;
|
|
12
|
+
tools: LLMTool[];
|
|
13
|
+
client: AIServiceClient;
|
|
14
|
+
logger?: (event: ConversationEvent) => void;
|
|
15
|
+
};
|
|
16
|
+
export type ConversationEvent = {
|
|
17
|
+
type: 'message';
|
|
18
|
+
message: Message;
|
|
19
|
+
} | ResultStreamEvent;
|
|
20
|
+
export declare const runLLM: (params: CreateLLMConversationParams) => Promise<{
|
|
21
|
+
result: any;
|
|
22
|
+
}>;
|
|
23
|
+
//# sourceMappingURL=conversation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../../../src/conversation/conversation.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAI1C,OAAO,EAAE,QAAQ,EAAE,KAAK,OAAO,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,OAAO,EAAE,KAAK,iBAAiB,EAAE,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE1G,MAAM,MAAM,2BAA2B,GAAG;IACxC,KAAK,EAAE,QAAQ,CAAC;IAEhB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,QAAQ,CAAC;IAEnB,KAAK,EAAE,OAAO,EAAE,CAAC;IAEjB,MAAM,EAAE,eAAe,CAAC;IAExB,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,iBAAiB,GACzB;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;CAClB,GACD,iBAAiB,CAAC;AAEtB,eAAO,MAAM,MAAM,WAAkB,2BAA2B;;EAgG/D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversation.test.d.ts","sourceRoot":"","sources":["../../../../src/conversation/conversation.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/conversation/index.ts"],"names":[],"mappings":"AAIA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Schema as S } from '@effect/schema';
|
|
2
|
+
import { JsonSchemaType } from '@dxos/echo-schema';
|
|
3
|
+
import type { SpaceId } from '@dxos/keys';
|
|
4
|
+
import { ObjectId, type Message } from '../ai-service';
|
|
5
|
+
export declare const createUserMessage: (spaceId: SpaceId, threadId: ObjectId, text: string) => Message;
|
|
6
|
+
export declare const LLMToolDefinition: S.Struct<{
|
|
7
|
+
name: typeof S.String;
|
|
8
|
+
description: typeof S.String;
|
|
9
|
+
parameters: S.Schema<JsonSchemaType, JsonSchemaType, never>;
|
|
10
|
+
execute: typeof S.Any;
|
|
11
|
+
}>;
|
|
12
|
+
export type LLMToolDefinition = {
|
|
13
|
+
name: string;
|
|
14
|
+
description: string;
|
|
15
|
+
parameters: JsonSchemaType;
|
|
16
|
+
execute: (params: unknown, context: ToolExecutionContext) => Promise<LLMToolResult>;
|
|
17
|
+
};
|
|
18
|
+
export type ToolExecutionContext = {};
|
|
19
|
+
export type LLMToolResult = {
|
|
20
|
+
kind: 'success';
|
|
21
|
+
result: unknown;
|
|
22
|
+
} | {
|
|
23
|
+
kind: 'error';
|
|
24
|
+
message: string;
|
|
25
|
+
} | {
|
|
26
|
+
kind: 'break';
|
|
27
|
+
result: unknown;
|
|
28
|
+
};
|
|
29
|
+
export declare const LLMToolResult: Readonly<{
|
|
30
|
+
/**
|
|
31
|
+
* The tool execution was successful.
|
|
32
|
+
* Gives the result back to the LLM.
|
|
33
|
+
*/
|
|
34
|
+
Success: (result: unknown) => LLMToolResult;
|
|
35
|
+
Error: (message: string) => LLMToolResult;
|
|
36
|
+
/**
|
|
37
|
+
* Stop the conversation and return the result.
|
|
38
|
+
*/
|
|
39
|
+
Break: (result: unknown) => LLMToolResult;
|
|
40
|
+
}>;
|
|
41
|
+
export type DefineToolParams<Params extends S.Schema.AnyNoContext> = {
|
|
42
|
+
name: string;
|
|
43
|
+
description: string;
|
|
44
|
+
schema: Params;
|
|
45
|
+
execute: (params: S.Schema.Type<Params>, context: ToolExecutionContext) => Promise<LLMToolResult>;
|
|
46
|
+
};
|
|
47
|
+
export declare const defineTool: <Params extends S.Schema.AnyNoContext>({ name, description, schema, execute, }: DefineToolParams<Params>) => LLMToolDefinition;
|
|
48
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/conversation/types.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,gBAAgB,CAAC;AAG7C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAG1C,OAAO,EAAE,QAAQ,EAAE,KAAK,OAAO,EAAE,MAAM,eAAe,CAAC;AAEvD,eAAO,MAAM,iBAAiB,YAAa,OAAO,YAAY,QAAQ,QAAQ,MAAM,KAAG,OAMrF,CAAC;AAEH,eAAO,MAAM,iBAAiB;;;;;EAK5B,CAAC;AAEH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,cAAc,CAAC;IAC3B,OAAO,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,oBAAoB,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC;CACrF,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAEtC,MAAM,MAAM,aAAa,GACrB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GACpC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAClC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,CAAC;AAEvC,eAAO,MAAM,aAAa;IACxB;;;OAGG;sBACe,OAAO,KAAG,aAAa;qBAExB,MAAM,KAAG,aAAa;IACvC;;OAEG;oBACa,OAAO,KAAG,aAAa;EACvC,CAAC;AAEH,MAAM,MAAM,gBAAgB,CAAC,MAAM,SAAS,CAAC,CAAC,MAAM,CAAC,YAAY,IAAI;IACnE,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,oBAAoB,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC;CACnG,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,MAAM,SAAS,CAAC,CAAC,MAAM,CAAC,YAAY,2CAK5D,gBAAgB,CAAC,MAAM,CAAC,KAAG,iBAU7B,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export interface AstNode<Kind extends string> {
|
|
2
|
+
astKind: Kind;
|
|
3
|
+
}
|
|
4
|
+
export interface Identifier extends AstNode<'Identifier'> {
|
|
5
|
+
name: string;
|
|
6
|
+
}
|
|
7
|
+
export interface Property {
|
|
8
|
+
key: Identifier;
|
|
9
|
+
value: StringLiteral;
|
|
10
|
+
}
|
|
11
|
+
export interface Properties extends AstNode<'Properties'> {
|
|
12
|
+
properties: Property[];
|
|
13
|
+
}
|
|
14
|
+
export interface NodePattern extends AstNode<'NodePattern'> {
|
|
15
|
+
variable: Identifier | null;
|
|
16
|
+
label: Identifier;
|
|
17
|
+
properties: Properties | null;
|
|
18
|
+
}
|
|
19
|
+
export interface RelationshipPattern extends AstNode<'RelationshipPattern'> {
|
|
20
|
+
variable: Identifier | null;
|
|
21
|
+
label: Identifier;
|
|
22
|
+
properties: Properties | null;
|
|
23
|
+
}
|
|
24
|
+
export interface GraphPatternConnector extends AstNode<'GraphPatternConnector'> {
|
|
25
|
+
direction: '-' | '->' | '<-';
|
|
26
|
+
}
|
|
27
|
+
export interface GraphPattern extends AstNode<'GraphPattern'> {
|
|
28
|
+
segments: (NodePattern | RelationshipPattern)[] & {
|
|
29
|
+
separators: GraphPatternConnector[];
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export interface MatchClause extends AstNode<'MatchClause'> {
|
|
33
|
+
pattern: GraphPattern;
|
|
34
|
+
}
|
|
35
|
+
export interface StringLiteral extends AstNode<'StringLiteral'> {
|
|
36
|
+
value: string;
|
|
37
|
+
}
|
|
38
|
+
export interface MemberExpression extends AstNode<'MemberExpression'> {
|
|
39
|
+
path: Identifier[];
|
|
40
|
+
}
|
|
41
|
+
export interface EqualsPredicate extends AstNode<'EqualsPredicate'> {
|
|
42
|
+
left: MemberExpression;
|
|
43
|
+
right: StringLiteral;
|
|
44
|
+
}
|
|
45
|
+
export interface WhereClause extends AstNode<'WhereClause'> {
|
|
46
|
+
predicates: EqualsPredicate[];
|
|
47
|
+
}
|
|
48
|
+
export interface ReturnClause extends AstNode<'ReturnClause'> {
|
|
49
|
+
fields: MemberExpression[];
|
|
50
|
+
}
|
|
51
|
+
export interface CypherQuery extends AstNode<'CypherQuery'> {
|
|
52
|
+
matchClause: MatchClause;
|
|
53
|
+
whereClause: WhereClause | null;
|
|
54
|
+
returnClause: ReturnClause;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=ast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AM,WAAW,aAAc,SAAQ,OAAO,CAAC,eAAe,CAAC;IAC7D,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,gBAAiB,SAAQ,OAAO,CAAC,kBAAkB,CAAC;IACnE,IAAI,EAAE,UAAU,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,eAAgB,SAAQ,OAAO,CAAC,iBAAiB,CAAC;IACjE,IAAI,EAAE,gBAAgB,CAAC;IACvB,KAAK,EAAE,aAAa,CAAC;CACtB;AAED,MAAM,WAAW,WAAY,SAAQ,OAAO,CAAC,aAAa,CAAC;IACzD,UAAU,EAAE,eAAe,EAAE,CAAC;CAC/B;AAED,MAAM,WAAW,YAAa,SAAQ,OAAO,CAAC,cAAc,CAAC;IAC3D,MAAM,EAAE,gBAAgB,EAAE,CAAC;CAC5B;AAED,MAAM,WAAW,WAAY,SAAQ,OAAO,CAAC,aAAa,CAAC;IACzD,WAAW,EAAE,WAAW,CAAC;IACzB,WAAW,EAAE,WAAW,GAAG,IAAI,CAAC;IAChC,YAAY,EAAE,YAAY,CAAC;CAC5B"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CypherQuery, GraphPattern, Identifier, MatchClause, NodePattern, Properties, Property, RelationshipPattern, ReturnClause, WhereClause } from './ast';
|
|
2
|
+
import { Parjser } from './parjs';
|
|
3
|
+
export declare const identifier: Parjser<Identifier>;
|
|
4
|
+
export declare const label: Parjser<Identifier>;
|
|
5
|
+
export declare const property: Parjser<Property>;
|
|
6
|
+
export declare const properties: Parjser<Properties>;
|
|
7
|
+
export declare const nodePattern: Parjser<NodePattern>;
|
|
8
|
+
export declare const relationshipPattern: Parjser<RelationshipPattern>;
|
|
9
|
+
export declare const graphPattern: Parjser<GraphPattern>;
|
|
10
|
+
export declare const matchClause: Parjser<MatchClause>;
|
|
11
|
+
export declare const whereClause: Parjser<WhereClause>;
|
|
12
|
+
export declare const returnClause: Parjser<ReturnClause>;
|
|
13
|
+
export declare const cypherQuery: Parjser<CypherQuery>;
|
|
14
|
+
//# sourceMappingURL=combinators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"combinators.d.ts","sourceRoot":"","sources":["../../../../src/cypher/combinators.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,WAAW,EAEX,YAAY,EAEZ,UAAU,EACV,WAAW,EAEX,WAAW,EACX,UAAU,EACV,QAAQ,EACR,mBAAmB,EACnB,YAAY,EAEZ,WAAW,EACZ,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,OAAO,EAA2B,MAAM,SAAS,CAAC;AAgB3D,eAAO,MAAM,UAAU,qBAEtB,CAAC;AAUF,eAAO,MAAM,KAAK,qBAAwD,CAAC;AAC3E,eAAO,MAAM,QAAQ,mBAGpB,CAAC;AACF,eAAO,MAAM,UAAU,qBAItB,CAAC;AACF,eAAO,MAAM,WAAW,sBAQvB,CAAC;AAEF,eAAO,MAAM,mBAAmB,8BAa/B,CAAC;AAOF,eAAO,MAAM,YAAY,uBAIxB,CAAC;AAEF,eAAO,MAAM,WAAW,sBAIvB,CAAC;AAYF,eAAO,MAAM,WAAW,sBAOvB,CAAC;AAEF,eAAO,MAAM,YAAY,uBAaxB,CAAC;AAEF,eAAO,MAAM,WAAW,sBAUvB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"combinators.test.d.ts","sourceRoot":"","sources":["../../../../src/cypher/combinators.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type EchoDatabase } from '@dxos/echo-db';
|
|
2
|
+
import type { DataSource, Node, Relationship } from './query-executor';
|
|
3
|
+
export declare class EchoDataSource implements DataSource {
|
|
4
|
+
private readonly _db;
|
|
5
|
+
constructor(_db: EchoDatabase);
|
|
6
|
+
getNodes({ label }: {
|
|
7
|
+
label?: string;
|
|
8
|
+
}): Promise<Node[]>;
|
|
9
|
+
getRelationships({ label }: {
|
|
10
|
+
label?: string;
|
|
11
|
+
}): Promise<Relationship[]>;
|
|
12
|
+
private _getAllSchema;
|
|
13
|
+
private _objectToNode;
|
|
14
|
+
private _projectRefRelationship;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=echo-data-source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"echo-data-source.d.ts","sourceRoot":"","sources":["../../../../src/cypher/echo-data-source.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,YAAY,EAAmC,MAAM,eAAe,CAAC;AAKnF,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGvE,qBAAa,cAAe,YAAW,UAAU;IACnC,OAAO,CAAC,QAAQ,CAAC,GAAG;gBAAH,GAAG,EAAE,YAAY;IAGxC,QAAQ,CAAC,EAAE,KAAK,EAAE,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAiBxD,gBAAgB,CAAC,EAAE,KAAK,EAAE,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;YA+BhE,aAAa;IAQ3B,OAAO,CAAC,aAAa;YAUP,uBAAuB;CAqBtC"}
|