@dxos/assistant 0.8.4-main.f9ba587 → 0.8.4-main.fd6878d
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-6WRGDEMH.mjs +89 -0
- package/dist/lib/browser/chunk-6WRGDEMH.mjs.map +7 -0
- package/dist/lib/browser/chunk-NZGGCEF3.mjs +341 -0
- package/dist/lib/browser/chunk-NZGGCEF3.mjs.map +7 -0
- package/dist/lib/browser/extraction/index.mjs +269 -0
- package/dist/lib/browser/extraction/index.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +240 -1905
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/named-entity-recognition-O46UTCLR.mjs +13 -0
- package/dist/lib/browser/named-entity-recognition-O46UTCLR.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-3UU5V4FS.mjs +91 -0
- package/dist/lib/node-esm/chunk-3UU5V4FS.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-XOOPGSGW.mjs +343 -0
- package/dist/lib/node-esm/chunk-XOOPGSGW.mjs.map +7 -0
- package/dist/lib/node-esm/extraction/index.mjs +270 -0
- package/dist/lib/node-esm/extraction/index.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +240 -1906
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/named-entity-recognition-W4VMRCH6.mjs +14 -0
- package/dist/lib/node-esm/named-entity-recognition-W4VMRCH6.mjs.map +7 -0
- package/dist/types/src/conversation/context.d.ts +90 -0
- package/dist/types/src/conversation/context.d.ts.map +1 -0
- package/dist/types/src/conversation/conversation.d.ts +31 -25
- package/dist/types/src/conversation/conversation.d.ts.map +1 -1
- package/dist/types/src/conversation/index.d.ts +1 -0
- package/dist/types/src/conversation/index.d.ts.map +1 -1
- package/dist/types/src/errors.d.ts +39 -0
- package/dist/types/src/errors.d.ts.map +1 -0
- package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts.map +1 -1
- package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts +143 -45
- package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts.map +1 -1
- package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.d.ts +1 -1
- package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.d.ts.map +1 -1
- package/dist/types/src/extraction/extraction.d.ts +106 -44
- package/dist/types/src/extraction/extraction.d.ts.map +1 -1
- package/dist/types/src/functions/index.d.ts +2 -0
- package/dist/types/src/functions/index.d.ts.map +1 -0
- package/dist/types/src/functions/services.d.ts +7 -0
- package/dist/types/src/functions/services.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +3 -5
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/session/artifact-diff.d.ts +27 -0
- package/dist/types/src/session/artifact-diff.d.ts.map +1 -0
- package/dist/types/src/session/format.d.ts +168 -0
- package/dist/types/src/session/format.d.ts.map +1 -0
- package/dist/types/src/session/format.test.d.ts +2 -0
- package/dist/types/src/session/format.test.d.ts.map +1 -0
- package/dist/types/src/session/index.d.ts +1 -0
- package/dist/types/src/session/index.d.ts.map +1 -1
- package/dist/types/src/session/session.d.ts +123 -239
- package/dist/types/src/session/session.d.ts.map +1 -1
- package/dist/types/src/session/version-pin.d.ts +4 -4
- package/dist/types/src/session/version-pin.d.ts.map +1 -1
- package/dist/types/src/templates/index.d.ts +2 -0
- package/dist/types/src/templates/index.d.ts.map +1 -0
- package/dist/types/src/templates/system.d.ts +22 -0
- package/dist/types/src/templates/system.d.ts.map +1 -0
- package/dist/types/src/types.d.ts +13 -0
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +46 -22
- package/src/{context/binder.ts → conversation/context.ts} +51 -19
- package/src/conversation/conversation.ts +90 -68
- package/src/conversation/index.ts +1 -0
- package/src/errors.ts +10 -0
- package/src/extraction/extraction-llm-function/extraction-llm-function.test.ts +7 -18
- package/src/extraction/extraction-llm-function/extraction-llm-function.ts +22 -17
- package/src/extraction/extraction-ner-function/extraction-ner-function.test.ts +4 -3
- package/src/extraction/extraction-ner-function/extraction-ner-function.ts +7 -4
- package/src/extraction/extraction-ner-function/named-entity-recognition.test.ts +2 -2
- package/src/extraction/extraction-ner-function/named-entity-recognition.ts +1 -1
- package/src/extraction/quotes.test.ts +1 -1
- package/src/extraction/quotes.ts +1 -1
- package/src/functions/index.ts +5 -0
- package/src/functions/services.ts +114 -0
- package/src/index.ts +3 -5
- package/src/session/__snapshots__/session.test.ts.snap +32 -0
- package/src/session/artifact-diff.ts +37 -0
- package/src/session/format.test.ts +60 -0
- package/src/session/format.ts +139 -0
- package/src/session/index.ts +1 -0
- package/src/session/session.test.ts +87 -57
- package/src/session/session.ts +220 -523
- package/src/session/version-pin.test.ts +2 -21
- package/src/session/version-pin.ts +9 -9
- package/src/summarization/summarization.test.ts +82 -106
- package/src/templates/format.tpl +55 -0
- package/src/templates/index.ts +5 -0
- package/src/templates/system.tpl +47 -0
- package/src/templates/system.ts +32 -0
- package/src/types.ts +45 -1
- package/src/typings.d.ts +5 -0
- package/dist/types/bin/chat.d.ts +0 -2
- package/dist/types/bin/chat.d.ts.map +0 -1
- package/dist/types/src/blueprint/blueprint.d.ts +0 -41
- package/dist/types/src/blueprint/blueprint.d.ts.map +0 -1
- package/dist/types/src/blueprint/index.d.ts +0 -3
- package/dist/types/src/blueprint/index.d.ts.map +0 -1
- package/dist/types/src/blueprint/registry.d.ts +0 -7
- package/dist/types/src/blueprint/registry.d.ts.map +0 -1
- package/dist/types/src/context/binder.d.ts +0 -34
- package/dist/types/src/context/binder.d.ts.map +0 -1
- package/dist/types/src/context/binding.d.ts +0 -38
- package/dist/types/src/context/binding.d.ts.map +0 -1
- package/dist/types/src/context/index.d.ts +0 -3
- package/dist/types/src/context/index.d.ts.map +0 -1
- package/dist/types/src/research/exa.d.ts +0 -7
- package/dist/types/src/research/exa.d.ts.map +0 -1
- package/dist/types/src/research/graph.d.ts +0 -41
- package/dist/types/src/research/graph.d.ts.map +0 -1
- package/dist/types/src/research/graph.test.d.ts +0 -2
- package/dist/types/src/research/graph.test.d.ts.map +0 -1
- package/dist/types/src/research/index.d.ts +0 -4
- package/dist/types/src/research/index.d.ts.map +0 -1
- package/dist/types/src/research/research.d.ts +0 -10
- package/dist/types/src/research/research.d.ts.map +0 -1
- package/dist/types/src/research/research.test.d.ts +0 -2
- package/dist/types/src/research/research.test.d.ts.map +0 -1
- package/dist/types/src/testing/exa-search-1748337321991.d.ts +0 -38
- package/dist/types/src/testing/exa-search-1748337321991.d.ts.map +0 -1
- package/dist/types/src/testing/exa-search-1748337331526.d.ts +0 -37
- package/dist/types/src/testing/exa-search-1748337331526.d.ts.map +0 -1
- package/dist/types/src/testing/exa-search-1748337344119.d.ts +0 -58
- package/dist/types/src/testing/exa-search-1748337344119.d.ts.map +0 -1
- package/dist/types/src/testing/index.d.ts +0 -3
- package/dist/types/src/testing/index.d.ts.map +0 -1
- package/src/blueprint/blueprint.ts +0 -75
- package/src/blueprint/index.ts +0 -6
- package/src/blueprint/registry.ts +0 -15
- package/src/context/binding.ts +0 -31
- package/src/context/index.ts +0 -6
- package/src/research/exa.ts +0 -100
- package/src/research/graph.test.ts +0 -15
- package/src/research/graph.ts +0 -337
- package/src/research/index.ts +0 -7
- package/src/research/instructions-research.tpl +0 -97
- package/src/research/research.test.ts +0 -190
- package/src/research/research.ts +0 -90
- package/src/testing/exa-search-1748337321991.ts +0 -131
- package/src/testing/exa-search-1748337331526.ts +0 -144
- package/src/testing/exa-search-1748337344119.ts +0 -133
- package/src/testing/index.ts +0 -11
- package/src/typedefs.d.ts +0 -8
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Context } from 'effect';
|
|
2
|
+
import { type ObjectVersion } from '@dxos/echo-db';
|
|
3
|
+
import { type ObjectId } from '@dxos/echo-schema';
|
|
4
|
+
declare const ArtifactDiffResolver_base: Context.TagClass<ArtifactDiffResolver, "@dxos/assistant/ArtifactDiffResolver", ArtifactDiffResolver.Service>;
|
|
5
|
+
/**
|
|
6
|
+
* Resolves artifact ids to their versions.
|
|
7
|
+
* Used to give the model a sense of the changes to the artifacts made by users during the conversation.
|
|
8
|
+
* The artifacts versions are pinned in the history, and whenever the artifact changes in-between assistant's steps,
|
|
9
|
+
* a diff is inserted into the conversation.
|
|
10
|
+
*
|
|
11
|
+
* Can be optionally provided to the session run call.
|
|
12
|
+
*/
|
|
13
|
+
export declare class ArtifactDiffResolver extends ArtifactDiffResolver_base {
|
|
14
|
+
}
|
|
15
|
+
export declare namespace ArtifactDiffResolver {
|
|
16
|
+
type Service = {
|
|
17
|
+
resolve: (artifacts: {
|
|
18
|
+
id: ObjectId;
|
|
19
|
+
lastVersion: ObjectVersion;
|
|
20
|
+
}[]) => Promise<Map<ObjectId, {
|
|
21
|
+
version: ObjectVersion;
|
|
22
|
+
diff?: string;
|
|
23
|
+
}>>;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=artifact-diff.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artifact-diff.d.ts","sourceRoot":"","sources":["../../../../src/session/artifact-diff.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEjC,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;;AAElD;;;;;;;GAOG;AAGH,qBAAa,oBAAqB,SAAQ,yBAGvC;CAAG;AAEN,yBAAiB,oBAAoB,CAAC;IACpC,KAAY,OAAO,GAAG;QACpB,OAAO,EAAE,CAAC,SAAS,EAAE;YAAE,EAAE,EAAE,QAAQ,CAAC;YAAC,WAAW,EAAE,aAAa,CAAA;SAAE,EAAE,KAAK,OAAO,CAC7E,GAAG,CACD,QAAQ,EACR;YACE,OAAO,EAAE,aAAa,CAAC;YACvB,IAAI,CAAC,EAAE,MAAM,CAAC;SACf,CACF,CACF,CAAC;KACH,CAAC;CACH"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
|
+
import { type SessionRunParams } from './session';
|
|
3
|
+
/**
|
|
4
|
+
* Formats the system prompt.
|
|
5
|
+
*/
|
|
6
|
+
export declare const formatSystemPrompt: ({ system, blueprints, objects, }: Pick<SessionRunParams<any>, "system" | "blueprints" | "objects">) => Effect.Effect<string, never, never>;
|
|
7
|
+
/**
|
|
8
|
+
* Formats the user prompt.
|
|
9
|
+
*/
|
|
10
|
+
export declare const formatUserPrompt: ({ prompt, history }: Pick<SessionRunParams<any>, "prompt" | "history">) => Effect.Effect<import("@dxos/live-object").Live<import("@dxos/echo/Type").OfKind<import("@dxos/echo-schema").EntityKind.Object> & {
|
|
11
|
+
id: string;
|
|
12
|
+
parentMessage?: string | undefined;
|
|
13
|
+
created: string;
|
|
14
|
+
sender: {
|
|
15
|
+
name?: string | undefined;
|
|
16
|
+
contact?: import("@dxos/echo-schema").Ref<import("@dxos/echo/Type").OfKind<import("@dxos/echo-schema").EntityKind.Object> & {
|
|
17
|
+
fields?: {
|
|
18
|
+
readonly value: string;
|
|
19
|
+
readonly category?: string | undefined;
|
|
20
|
+
readonly label: string;
|
|
21
|
+
}[] | undefined;
|
|
22
|
+
image?: string | undefined;
|
|
23
|
+
fullName?: string | undefined;
|
|
24
|
+
preferredName?: string | undefined;
|
|
25
|
+
nickname?: string | undefined;
|
|
26
|
+
organization?: import("@dxos/echo-schema").Ref<import("@dxos/echo/Type").OfKind<import("@dxos/echo-schema").EntityKind.Object> & {
|
|
27
|
+
id: string;
|
|
28
|
+
name?: string | undefined;
|
|
29
|
+
description?: string | undefined;
|
|
30
|
+
status?: "prospect" | "qualified" | "active" | "commit" | "reject" | undefined;
|
|
31
|
+
image?: string | undefined;
|
|
32
|
+
website?: string | undefined;
|
|
33
|
+
}> | undefined;
|
|
34
|
+
jobTitle?: string | undefined;
|
|
35
|
+
department?: string | undefined;
|
|
36
|
+
notes?: string | undefined;
|
|
37
|
+
emails?: {
|
|
38
|
+
readonly value: string;
|
|
39
|
+
readonly label?: string | undefined;
|
|
40
|
+
}[] | undefined;
|
|
41
|
+
identities?: {
|
|
42
|
+
readonly value: string;
|
|
43
|
+
readonly label?: string | undefined;
|
|
44
|
+
}[] | undefined;
|
|
45
|
+
phoneNumbers?: {
|
|
46
|
+
readonly value: string;
|
|
47
|
+
readonly label?: string | undefined;
|
|
48
|
+
}[] | undefined;
|
|
49
|
+
addresses?: {
|
|
50
|
+
readonly value: {
|
|
51
|
+
readonly street?: string | undefined;
|
|
52
|
+
readonly extended?: string | undefined;
|
|
53
|
+
readonly locality?: string | undefined;
|
|
54
|
+
readonly region?: string | undefined;
|
|
55
|
+
readonly postalCode?: string | undefined;
|
|
56
|
+
readonly postOfficeBoxNumber?: string | undefined;
|
|
57
|
+
readonly country?: string | undefined;
|
|
58
|
+
};
|
|
59
|
+
readonly label?: string | undefined;
|
|
60
|
+
}[] | undefined;
|
|
61
|
+
urls?: {
|
|
62
|
+
readonly value: string;
|
|
63
|
+
readonly label?: string | undefined;
|
|
64
|
+
}[] | undefined;
|
|
65
|
+
birthday?: string | undefined;
|
|
66
|
+
}> | undefined;
|
|
67
|
+
identityDid?: string | undefined;
|
|
68
|
+
identityKey?: string | undefined;
|
|
69
|
+
email?: string | undefined;
|
|
70
|
+
role?: "user" | "assistant" | undefined;
|
|
71
|
+
};
|
|
72
|
+
blocks: ({
|
|
73
|
+
version: unknown;
|
|
74
|
+
_tag: "anchor";
|
|
75
|
+
pending?: boolean | undefined;
|
|
76
|
+
objectId: string;
|
|
77
|
+
} | {
|
|
78
|
+
name?: string | undefined;
|
|
79
|
+
_tag: "file";
|
|
80
|
+
pending?: boolean | undefined;
|
|
81
|
+
url: string;
|
|
82
|
+
mediaType?: string | undefined;
|
|
83
|
+
} | {
|
|
84
|
+
source?: {
|
|
85
|
+
mediaType: string;
|
|
86
|
+
type: "base64";
|
|
87
|
+
data: string;
|
|
88
|
+
} | {
|
|
89
|
+
url: string;
|
|
90
|
+
type: "http";
|
|
91
|
+
} | undefined;
|
|
92
|
+
id?: string | undefined;
|
|
93
|
+
_tag: "image";
|
|
94
|
+
pending?: boolean | undefined;
|
|
95
|
+
} | {
|
|
96
|
+
_tag: "json";
|
|
97
|
+
pending?: boolean | undefined;
|
|
98
|
+
data: string;
|
|
99
|
+
disposition?: string | undefined;
|
|
100
|
+
} | {
|
|
101
|
+
text: string;
|
|
102
|
+
_tag: "proposal";
|
|
103
|
+
pending?: boolean | undefined;
|
|
104
|
+
} | {
|
|
105
|
+
_tag: "reasoning";
|
|
106
|
+
pending?: boolean | undefined;
|
|
107
|
+
reasoningText?: string | undefined;
|
|
108
|
+
redactedText?: string | undefined;
|
|
109
|
+
signature?: string | undefined;
|
|
110
|
+
} | {
|
|
111
|
+
reference: import("@dxos/echo-schema").Ref<import("@dxos/echo/Type").Expando>;
|
|
112
|
+
_tag: "reference";
|
|
113
|
+
pending?: boolean | undefined;
|
|
114
|
+
} | {
|
|
115
|
+
_tag: "select";
|
|
116
|
+
pending?: boolean | undefined;
|
|
117
|
+
options: readonly string[];
|
|
118
|
+
} | {
|
|
119
|
+
_tag: "status";
|
|
120
|
+
pending?: boolean | undefined;
|
|
121
|
+
statusText: string;
|
|
122
|
+
} | {
|
|
123
|
+
text: string;
|
|
124
|
+
_tag: "suggest";
|
|
125
|
+
pending?: boolean | undefined;
|
|
126
|
+
} | {
|
|
127
|
+
text: string;
|
|
128
|
+
_tag: "text";
|
|
129
|
+
pending?: boolean | undefined;
|
|
130
|
+
disposition?: string | undefined;
|
|
131
|
+
mimeType?: string | undefined;
|
|
132
|
+
} | {
|
|
133
|
+
_tag: "toolkit";
|
|
134
|
+
pending?: boolean | undefined;
|
|
135
|
+
} | {
|
|
136
|
+
name: string;
|
|
137
|
+
_tag: "toolCall";
|
|
138
|
+
pending?: boolean | undefined;
|
|
139
|
+
toolCallId: string;
|
|
140
|
+
input: unknown;
|
|
141
|
+
} | {
|
|
142
|
+
name: string;
|
|
143
|
+
_tag: "toolResult";
|
|
144
|
+
pending?: boolean | undefined;
|
|
145
|
+
toolCallId: string;
|
|
146
|
+
result: unknown;
|
|
147
|
+
error?: string | undefined;
|
|
148
|
+
} | {
|
|
149
|
+
text: string;
|
|
150
|
+
_tag: "transcript";
|
|
151
|
+
pending?: boolean | undefined;
|
|
152
|
+
started: string;
|
|
153
|
+
})[];
|
|
154
|
+
properties?: {
|
|
155
|
+
[x: string]: any;
|
|
156
|
+
} | undefined;
|
|
157
|
+
}>, {
|
|
158
|
+
#code: "AI_ASSISTANT_ERROR";
|
|
159
|
+
#context: Record<string, unknown>;
|
|
160
|
+
readonly name: "AI_ASSISTANT_ERROR";
|
|
161
|
+
readonly code: "AI_ASSISTANT_ERROR";
|
|
162
|
+
readonly _tag: "AI_ASSISTANT_ERROR";
|
|
163
|
+
readonly context: Record<string, unknown>;
|
|
164
|
+
message: string;
|
|
165
|
+
stack?: string;
|
|
166
|
+
cause?: unknown;
|
|
167
|
+
}, never>;
|
|
168
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../../../src/session/format.ts"],"names":[],"mappings":"AAIA,OAAO,EAAS,MAAM,EAAgB,MAAM,QAAQ,CAAC;AAcrD,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAElD;;GAEG;AAEH,eAAO,MAAM,kBAAkB,GAAI,kCAIhC,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAAE,QAAQ,GAAG,YAAY,GAAG,SAAS,CAAC,wCAsC/D,CAAC;AAEL;;GAEG;AAGH,eAAO,MAAM,gBAAgB,GAAI,qBAA0B,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAoCxG,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.test.d.ts","sourceRoot":"","sources":["../../../../src/session/format.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/session/index.ts"],"names":[],"mappings":"AAIA,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/session/index.ts"],"names":[],"mappings":"AAIA,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC"}
|
|
@@ -1,283 +1,167 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { type
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { type
|
|
1
|
+
import { type AiError, AiLanguageModel, type AiResponse, type AiTool, AiToolkit } from '@effect/ai';
|
|
2
|
+
import { Effect, Option, Queue, type Schema } from 'effect';
|
|
3
|
+
import { type AiInputPreprocessingError, type AiToolNotFoundError, type ConsolePrinter, ToolExecutionService, ToolResolverService } from '@dxos/ai';
|
|
4
|
+
import { type Blueprint } from '@dxos/blueprints';
|
|
5
|
+
import { Obj } from '@dxos/echo';
|
|
6
|
+
import { type ContentBlock, DataType } from '@dxos/schema';
|
|
7
|
+
import { type AiAssistantError } from '../errors';
|
|
8
|
+
export type AiSessionOptions = {};
|
|
7
9
|
/**
|
|
8
|
-
*
|
|
9
|
-
* Current context means the state of the app, time of day, and other contextual information.
|
|
10
|
-
* It makes requests to the model, its a state machine.
|
|
11
|
-
* It keeps track of the current goal.
|
|
12
|
-
* It manages the context window.
|
|
13
|
-
* Tracks the success criteria of reaching the goal, exposing metrics (stretch)
|
|
14
|
-
* Could be run locally in the app or remotely.
|
|
15
|
-
* Could be personal or shared.
|
|
10
|
+
* Live observer of the generation process.
|
|
16
11
|
*/
|
|
17
|
-
|
|
18
|
-
* Resolves artifact ids to their versions.
|
|
19
|
-
* Used to give the model a sense of the changes to the artifacts made by users during the conversation.
|
|
20
|
-
* The artifacts versions are pinned in the history, and whenever the artifact changes in-between assistant's steps,
|
|
21
|
-
* a diff is inserted into the conversation.
|
|
22
|
-
*/
|
|
23
|
-
export type ArtifactDiffResolver = (artifacts: {
|
|
24
|
-
id: ObjectId;
|
|
25
|
-
lastVersion: ObjectVersion;
|
|
26
|
-
}[]) => Promise<Map<ObjectId, {
|
|
27
|
-
version: ObjectVersion;
|
|
28
|
-
diff?: string;
|
|
29
|
-
}>>;
|
|
30
|
-
export type SessionRunOptions = {
|
|
31
|
-
artifacts: ArtifactDefinition[];
|
|
32
|
-
/**
|
|
33
|
-
* Non-artifact specific tools.
|
|
34
|
-
*/
|
|
35
|
-
tools: ToolId[];
|
|
36
|
-
history: Message[];
|
|
37
|
-
prompt: string;
|
|
38
|
-
generationOptions?: Pick<GenerateRequest, 'model'>;
|
|
39
|
-
extensions?: ToolContextExtensions;
|
|
40
|
-
systemPrompt?: string;
|
|
12
|
+
export interface GenerationObserver {
|
|
41
13
|
/**
|
|
42
|
-
*
|
|
14
|
+
* Unparsed content block parts from the model.
|
|
43
15
|
*/
|
|
44
|
-
|
|
45
|
-
client: AiServiceClient;
|
|
46
|
-
toolResolver: ToolResolver;
|
|
16
|
+
onPart: (part: AiResponse.Part) => Effect.Effect<void>;
|
|
47
17
|
/**
|
|
48
|
-
*
|
|
18
|
+
* Parsed content blocks from the model.
|
|
19
|
+
* NOTE: Use block.pending to determine if the block was completed.
|
|
20
|
+
* For each block this will be called 0..n times with a pending block and then once with the final state of the block.
|
|
21
|
+
*
|
|
22
|
+
* Example:
|
|
23
|
+
* 1. { pending: true, text: "Hello"}
|
|
24
|
+
* 2. { pending: true, text: "Hello, I am a"}
|
|
25
|
+
* 3. { pending: false, text: "Hello, I am a helpful assistant!"}
|
|
49
26
|
*/
|
|
50
|
-
|
|
27
|
+
onBlock: (block: ContentBlock.Any) => Effect.Effect<void>;
|
|
51
28
|
/**
|
|
52
|
-
*
|
|
29
|
+
* Complete messages fired during the session, both from the model and from the user.
|
|
30
|
+
* This message will contain all message blocks emitted through the `onBlock` callback.
|
|
53
31
|
*/
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
32
|
+
onMessage: (message: DataType.Message) => Effect.Effect<void>;
|
|
33
|
+
}
|
|
34
|
+
export declare const GenerationObserver: Readonly<{
|
|
35
|
+
make: ({ onPart, onBlock, onMessage, }?: Partial<GenerationObserver>) => GenerationObserver;
|
|
36
|
+
noop: () => GenerationObserver;
|
|
58
37
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* - `planning`: The model will create a plan with required artifacts for each step.
|
|
62
|
-
* - `importing`: The model can query registry and only pull in the artifacts that are required to complete the task.
|
|
63
|
-
* - `configured`: The available artifacts are pre-selected and the model cannot select additional artifacts.
|
|
38
|
+
* Debug printer to be used in unit-tests and browser devtools.
|
|
64
39
|
*/
|
|
65
|
-
|
|
40
|
+
fromPrinter: (printer: ConsolePrinter) => GenerationObserver;
|
|
41
|
+
}>;
|
|
42
|
+
export type SessionRunParams<Tools extends AiTool.Any> = {
|
|
43
|
+
prompt: string;
|
|
44
|
+
system?: string;
|
|
45
|
+
history?: DataType.Message[];
|
|
46
|
+
objects?: Obj.Any[];
|
|
47
|
+
blueprints?: Blueprint.Blueprint[];
|
|
48
|
+
toolkit?: AiToolkit.AiToolkit<Tools>;
|
|
49
|
+
observer?: GenerationObserver;
|
|
66
50
|
};
|
|
67
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Contains message history, tools, current context.
|
|
53
|
+
* Current context means the state of the app, time of day, and other contextual information.
|
|
54
|
+
* It makes requests to the model, its a state machine.
|
|
55
|
+
* It keeps track of the current goal.
|
|
56
|
+
* It manages the context window.
|
|
57
|
+
* Tracks the success criteria of reaching the goal, exposing metrics (stretch).
|
|
58
|
+
* Could be run locally in the app or remotely.
|
|
59
|
+
* Could be personal or shared.
|
|
60
|
+
*/
|
|
61
|
+
export declare class AiSession {
|
|
68
62
|
private readonly _options;
|
|
69
|
-
/**
|
|
70
|
-
|
|
71
|
-
/** Pending messages (incl. the current user request). */
|
|
72
|
-
private _pending;
|
|
73
|
-
/** Current streaming response. */
|
|
74
|
-
private _stream;
|
|
75
|
-
/** Prior history from queue. */
|
|
76
|
-
private _history;
|
|
77
|
-
/**
|
|
78
|
-
* New message.
|
|
79
|
-
*/
|
|
80
|
-
readonly message: Event<import("@dxos/echo/Type").OfKind<import("@dxos/echo-schema").EntityKind.Object> & {
|
|
81
|
-
id: string;
|
|
82
|
-
content: ({
|
|
83
|
-
pending?: boolean | undefined;
|
|
84
|
-
type: "text";
|
|
85
|
-
text: string;
|
|
86
|
-
disposition?: string | undefined;
|
|
87
|
-
} | {
|
|
88
|
-
pending?: boolean | undefined;
|
|
89
|
-
type: "json";
|
|
90
|
-
disposition?: string | undefined;
|
|
91
|
-
json: string;
|
|
92
|
-
} | {
|
|
93
|
-
pending?: boolean | undefined;
|
|
94
|
-
id?: string | undefined;
|
|
95
|
-
type: "image";
|
|
96
|
-
source?: {
|
|
97
|
-
type: "base64";
|
|
98
|
-
mediaType: string;
|
|
99
|
-
data: string;
|
|
100
|
-
} | undefined;
|
|
101
|
-
} | {
|
|
102
|
-
pending?: boolean | undefined;
|
|
103
|
-
id: string;
|
|
104
|
-
type: "tool_use";
|
|
105
|
-
name: string;
|
|
106
|
-
input: unknown;
|
|
107
|
-
currentStatus?: {
|
|
108
|
-
readonly id: string;
|
|
109
|
-
message: string;
|
|
110
|
-
} | undefined;
|
|
111
|
-
} | {
|
|
112
|
-
pending?: boolean | undefined;
|
|
113
|
-
type: "tool_result";
|
|
114
|
-
toolUseId: string;
|
|
115
|
-
content: string;
|
|
116
|
-
isError?: boolean | undefined;
|
|
117
|
-
})[];
|
|
118
|
-
role: "user" | "assistant";
|
|
119
|
-
}>;
|
|
63
|
+
/** Complete messages fired during the session, both from the model and from the user. */
|
|
64
|
+
readonly messageQueue: Queue.Queue<import("@dxos/schema").Message>;
|
|
120
65
|
/**
|
|
121
|
-
*
|
|
66
|
+
* Blocks streaming from the model during the session.
|
|
67
|
+
* @deprecated Use `observer.onBlock` instead.
|
|
122
68
|
*/
|
|
123
|
-
readonly
|
|
69
|
+
readonly blockQueue: Queue.Queue<Option.Option<{
|
|
70
|
+
version: unknown;
|
|
71
|
+
_tag: "anchor";
|
|
124
72
|
pending?: boolean | undefined;
|
|
125
|
-
|
|
126
|
-
text: string;
|
|
127
|
-
disposition?: string | undefined;
|
|
73
|
+
objectId: string;
|
|
128
74
|
} | {
|
|
75
|
+
name?: string | undefined;
|
|
76
|
+
_tag: "file";
|
|
129
77
|
pending?: boolean | undefined;
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
json: string;
|
|
78
|
+
url: string;
|
|
79
|
+
mediaType?: string | undefined;
|
|
133
80
|
} | {
|
|
134
|
-
pending?: boolean | undefined;
|
|
135
|
-
id?: string | undefined;
|
|
136
|
-
type: "image";
|
|
137
81
|
source?: {
|
|
138
|
-
type: "base64";
|
|
139
82
|
mediaType: string;
|
|
83
|
+
type: "base64";
|
|
140
84
|
data: string;
|
|
85
|
+
} | {
|
|
86
|
+
url: string;
|
|
87
|
+
type: "http";
|
|
141
88
|
} | undefined;
|
|
89
|
+
id?: string | undefined;
|
|
90
|
+
_tag: "image";
|
|
91
|
+
pending?: boolean | undefined;
|
|
142
92
|
} | {
|
|
93
|
+
_tag: "json";
|
|
143
94
|
pending?: boolean | undefined;
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
name: string;
|
|
147
|
-
input: unknown;
|
|
148
|
-
currentStatus?: {
|
|
149
|
-
readonly id: string;
|
|
150
|
-
message: string;
|
|
151
|
-
} | undefined;
|
|
95
|
+
data: string;
|
|
96
|
+
disposition?: string | undefined;
|
|
152
97
|
} | {
|
|
98
|
+
text: string;
|
|
99
|
+
_tag: "proposal";
|
|
153
100
|
pending?: boolean | undefined;
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
content: string;
|
|
157
|
-
isError?: boolean | undefined;
|
|
158
|
-
}>;
|
|
159
|
-
/**
|
|
160
|
-
* Update partial block (while streaming).
|
|
161
|
-
*/
|
|
162
|
-
readonly update: Event<{
|
|
101
|
+
} | {
|
|
102
|
+
_tag: "reasoning";
|
|
163
103
|
pending?: boolean | undefined;
|
|
164
|
-
|
|
104
|
+
reasoningText?: string | undefined;
|
|
105
|
+
redactedText?: string | undefined;
|
|
106
|
+
signature?: string | undefined;
|
|
107
|
+
} | {
|
|
108
|
+
reference: import("@dxos/echo-schema").Ref<import("@dxos/echo/Type").Expando>;
|
|
109
|
+
_tag: "reference";
|
|
110
|
+
pending?: boolean | undefined;
|
|
111
|
+
} | {
|
|
112
|
+
_tag: "select";
|
|
113
|
+
pending?: boolean | undefined;
|
|
114
|
+
options: readonly string[];
|
|
115
|
+
} | {
|
|
116
|
+
_tag: "status";
|
|
117
|
+
pending?: boolean | undefined;
|
|
118
|
+
statusText: string;
|
|
119
|
+
} | {
|
|
165
120
|
text: string;
|
|
166
|
-
|
|
121
|
+
_tag: "suggest";
|
|
122
|
+
pending?: boolean | undefined;
|
|
167
123
|
} | {
|
|
124
|
+
text: string;
|
|
125
|
+
_tag: "text";
|
|
168
126
|
pending?: boolean | undefined;
|
|
169
|
-
type: "json";
|
|
170
127
|
disposition?: string | undefined;
|
|
171
|
-
|
|
128
|
+
mimeType?: string | undefined;
|
|
172
129
|
} | {
|
|
130
|
+
_tag: "toolkit";
|
|
173
131
|
pending?: boolean | undefined;
|
|
174
|
-
id?: string | undefined;
|
|
175
|
-
type: "image";
|
|
176
|
-
source?: {
|
|
177
|
-
type: "base64";
|
|
178
|
-
mediaType: string;
|
|
179
|
-
data: string;
|
|
180
|
-
} | undefined;
|
|
181
132
|
} | {
|
|
182
|
-
pending?: boolean | undefined;
|
|
183
|
-
id: string;
|
|
184
|
-
type: "tool_use";
|
|
185
133
|
name: string;
|
|
134
|
+
_tag: "toolCall";
|
|
135
|
+
pending?: boolean | undefined;
|
|
136
|
+
toolCallId: string;
|
|
186
137
|
input: unknown;
|
|
187
|
-
currentStatus?: {
|
|
188
|
-
readonly id: string;
|
|
189
|
-
message: string;
|
|
190
|
-
} | undefined;
|
|
191
138
|
} | {
|
|
139
|
+
name: string;
|
|
140
|
+
_tag: "toolResult";
|
|
192
141
|
pending?: boolean | undefined;
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
readonly
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
disposition?: string | undefined;
|
|
212
|
-
text: string;
|
|
213
|
-
} | {
|
|
214
|
-
pending?: boolean | undefined;
|
|
215
|
-
type: "json";
|
|
216
|
-
disposition?: string | undefined;
|
|
217
|
-
json: string;
|
|
218
|
-
} | {
|
|
219
|
-
pending?: boolean | undefined;
|
|
220
|
-
id?: string | undefined;
|
|
221
|
-
type: "image";
|
|
222
|
-
source?: {
|
|
223
|
-
type: "base64";
|
|
224
|
-
mediaType: string;
|
|
225
|
-
data: string;
|
|
226
|
-
} | undefined;
|
|
227
|
-
} | {
|
|
228
|
-
pending?: boolean | undefined;
|
|
229
|
-
id: string;
|
|
230
|
-
name: string;
|
|
231
|
-
type: "tool_use";
|
|
232
|
-
input: unknown;
|
|
233
|
-
currentStatus?: {
|
|
234
|
-
readonly id: string;
|
|
235
|
-
message: string;
|
|
236
|
-
} | undefined;
|
|
237
|
-
} | {
|
|
238
|
-
pending?: boolean | undefined;
|
|
239
|
-
type: "tool_result";
|
|
240
|
-
content: string;
|
|
241
|
-
toolUseId: string;
|
|
242
|
-
isError?: boolean | undefined;
|
|
243
|
-
})[];
|
|
244
|
-
}>;
|
|
245
|
-
/**
|
|
246
|
-
* Agent self-reporting its status.
|
|
247
|
-
* Triggered by the model.
|
|
248
|
-
*/
|
|
249
|
-
readonly statusReport: Event<AgentStatus>;
|
|
250
|
-
/**
|
|
251
|
-
* Emits when the session is done.
|
|
252
|
-
*/
|
|
253
|
-
readonly done: Event<void>;
|
|
254
|
-
/**
|
|
255
|
-
* Emits when the tool reports its status.
|
|
256
|
-
* Triggered by the tool execution function.
|
|
257
|
-
*/
|
|
258
|
-
readonly toolStatusReport: Event<{
|
|
259
|
-
message: Message;
|
|
260
|
-
status: AgentStatus;
|
|
261
|
-
}>;
|
|
262
|
-
constructor(_options: AiSessionOptions);
|
|
142
|
+
toolCallId: string;
|
|
143
|
+
result: unknown;
|
|
144
|
+
error?: string | undefined;
|
|
145
|
+
} | {
|
|
146
|
+
text: string;
|
|
147
|
+
_tag: "transcript";
|
|
148
|
+
pending?: boolean | undefined;
|
|
149
|
+
started: string;
|
|
150
|
+
}>>;
|
|
151
|
+
/** Unparsed events from the underlying generation stream. */
|
|
152
|
+
readonly eventQueue: Queue.Queue<AiResponse.TextPart | AiResponse.ReasoningPart | AiResponse.RedactedReasoningPart | AiResponse.ToolCallPart | AiResponse.MetadataPart | AiResponse.FinishPart>;
|
|
153
|
+
/** Prevents concurrent execution of session. */
|
|
154
|
+
private readonly _semaphore;
|
|
155
|
+
/** Pending messages (incl. the current user request). */
|
|
156
|
+
private _pending;
|
|
157
|
+
/** Prior history from queue. */
|
|
158
|
+
private _history;
|
|
159
|
+
constructor(_options?: AiSessionOptions);
|
|
263
160
|
/**
|
|
264
161
|
* Runs the AI model loop interacting with tools and artifacts.
|
|
265
|
-
* @param options - The session options.
|
|
266
162
|
* @returns The messages generated by the session, including the user's prompt.
|
|
267
163
|
*/
|
|
268
|
-
run(
|
|
269
|
-
runStructured<S extends Schema.Schema.AnyNoContext>(
|
|
270
|
-
private _formatUserPrompt;
|
|
271
|
-
private _createQueryArtifactsTool;
|
|
272
|
-
private _createRequireTool;
|
|
273
|
-
private _createPlanningTool;
|
|
274
|
-
private _onToolStatusReport;
|
|
275
|
-
abort(): void;
|
|
276
|
-
}
|
|
277
|
-
declare const AIServiecOverloadedError_base: Schema.TaggedErrorClass<AIServiecOverloadedError, "AIServiecOverloadedError", {
|
|
278
|
-
readonly _tag: Schema.tag<"AIServiecOverloadedError">;
|
|
279
|
-
}>;
|
|
280
|
-
export declare class AIServiecOverloadedError extends AIServiecOverloadedError_base {
|
|
164
|
+
run: <Tools extends AiTool.Any>(params: SessionRunParams<Tools>) => Effect.Effect<DataType.Message[], AiAssistantError | AiInputPreprocessingError | AiToolNotFoundError | AiError.AiError, AiLanguageModel.AiLanguageModel | ToolResolverService | ToolExecutionService | AiTool.ToHandler<Tools>>;
|
|
165
|
+
runStructured<S extends Schema.Schema.AnyNoContext>(_schema: S, _options: SessionRunParams<AiTool.Any>): Promise<Schema.Schema.Type<S>>;
|
|
281
166
|
}
|
|
282
|
-
export {};
|
|
283
167
|
//# sourceMappingURL=session.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../../src/session/session.ts"],"names":[],"mappings":"AAIA,OAAO,
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../../src/session/session.ts"],"names":[],"mappings":"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"}
|