@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.
Files changed (145) hide show
  1. package/dist/lib/browser/chunk-6WRGDEMH.mjs +89 -0
  2. package/dist/lib/browser/chunk-6WRGDEMH.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-NZGGCEF3.mjs +341 -0
  4. package/dist/lib/browser/chunk-NZGGCEF3.mjs.map +7 -0
  5. package/dist/lib/browser/extraction/index.mjs +269 -0
  6. package/dist/lib/browser/extraction/index.mjs.map +7 -0
  7. package/dist/lib/browser/index.mjs +240 -1905
  8. package/dist/lib/browser/index.mjs.map +4 -4
  9. package/dist/lib/browser/meta.json +1 -1
  10. package/dist/lib/browser/named-entity-recognition-O46UTCLR.mjs +13 -0
  11. package/dist/lib/browser/named-entity-recognition-O46UTCLR.mjs.map +7 -0
  12. package/dist/lib/node-esm/chunk-3UU5V4FS.mjs +91 -0
  13. package/dist/lib/node-esm/chunk-3UU5V4FS.mjs.map +7 -0
  14. package/dist/lib/node-esm/chunk-XOOPGSGW.mjs +343 -0
  15. package/dist/lib/node-esm/chunk-XOOPGSGW.mjs.map +7 -0
  16. package/dist/lib/node-esm/extraction/index.mjs +270 -0
  17. package/dist/lib/node-esm/extraction/index.mjs.map +7 -0
  18. package/dist/lib/node-esm/index.mjs +240 -1906
  19. package/dist/lib/node-esm/index.mjs.map +4 -4
  20. package/dist/lib/node-esm/meta.json +1 -1
  21. package/dist/lib/node-esm/named-entity-recognition-W4VMRCH6.mjs +14 -0
  22. package/dist/lib/node-esm/named-entity-recognition-W4VMRCH6.mjs.map +7 -0
  23. package/dist/types/src/conversation/context.d.ts +90 -0
  24. package/dist/types/src/conversation/context.d.ts.map +1 -0
  25. package/dist/types/src/conversation/conversation.d.ts +31 -25
  26. package/dist/types/src/conversation/conversation.d.ts.map +1 -1
  27. package/dist/types/src/conversation/index.d.ts +1 -0
  28. package/dist/types/src/conversation/index.d.ts.map +1 -1
  29. package/dist/types/src/errors.d.ts +39 -0
  30. package/dist/types/src/errors.d.ts.map +1 -0
  31. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts.map +1 -1
  32. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts +143 -45
  33. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts.map +1 -1
  34. package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.d.ts +1 -1
  35. package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.d.ts.map +1 -1
  36. package/dist/types/src/extraction/extraction.d.ts +106 -44
  37. package/dist/types/src/extraction/extraction.d.ts.map +1 -1
  38. package/dist/types/src/functions/index.d.ts +2 -0
  39. package/dist/types/src/functions/index.d.ts.map +1 -0
  40. package/dist/types/src/functions/services.d.ts +7 -0
  41. package/dist/types/src/functions/services.d.ts.map +1 -0
  42. package/dist/types/src/index.d.ts +3 -5
  43. package/dist/types/src/index.d.ts.map +1 -1
  44. package/dist/types/src/session/artifact-diff.d.ts +27 -0
  45. package/dist/types/src/session/artifact-diff.d.ts.map +1 -0
  46. package/dist/types/src/session/format.d.ts +168 -0
  47. package/dist/types/src/session/format.d.ts.map +1 -0
  48. package/dist/types/src/session/format.test.d.ts +2 -0
  49. package/dist/types/src/session/format.test.d.ts.map +1 -0
  50. package/dist/types/src/session/index.d.ts +1 -0
  51. package/dist/types/src/session/index.d.ts.map +1 -1
  52. package/dist/types/src/session/session.d.ts +123 -239
  53. package/dist/types/src/session/session.d.ts.map +1 -1
  54. package/dist/types/src/session/version-pin.d.ts +4 -4
  55. package/dist/types/src/session/version-pin.d.ts.map +1 -1
  56. package/dist/types/src/templates/index.d.ts +2 -0
  57. package/dist/types/src/templates/index.d.ts.map +1 -0
  58. package/dist/types/src/templates/system.d.ts +22 -0
  59. package/dist/types/src/templates/system.d.ts.map +1 -0
  60. package/dist/types/src/types.d.ts +13 -0
  61. package/dist/types/src/types.d.ts.map +1 -1
  62. package/dist/types/tsconfig.tsbuildinfo +1 -1
  63. package/package.json +46 -22
  64. package/src/{context/binder.ts → conversation/context.ts} +51 -19
  65. package/src/conversation/conversation.ts +90 -68
  66. package/src/conversation/index.ts +1 -0
  67. package/src/errors.ts +10 -0
  68. package/src/extraction/extraction-llm-function/extraction-llm-function.test.ts +7 -18
  69. package/src/extraction/extraction-llm-function/extraction-llm-function.ts +22 -17
  70. package/src/extraction/extraction-ner-function/extraction-ner-function.test.ts +4 -3
  71. package/src/extraction/extraction-ner-function/extraction-ner-function.ts +7 -4
  72. package/src/extraction/extraction-ner-function/named-entity-recognition.test.ts +2 -2
  73. package/src/extraction/extraction-ner-function/named-entity-recognition.ts +1 -1
  74. package/src/extraction/quotes.test.ts +1 -1
  75. package/src/extraction/quotes.ts +1 -1
  76. package/src/functions/index.ts +5 -0
  77. package/src/functions/services.ts +114 -0
  78. package/src/index.ts +3 -5
  79. package/src/session/__snapshots__/session.test.ts.snap +32 -0
  80. package/src/session/artifact-diff.ts +37 -0
  81. package/src/session/format.test.ts +60 -0
  82. package/src/session/format.ts +139 -0
  83. package/src/session/index.ts +1 -0
  84. package/src/session/session.test.ts +87 -57
  85. package/src/session/session.ts +220 -523
  86. package/src/session/version-pin.test.ts +2 -21
  87. package/src/session/version-pin.ts +9 -9
  88. package/src/summarization/summarization.test.ts +82 -106
  89. package/src/templates/format.tpl +55 -0
  90. package/src/templates/index.ts +5 -0
  91. package/src/templates/system.tpl +47 -0
  92. package/src/templates/system.ts +32 -0
  93. package/src/types.ts +45 -1
  94. package/src/typings.d.ts +5 -0
  95. package/dist/types/bin/chat.d.ts +0 -2
  96. package/dist/types/bin/chat.d.ts.map +0 -1
  97. package/dist/types/src/blueprint/blueprint.d.ts +0 -41
  98. package/dist/types/src/blueprint/blueprint.d.ts.map +0 -1
  99. package/dist/types/src/blueprint/index.d.ts +0 -3
  100. package/dist/types/src/blueprint/index.d.ts.map +0 -1
  101. package/dist/types/src/blueprint/registry.d.ts +0 -7
  102. package/dist/types/src/blueprint/registry.d.ts.map +0 -1
  103. package/dist/types/src/context/binder.d.ts +0 -34
  104. package/dist/types/src/context/binder.d.ts.map +0 -1
  105. package/dist/types/src/context/binding.d.ts +0 -38
  106. package/dist/types/src/context/binding.d.ts.map +0 -1
  107. package/dist/types/src/context/index.d.ts +0 -3
  108. package/dist/types/src/context/index.d.ts.map +0 -1
  109. package/dist/types/src/research/exa.d.ts +0 -7
  110. package/dist/types/src/research/exa.d.ts.map +0 -1
  111. package/dist/types/src/research/graph.d.ts +0 -41
  112. package/dist/types/src/research/graph.d.ts.map +0 -1
  113. package/dist/types/src/research/graph.test.d.ts +0 -2
  114. package/dist/types/src/research/graph.test.d.ts.map +0 -1
  115. package/dist/types/src/research/index.d.ts +0 -4
  116. package/dist/types/src/research/index.d.ts.map +0 -1
  117. package/dist/types/src/research/research.d.ts +0 -10
  118. package/dist/types/src/research/research.d.ts.map +0 -1
  119. package/dist/types/src/research/research.test.d.ts +0 -2
  120. package/dist/types/src/research/research.test.d.ts.map +0 -1
  121. package/dist/types/src/testing/exa-search-1748337321991.d.ts +0 -38
  122. package/dist/types/src/testing/exa-search-1748337321991.d.ts.map +0 -1
  123. package/dist/types/src/testing/exa-search-1748337331526.d.ts +0 -37
  124. package/dist/types/src/testing/exa-search-1748337331526.d.ts.map +0 -1
  125. package/dist/types/src/testing/exa-search-1748337344119.d.ts +0 -58
  126. package/dist/types/src/testing/exa-search-1748337344119.d.ts.map +0 -1
  127. package/dist/types/src/testing/index.d.ts +0 -3
  128. package/dist/types/src/testing/index.d.ts.map +0 -1
  129. package/src/blueprint/blueprint.ts +0 -75
  130. package/src/blueprint/index.ts +0 -6
  131. package/src/blueprint/registry.ts +0 -15
  132. package/src/context/binding.ts +0 -31
  133. package/src/context/index.ts +0 -6
  134. package/src/research/exa.ts +0 -100
  135. package/src/research/graph.test.ts +0 -15
  136. package/src/research/graph.ts +0 -337
  137. package/src/research/index.ts +0 -7
  138. package/src/research/instructions-research.tpl +0 -97
  139. package/src/research/research.test.ts +0 -190
  140. package/src/research/research.ts +0 -90
  141. package/src/testing/exa-search-1748337321991.ts +0 -131
  142. package/src/testing/exa-search-1748337331526.ts +0 -144
  143. package/src/testing/exa-search-1748337344119.ts +0 -133
  144. package/src/testing/index.ts +0 -11
  145. 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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=format.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.test.d.ts","sourceRoot":"","sources":["../../../../src/session/format.test.ts"],"names":[],"mappings":""}
@@ -1,3 +1,4 @@
1
+ export * from './artifact-diff';
1
2
  export * from './session';
2
3
  export * from './version-pin';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -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 { Schema } from 'effect';
2
- import { type AgentStatus, type AiServiceClient, type GenerateRequest, Message, type ExecutableTool, type ToolId, type ToolResolver } from '@dxos/ai';
3
- import { type ArtifactDefinition } from '@dxos/artifact';
4
- import { Event } from '@dxos/async';
5
- import { ObjectVersion } from '@dxos/echo-db';
6
- import { type ObjectId } from '@dxos/echo-schema';
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
- * Contains message history, tools, current context.
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
- * Pre-require artifacts.
14
+ * Unparsed content block parts from the model.
43
15
  */
44
- requiredArtifactIds?: string[];
45
- client: AiServiceClient;
46
- toolResolver: ToolResolver;
16
+ onPart: (part: AiResponse.Part) => Effect.Effect<void>;
47
17
  /**
48
- * Executable tools that do not go through the tool resolver.
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
- executableTools?: ExecutableTool[];
27
+ onBlock: (block: ContentBlock.Any) => Effect.Effect<void>;
51
28
  /**
52
- * @see ArtifactDiffResolver
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
- artifactDiffResolver?: ArtifactDiffResolver;
55
- };
56
- type OperationModel = 'planning' | 'importing' | 'configured';
57
- export type AiSessionOptions = {
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
- * Determines the agent's handling of the artifacts definitions:
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
- operationModel: OperationModel;
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
- export declare class AISession {
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
- /** SSE stream parser. */
70
- private readonly _parser;
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
- * Complete block added to Message.
66
+ * Blocks streaming from the model during the session.
67
+ * @deprecated Use `observer.onBlock` instead.
122
68
  */
123
- readonly block: Event<{
69
+ readonly blockQueue: Queue.Queue<Option.Option<{
70
+ version: unknown;
71
+ _tag: "anchor";
124
72
  pending?: boolean | undefined;
125
- type: "text";
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
- type: "json";
131
- disposition?: string | undefined;
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
- id: string;
145
- type: "tool_use";
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
- type: "tool_result";
155
- toolUseId: string;
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
- type: "text";
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
- disposition?: string | undefined;
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
- json: string;
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
- type: "tool_result";
194
- toolUseId: string;
195
- content: string;
196
- isError?: boolean | undefined;
197
- }>;
198
- /**
199
- * Unparsed events from the underlying generation stream.
200
- */
201
- readonly streamEvent: Event<import("@dxos/ai").GenerationStreamEvent>;
202
- /**
203
- * User prompt or tool result.
204
- */
205
- readonly userMessage: Event<import("@dxos/echo/Type").OfKind<import("@dxos/echo-schema").EntityKind.Object> & {
206
- id: string;
207
- role: "user" | "assistant";
208
- content: ({
209
- pending?: boolean | undefined;
210
- type: "text";
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(options: SessionRunOptions): Promise<Message[]>;
269
- runStructured<S extends Schema.Schema.AnyNoContext>(schema: S, options: SessionRunOptions): Promise<Schema.Schema.Type<S>>;
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.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