@dxos/assistant 0.8.4-main.fd6878d → 0.8.4-staging.60fe92afc8
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 +102 -5
- package/README.md +2 -1
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/neutral/extraction/index.mjs +208 -0
- package/dist/lib/neutral/extraction/index.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +1886 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/types/src/extraction/extraction-ner-function/index.d.ts +0 -1
- package/dist/types/src/extraction/extraction-ner-function/index.d.ts.map +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 +1650 -281
- package/dist/types/src/extraction/extraction.d.ts.map +1 -1
- package/dist/types/src/extraction/index.d.ts +0 -1
- package/dist/types/src/extraction/index.d.ts.map +1 -1
- package/dist/types/src/extraction/quotes.d.ts +3 -3
- package/dist/types/src/extraction/quotes.d.ts.map +1 -1
- package/dist/types/src/functions/services.d.ts +16 -5
- package/dist/types/src/functions/services.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +2 -3
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/request/AiRequest.d.ts +308 -0
- package/dist/types/src/request/AiRequest.d.ts.map +1 -0
- package/dist/types/src/{session → request}/artifact-diff.d.ts +5 -5
- package/dist/types/src/request/artifact-diff.d.ts.map +1 -0
- package/dist/types/src/request/format.d.ts +15 -0
- package/dist/types/src/request/format.d.ts.map +1 -0
- package/dist/types/src/request/index.d.ts +4 -0
- package/dist/types/src/request/index.d.ts.map +1 -0
- package/dist/types/src/request/observer.d.ts +23 -0
- package/dist/types/src/request/observer.d.ts.map +1 -0
- package/dist/types/src/{session → request}/version-pin.d.ts +6 -6
- package/dist/types/src/request/version-pin.d.ts.map +1 -0
- package/dist/types/src/session/AiContext.d.ts +178 -0
- package/dist/types/src/session/AiContext.d.ts.map +1 -0
- package/dist/types/src/session/AiContext.test.d.ts +2 -0
- package/dist/types/src/session/AiContext.test.d.ts.map +1 -0
- package/dist/types/src/session/AiSession.d.ts +79 -0
- package/dist/types/src/session/AiSession.d.ts.map +1 -0
- package/dist/types/src/session/AiSession.test.d.ts +2 -0
- package/dist/types/src/session/AiSession.test.d.ts.map +1 -0
- package/dist/types/src/session/SessionLink.d.ts +17 -0
- package/dist/types/src/session/SessionLink.d.ts.map +1 -0
- package/dist/types/src/session/SessionLoader.d.ts +15 -0
- package/dist/types/src/session/SessionLoader.d.ts.map +1 -0
- package/dist/types/src/session/SessionLoader.test.d.ts +2 -0
- package/dist/types/src/session/SessionLoader.test.d.ts.map +1 -0
- package/dist/types/src/session/index.d.ts +5 -3
- package/dist/types/src/session/index.d.ts.map +1 -1
- package/dist/types/src/session/toolkit.d.ts +16 -0
- package/dist/types/src/session/toolkit.d.ts.map +1 -0
- package/dist/types/src/templates/system.d.ts +19 -14
- package/dist/types/src/templates/system.d.ts.map +1 -1
- package/dist/types/src/util/artifact.d.ts +18 -0
- package/dist/types/src/util/artifact.d.ts.map +1 -0
- package/dist/types/src/util/diff.d.ts +17 -0
- package/dist/types/src/util/diff.d.ts.map +1 -0
- package/dist/types/src/util/diff.test.d.ts +2 -0
- package/dist/types/src/util/diff.test.d.ts.map +1 -0
- package/dist/types/src/util/error-handling.d.ts +4 -0
- package/dist/types/src/util/error-handling.d.ts.map +1 -0
- package/dist/types/src/util/errors.d.ts +67 -0
- package/dist/types/src/util/errors.d.ts.map +1 -0
- package/dist/types/src/util/execution-graph.d.ts +85 -0
- package/dist/types/src/util/execution-graph.d.ts.map +1 -0
- package/dist/types/src/util/execution-graph.test.d.ts +2 -0
- package/dist/types/src/util/execution-graph.test.d.ts.map +1 -0
- package/dist/types/src/util/index.d.ts +7 -0
- package/dist/types/src/util/index.d.ts.map +1 -0
- package/dist/types/src/util/tracing.d.ts +296 -0
- package/dist/types/src/util/tracing.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +37 -47
- package/src/extraction/extraction-ner-function/index.ts +0 -1
- package/src/extraction/extraction-ner-function/named-entity-recognition.test.ts +12 -6
- package/src/extraction/extraction-ner-function/named-entity-recognition.ts +2 -0
- package/src/extraction/extraction.ts +49 -19
- package/src/extraction/index.ts +0 -1
- package/src/extraction/quotes.test.ts +2 -2
- package/src/extraction/quotes.ts +7 -9
- package/src/functions/services.ts +180 -66
- package/src/index.ts +2 -3
- package/src/request/AiRequest.ts +387 -0
- package/src/{session → request}/artifact-diff.ts +10 -6
- package/src/{session → request}/format.ts +45 -37
- package/src/request/index.ts +8 -0
- package/src/request/observer.ts +62 -0
- package/src/{session → request}/version-pin.ts +8 -8
- package/src/session/AiContext.test.ts +49 -0
- package/src/session/AiContext.ts +420 -0
- package/src/session/AiSession.test.ts +111 -0
- package/src/session/AiSession.ts +328 -0
- package/src/session/SessionLink.ts +23 -0
- package/src/session/SessionLoader.test.ts +115 -0
- package/src/session/SessionLoader.ts +55 -0
- package/src/session/index.ts +6 -3
- package/src/session/toolkit.ts +47 -0
- package/src/templates/{format.tpl → instructions/format.tpl} +6 -4
- package/src/templates/instructions/system.tpl +96 -0
- package/src/templates/system.ts +26 -16
- package/src/util/artifact.ts +96 -0
- package/src/util/diff.test.ts +74 -0
- package/src/util/diff.ts +93 -0
- package/src/util/error-handling.ts +42 -0
- package/src/util/errors.ts +15 -0
- package/src/util/execution-graph.test.ts +740 -0
- package/src/util/execution-graph.ts +520 -0
- package/src/util/index.ts +10 -0
- package/src/util/tracing.ts +60 -0
- package/dist/lib/browser/chunk-6WRGDEMH.mjs +0 -89
- package/dist/lib/browser/chunk-6WRGDEMH.mjs.map +0 -7
- package/dist/lib/browser/chunk-NZGGCEF3.mjs +0 -341
- package/dist/lib/browser/chunk-NZGGCEF3.mjs.map +0 -7
- package/dist/lib/browser/extraction/index.mjs +0 -269
- package/dist/lib/browser/extraction/index.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -354
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/named-entity-recognition-O46UTCLR.mjs +0 -13
- package/dist/lib/node-esm/chunk-3UU5V4FS.mjs +0 -91
- package/dist/lib/node-esm/chunk-3UU5V4FS.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-XOOPGSGW.mjs +0 -343
- package/dist/lib/node-esm/chunk-XOOPGSGW.mjs.map +0 -7
- package/dist/lib/node-esm/extraction/index.mjs +0 -270
- package/dist/lib/node-esm/extraction/index.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -355
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/named-entity-recognition-W4VMRCH6.mjs +0 -14
- package/dist/lib/node-esm/named-entity-recognition-W4VMRCH6.mjs.map +0 -7
- package/dist/types/src/conversation/context.d.ts +0 -90
- package/dist/types/src/conversation/context.d.ts.map +0 -1
- package/dist/types/src/conversation/conversation.d.ts +0 -50
- package/dist/types/src/conversation/conversation.d.ts.map +0 -1
- package/dist/types/src/conversation/index.d.ts +0 -3
- package/dist/types/src/conversation/index.d.ts.map +0 -1
- package/dist/types/src/errors.d.ts +0 -39
- package/dist/types/src/errors.d.ts.map +0 -1
- package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts +0 -4
- package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts.map +0 -1
- package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.test.d.ts +0 -2
- package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.test.d.ts.map +0 -1
- package/dist/types/src/extraction/extraction-llm-function/index.d.ts +0 -2
- package/dist/types/src/extraction/extraction-llm-function/index.d.ts.map +0 -1
- package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts +0 -306
- package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts.map +0 -1
- package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.test.d.ts +0 -2
- package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.test.d.ts.map +0 -1
- package/dist/types/src/session/artifact-diff.d.ts.map +0 -1
- package/dist/types/src/session/format.d.ts +0 -168
- package/dist/types/src/session/format.d.ts.map +0 -1
- package/dist/types/src/session/format.test.d.ts +0 -2
- package/dist/types/src/session/format.test.d.ts.map +0 -1
- package/dist/types/src/session/session.d.ts +0 -167
- package/dist/types/src/session/session.d.ts.map +0 -1
- package/dist/types/src/session/session.test.d.ts +0 -2
- package/dist/types/src/session/session.test.d.ts.map +0 -1
- package/dist/types/src/session/version-pin.d.ts.map +0 -1
- package/dist/types/src/session/version-pin.test.d.ts +0 -2
- package/dist/types/src/session/version-pin.test.d.ts.map +0 -1
- package/dist/types/src/summarization/summarization.test.d.ts +0 -2
- package/dist/types/src/summarization/summarization.test.d.ts.map +0 -1
- package/dist/types/src/types.d.ts +0 -16
- package/dist/types/src/types.d.ts.map +0 -1
- package/src/conversation/context.ts +0 -133
- package/src/conversation/conversation.ts +0 -125
- package/src/conversation/index.ts +0 -6
- package/src/errors.ts +0 -10
- package/src/extraction/extraction-llm-function/extraction-llm-function.test.ts +0 -84
- package/src/extraction/extraction-llm-function/extraction-llm-function.ts +0 -71
- package/src/extraction/extraction-llm-function/index.ts +0 -5
- package/src/extraction/extraction-ner-function/extraction-ner-function.test.ts +0 -116
- package/src/extraction/extraction-ner-function/extraction-ner-function.ts +0 -57
- package/src/session/__snapshots__/session.test.ts.snap +0 -32
- package/src/session/format.test.ts +0 -60
- package/src/session/session.test.ts +0 -305
- package/src/session/session.ts +0 -279
- package/src/session/version-pin.test.ts +0 -7
- package/src/summarization/summarization.test.ts +0 -197
- package/src/templates/system.tpl +0 -47
- package/src/types.ts +0 -52
- /package/dist/lib/{browser/named-entity-recognition-O46UTCLR.mjs.map → neutral/chunk-J5LGTIGS.mjs.map} +0 -0
- /package/src/extraction/extraction-llm-function/{instructions.tpl → transcription-instructions.tpl} +0 -0
|
@@ -1,167 +0,0 @@
|
|
|
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 = {};
|
|
9
|
-
/**
|
|
10
|
-
* Live observer of the generation process.
|
|
11
|
-
*/
|
|
12
|
-
export interface GenerationObserver {
|
|
13
|
-
/**
|
|
14
|
-
* Unparsed content block parts from the model.
|
|
15
|
-
*/
|
|
16
|
-
onPart: (part: AiResponse.Part) => Effect.Effect<void>;
|
|
17
|
-
/**
|
|
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!"}
|
|
26
|
-
*/
|
|
27
|
-
onBlock: (block: ContentBlock.Any) => Effect.Effect<void>;
|
|
28
|
-
/**
|
|
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.
|
|
31
|
-
*/
|
|
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;
|
|
37
|
-
/**
|
|
38
|
-
* Debug printer to be used in unit-tests and browser devtools.
|
|
39
|
-
*/
|
|
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;
|
|
50
|
-
};
|
|
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 {
|
|
62
|
-
private readonly _options;
|
|
63
|
-
/** Complete messages fired during the session, both from the model and from the user. */
|
|
64
|
-
readonly messageQueue: Queue.Queue<import("@dxos/schema").Message>;
|
|
65
|
-
/**
|
|
66
|
-
* Blocks streaming from the model during the session.
|
|
67
|
-
* @deprecated Use `observer.onBlock` instead.
|
|
68
|
-
*/
|
|
69
|
-
readonly blockQueue: Queue.Queue<Option.Option<{
|
|
70
|
-
version: unknown;
|
|
71
|
-
_tag: "anchor";
|
|
72
|
-
pending?: boolean | undefined;
|
|
73
|
-
objectId: string;
|
|
74
|
-
} | {
|
|
75
|
-
name?: string | undefined;
|
|
76
|
-
_tag: "file";
|
|
77
|
-
pending?: boolean | undefined;
|
|
78
|
-
url: string;
|
|
79
|
-
mediaType?: string | undefined;
|
|
80
|
-
} | {
|
|
81
|
-
source?: {
|
|
82
|
-
mediaType: string;
|
|
83
|
-
type: "base64";
|
|
84
|
-
data: string;
|
|
85
|
-
} | {
|
|
86
|
-
url: string;
|
|
87
|
-
type: "http";
|
|
88
|
-
} | undefined;
|
|
89
|
-
id?: string | undefined;
|
|
90
|
-
_tag: "image";
|
|
91
|
-
pending?: boolean | undefined;
|
|
92
|
-
} | {
|
|
93
|
-
_tag: "json";
|
|
94
|
-
pending?: boolean | undefined;
|
|
95
|
-
data: string;
|
|
96
|
-
disposition?: string | undefined;
|
|
97
|
-
} | {
|
|
98
|
-
text: string;
|
|
99
|
-
_tag: "proposal";
|
|
100
|
-
pending?: boolean | undefined;
|
|
101
|
-
} | {
|
|
102
|
-
_tag: "reasoning";
|
|
103
|
-
pending?: boolean | undefined;
|
|
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
|
-
} | {
|
|
120
|
-
text: string;
|
|
121
|
-
_tag: "suggest";
|
|
122
|
-
pending?: boolean | undefined;
|
|
123
|
-
} | {
|
|
124
|
-
text: string;
|
|
125
|
-
_tag: "text";
|
|
126
|
-
pending?: boolean | undefined;
|
|
127
|
-
disposition?: string | undefined;
|
|
128
|
-
mimeType?: string | undefined;
|
|
129
|
-
} | {
|
|
130
|
-
_tag: "toolkit";
|
|
131
|
-
pending?: boolean | undefined;
|
|
132
|
-
} | {
|
|
133
|
-
name: string;
|
|
134
|
-
_tag: "toolCall";
|
|
135
|
-
pending?: boolean | undefined;
|
|
136
|
-
toolCallId: string;
|
|
137
|
-
input: unknown;
|
|
138
|
-
} | {
|
|
139
|
-
name: string;
|
|
140
|
-
_tag: "toolResult";
|
|
141
|
-
pending?: boolean | undefined;
|
|
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);
|
|
160
|
-
/**
|
|
161
|
-
* Runs the AI model loop interacting with tools and artifacts.
|
|
162
|
-
* @returns The messages generated by the session, including the user's prompt.
|
|
163
|
-
*/
|
|
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>>;
|
|
166
|
-
}
|
|
167
|
-
//# sourceMappingURL=session.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../../src/session/session.ts"],"names":[],"mappings":"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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"session.test.d.ts","sourceRoot":"","sources":["../../../../src/session/session.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"version-pin.d.ts","sourceRoot":"","sources":["../../../../src/session/version-pin.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAE,KAAK,aAAa,EAAY,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAKjD,QAAA,MAAM,gBAAgB;;;EAKpB,CAAC;AAEH;;;GAGG;AACH,MAAM,WAAW,UAAW,SAAQ,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,gBAAgB,CAAC;CAAG;AAElF,eAAO,MAAM,UAAU,EAAE,OAAO,gBAAgB,GAAG;IACjD,WAAW,EAAE,aAAa,CAAC;IAC3B,UAAU,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,UAAU,CAAC;IAClD,WAAW,EAAE,CAAC,GAAG,EAAE,UAAU,KAAK,YAAY,CAAC,GAAG,CAAC;CAiBpD,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"version-pin.test.d.ts","sourceRoot":"","sources":["../../../../src/session/version-pin.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"summarization.test.d.ts","sourceRoot":"","sources":["../../../../src/summarization/summarization.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Schema } from 'effect';
|
|
2
|
-
import { type ObjectId } from '@dxos/echo-schema';
|
|
3
|
-
import { DXN, type SpaceId } from '@dxos/keys';
|
|
4
|
-
/**
|
|
5
|
-
* @deprecated
|
|
6
|
-
*/
|
|
7
|
-
export declare const createArtifactElement: (id: ObjectId) => string;
|
|
8
|
-
/**
|
|
9
|
-
* A model-friendly way to reference an object.
|
|
10
|
-
* Supports vairous formats that will be normalized to a DXN.
|
|
11
|
-
*/
|
|
12
|
-
export declare const ArtifactId: Schema.Schema<string> & {
|
|
13
|
-
toDXN: (reference: ArtifactId, owningSpaceId?: SpaceId) => DXN;
|
|
14
|
-
};
|
|
15
|
-
export type ArtifactId = Schema.Schema.Type<typeof ArtifactId>;
|
|
16
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,GAAG,EAAmB,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAGhE;;GAEG;AACH,eAAO,MAAM,qBAAqB,GAAI,IAAI,QAAQ,WAA4B,CAAC;AAE/E;;;GAGG;AAEH,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG;IAC/C,KAAK,EAAE,CAAC,SAAS,EAAE,UAAU,EAAE,aAAa,CAAC,EAAE,OAAO,KAAK,GAAG,CAAC;CA4BhE,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,UAAU,CAAC,CAAC"}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type ReadonlySignal, computed } from '@preact/signals-core';
|
|
6
|
-
import { Schema } from 'effect';
|
|
7
|
-
import { Array, pipe } from 'effect';
|
|
8
|
-
|
|
9
|
-
import { Blueprint } from '@dxos/blueprints';
|
|
10
|
-
import { Obj, type Ref, type Relation, Type } from '@dxos/echo';
|
|
11
|
-
import { type Queue } from '@dxos/echo-db';
|
|
12
|
-
import { ComplexSet } from '@dxos/util';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Thread message that binds or unbinds contextual objects to a conversation.
|
|
16
|
-
*/
|
|
17
|
-
// TODO(burdon): Move to @dxos/schema ContentBlock.
|
|
18
|
-
export const ContextBinding = Schema.Struct({
|
|
19
|
-
blueprints: Schema.Struct({
|
|
20
|
-
added: Schema.Array(Type.Ref(Blueprint.Blueprint)),
|
|
21
|
-
removed: Schema.Array(Type.Ref(Blueprint.Blueprint)),
|
|
22
|
-
}),
|
|
23
|
-
|
|
24
|
-
// TODO(burdon): Type.Expando => Type.Obj (or Obj.Any?)
|
|
25
|
-
objects: Schema.Struct({
|
|
26
|
-
added: Schema.Array(Type.Ref(Type.Expando)),
|
|
27
|
-
removed: Schema.Array(Type.Ref(Type.Expando)),
|
|
28
|
-
}),
|
|
29
|
-
}).pipe(
|
|
30
|
-
Type.Obj({
|
|
31
|
-
typename: 'dxos.org/type/ContextBinding',
|
|
32
|
-
version: '0.1.0',
|
|
33
|
-
}),
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
export interface ContextBinding extends Schema.Schema.Type<typeof ContextBinding> {}
|
|
37
|
-
|
|
38
|
-
export type BindingProps = Partial<{
|
|
39
|
-
blueprints: Ref.Ref<Blueprint.Blueprint>[];
|
|
40
|
-
objects: Ref.Ref<Type.Expando>[];
|
|
41
|
-
}>;
|
|
42
|
-
|
|
43
|
-
export class Bindings {
|
|
44
|
-
readonly blueprints = new ComplexSet<Ref.Ref<Blueprint.Blueprint>>((ref) => ref.dxn.toString());
|
|
45
|
-
readonly objects = new ComplexSet<Ref.Ref<Type.Expando>>((ref) => ref.dxn.toString());
|
|
46
|
-
|
|
47
|
-
toJSON() {
|
|
48
|
-
return {
|
|
49
|
-
blueprints: Array.fromIterable(this.blueprints).map((ref) => ref.dxn.toString()),
|
|
50
|
-
objects: Array.fromIterable(this.objects).map((ref) => ref.dxn.toString()),
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Manages bindings of blueprints and objects to a conversation.
|
|
57
|
-
*/
|
|
58
|
-
export class AiContextBinder {
|
|
59
|
-
/**
|
|
60
|
-
* Reactive query of all bindings.
|
|
61
|
-
*/
|
|
62
|
-
// TODO(burdon): Cache value?
|
|
63
|
-
readonly bindings: ReadonlySignal<Bindings> = computed(() => this._reduce(this._queue.objects));
|
|
64
|
-
|
|
65
|
-
readonly blueprints: ReadonlySignal<Ref.Ref<Blueprint.Blueprint>[]> = computed(() => [
|
|
66
|
-
...this.bindings.value.blueprints,
|
|
67
|
-
]);
|
|
68
|
-
|
|
69
|
-
readonly objects: ReadonlySignal<Ref.Ref<Type.Expando>[]> = computed(() => [...this.bindings.value.objects]);
|
|
70
|
-
|
|
71
|
-
constructor(private readonly _queue: Queue) {}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Asynchronous query of all bindings.
|
|
75
|
-
*/
|
|
76
|
-
async query(): Promise<Bindings> {
|
|
77
|
-
const queueItems = await this._queue.queryObjects();
|
|
78
|
-
return this._reduce(queueItems);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// TODO(burdon): Pass in Blueprint obj (from registry?) and create reference.
|
|
82
|
-
async bind(props: BindingProps): Promise<void> {
|
|
83
|
-
if (!props.blueprints?.length && !props.objects?.length) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
await this._queue.append([
|
|
88
|
-
Obj.make(ContextBinding, {
|
|
89
|
-
blueprints: {
|
|
90
|
-
added: props.blueprints ?? [],
|
|
91
|
-
removed: [],
|
|
92
|
-
},
|
|
93
|
-
objects: {
|
|
94
|
-
added: props.objects ?? [],
|
|
95
|
-
removed: [],
|
|
96
|
-
},
|
|
97
|
-
}),
|
|
98
|
-
]);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
async unbind(props: BindingProps): Promise<void> {
|
|
102
|
-
if (!props.blueprints?.length && !props.objects?.length) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
await this._queue.append([
|
|
107
|
-
Obj.make(ContextBinding, {
|
|
108
|
-
blueprints: {
|
|
109
|
-
added: [],
|
|
110
|
-
removed: props.blueprints ?? [],
|
|
111
|
-
},
|
|
112
|
-
objects: {
|
|
113
|
-
added: [],
|
|
114
|
-
removed: props.objects ?? [],
|
|
115
|
-
},
|
|
116
|
-
}),
|
|
117
|
-
]);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
private _reduce(items: (Obj.Any | Relation.Any)[]): Bindings {
|
|
121
|
-
return pipe(
|
|
122
|
-
items,
|
|
123
|
-
Array.filter(Obj.instanceOf(ContextBinding)),
|
|
124
|
-
Array.reduce(new Bindings(), (context, item) => {
|
|
125
|
-
item.blueprints.removed.forEach((item) => context.blueprints.delete(item));
|
|
126
|
-
item.blueprints.added.forEach((item) => context.blueprints.add(item));
|
|
127
|
-
item.objects.removed.forEach((item) => context.objects.delete(item));
|
|
128
|
-
item.objects.added.forEach((item) => context.objects.add(item));
|
|
129
|
-
return context;
|
|
130
|
-
}),
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type AiError, type AiLanguageModel, type AiTool, type AiToolkit } from '@effect/ai';
|
|
6
|
-
import { Effect } from 'effect';
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
type AiInputPreprocessingError,
|
|
10
|
-
type AiToolNotFoundError,
|
|
11
|
-
type ToolExecutionService,
|
|
12
|
-
type ToolResolverService,
|
|
13
|
-
} from '@dxos/ai';
|
|
14
|
-
import { Event } from '@dxos/async';
|
|
15
|
-
import { Obj } from '@dxos/echo';
|
|
16
|
-
import { type Queue } from '@dxos/echo-db';
|
|
17
|
-
import { DatabaseService } from '@dxos/functions';
|
|
18
|
-
import { log } from '@dxos/log';
|
|
19
|
-
import { DataType } from '@dxos/schema';
|
|
20
|
-
|
|
21
|
-
import { type AiAssistantError } from '../errors';
|
|
22
|
-
import { AiSession, type GenerationObserver } from '../session';
|
|
23
|
-
|
|
24
|
-
import { AiContextBinder, type ContextBinding } from './context';
|
|
25
|
-
|
|
26
|
-
export interface AiConversationRunParams<Tools extends AiTool.Any> {
|
|
27
|
-
prompt: string;
|
|
28
|
-
system?: string;
|
|
29
|
-
toolkit?: AiToolkit.AiToolkit<Tools>;
|
|
30
|
-
observer?: GenerationObserver;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @deprecated Remove
|
|
34
|
-
*/
|
|
35
|
-
session?: AiSession;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export type AiConversationOptions = {
|
|
39
|
-
queue: Queue<DataType.Message | ContextBinding>;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Persistent conversation state.
|
|
44
|
-
* Context + history + artifacts.
|
|
45
|
-
* Backed by a Queue.
|
|
46
|
-
*/
|
|
47
|
-
export class AiConversation {
|
|
48
|
-
private readonly _queue: Queue<DataType.Message | ContextBinding>;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Blueprints bound to the conversation.
|
|
52
|
-
*/
|
|
53
|
-
public readonly _context: AiContextBinder;
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Fired when the execution loop begins.
|
|
57
|
-
* This is called before the first message is sent.
|
|
58
|
-
*
|
|
59
|
-
* @deprecated Pass in a session instead.
|
|
60
|
-
*/
|
|
61
|
-
// TODO(burdon): Is this still deprecated?
|
|
62
|
-
public readonly onBegin = new Event<AiSession>();
|
|
63
|
-
|
|
64
|
-
constructor(options: AiConversationOptions) {
|
|
65
|
-
this._queue = options.queue;
|
|
66
|
-
this._context = new AiContextBinder(this._queue);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
get context() {
|
|
70
|
-
return this._context;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
async getHistory(): Promise<DataType.Message[]> {
|
|
74
|
-
const queueItems = await this._queue.queryObjects();
|
|
75
|
-
return queueItems.filter(Obj.instanceOf(DataType.Message));
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Executes a prompt.
|
|
80
|
-
* Each invocation creates a new `AiSession`, which handles potential tool calls.
|
|
81
|
-
*/
|
|
82
|
-
run = <Tools extends AiTool.Any>({
|
|
83
|
-
// TODO(burdon): Decide whether to pass in or to fully encapsulate.
|
|
84
|
-
session = new AiSession(),
|
|
85
|
-
...params
|
|
86
|
-
}: AiConversationRunParams<Tools>): Effect.Effect<
|
|
87
|
-
DataType.Message[],
|
|
88
|
-
AiAssistantError | AiInputPreprocessingError | AiError.AiError | AiToolNotFoundError,
|
|
89
|
-
AiLanguageModel.AiLanguageModel | ToolResolverService | ToolExecutionService | AiTool.ToHandler<Tools>
|
|
90
|
-
> =>
|
|
91
|
-
Effect.gen(this, function* () {
|
|
92
|
-
const history = yield* Effect.promise(() => this.getHistory());
|
|
93
|
-
const context = yield* Effect.promise(() => this.context.query());
|
|
94
|
-
const blueprints = yield* Effect.forEach(context.blueprints.values(), DatabaseService.load);
|
|
95
|
-
|
|
96
|
-
// TODO(burdon): These don't need to be loaded; just need id and typename from context.
|
|
97
|
-
const objects = yield* Effect.forEach(context.objects.values(), DatabaseService.load);
|
|
98
|
-
|
|
99
|
-
log.info('run', {
|
|
100
|
-
prompt: params.prompt,
|
|
101
|
-
system: params.system,
|
|
102
|
-
history: history.length,
|
|
103
|
-
objects: objects.length,
|
|
104
|
-
blueprints: blueprints.length,
|
|
105
|
-
toolkit: params.toolkit,
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
const start = Date.now();
|
|
109
|
-
this.onBegin.emit(session);
|
|
110
|
-
|
|
111
|
-
const messages = yield* session.run({
|
|
112
|
-
prompt: params.prompt,
|
|
113
|
-
system: params.system,
|
|
114
|
-
history,
|
|
115
|
-
objects,
|
|
116
|
-
blueprints,
|
|
117
|
-
toolkit: params.toolkit,
|
|
118
|
-
observer: params.observer,
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
log.info('result', { messages: messages, duration: Date.now() - start });
|
|
122
|
-
yield* Effect.promise(() => this._queue.append(messages));
|
|
123
|
-
return messages;
|
|
124
|
-
}).pipe(Effect.withSpan('AiConversation.run'));
|
|
125
|
-
}
|
package/src/errors.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { beforeAll, describe, test } from 'vitest';
|
|
6
|
-
|
|
7
|
-
import { todo } from '@dxos/debug';
|
|
8
|
-
import { FunctionExecutor } from '@dxos/functions';
|
|
9
|
-
import { log } from '@dxos/log';
|
|
10
|
-
import { createTestData } from '@dxos/schema/testing';
|
|
11
|
-
import { range } from '@dxos/util';
|
|
12
|
-
|
|
13
|
-
import { processTranscriptMessage } from '../extraction';
|
|
14
|
-
|
|
15
|
-
import { extractionAnthropicFn } from './extraction-llm-function';
|
|
16
|
-
|
|
17
|
-
// TODO(burdon): Rewrite test.
|
|
18
|
-
describe.skip('LLM EntityExtraction', () => {
|
|
19
|
-
let executor: FunctionExecutor;
|
|
20
|
-
|
|
21
|
-
beforeAll(async () => {
|
|
22
|
-
executor = new FunctionExecutor(todo());
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test('should process a transcript block', async () => {
|
|
26
|
-
const { transcriptMessages, documents, contacts } = createTestData();
|
|
27
|
-
log.info('context', { documents, contacts });
|
|
28
|
-
|
|
29
|
-
for (const message of transcriptMessages.slice(0, 1)) {
|
|
30
|
-
log.info('input', message);
|
|
31
|
-
const { message: enhancedMessage } = await processTranscriptMessage({
|
|
32
|
-
input: {
|
|
33
|
-
message,
|
|
34
|
-
objects: [...documents, ...Object.values(contacts)],
|
|
35
|
-
},
|
|
36
|
-
function: extractionAnthropicFn,
|
|
37
|
-
executor,
|
|
38
|
-
});
|
|
39
|
-
log.info('output', enhancedMessage);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test('computational irreducibility', async () => {
|
|
44
|
-
const { transcriptWoflram, documents, contacts } = createTestData();
|
|
45
|
-
|
|
46
|
-
log.info('context', { documents, contacts });
|
|
47
|
-
const message = transcriptWoflram[0];
|
|
48
|
-
log.info('input', message);
|
|
49
|
-
|
|
50
|
-
await Promise.all(
|
|
51
|
-
range(10).map(async () => {
|
|
52
|
-
const { message: enhancedMessage, timeElapsed } = await processTranscriptMessage({
|
|
53
|
-
input: {
|
|
54
|
-
message,
|
|
55
|
-
objects: [...documents, ...Object.values(contacts)],
|
|
56
|
-
},
|
|
57
|
-
function: extractionAnthropicFn,
|
|
58
|
-
executor,
|
|
59
|
-
});
|
|
60
|
-
log.info('output', { message: enhancedMessage.blocks[0], timeElapsed });
|
|
61
|
-
}),
|
|
62
|
-
);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
test('org and document linking', async () => {
|
|
66
|
-
const { transcriptJosiah, documents, contacts, organizations } = createTestData();
|
|
67
|
-
|
|
68
|
-
log.info('context', { contacts, organizations, documents });
|
|
69
|
-
|
|
70
|
-
for (const message of transcriptJosiah) {
|
|
71
|
-
log.info('input', message);
|
|
72
|
-
|
|
73
|
-
const { message: enhancedMessage } = await processTranscriptMessage({
|
|
74
|
-
input: {
|
|
75
|
-
message,
|
|
76
|
-
objects: [...documents, ...Object.values(contacts), ...Object.values(organizations)],
|
|
77
|
-
},
|
|
78
|
-
function: extractionAnthropicFn,
|
|
79
|
-
executor,
|
|
80
|
-
});
|
|
81
|
-
log.info('output', enhancedMessage);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
});
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
// ISSUE(burdon): defineFunction
|
|
6
|
-
// @ts-nocheck
|
|
7
|
-
|
|
8
|
-
import { AiService, ToolRegistry } from '@dxos/ai';
|
|
9
|
-
import { Obj } from '@dxos/echo';
|
|
10
|
-
import { create } from '@dxos/echo-schema';
|
|
11
|
-
import { type FunctionDefinition, defineFunction } from '@dxos/functions';
|
|
12
|
-
import { type ContentBlock, DataType } from '@dxos/schema';
|
|
13
|
-
|
|
14
|
-
import { AiSession } from '../../session';
|
|
15
|
-
import { ExtractionInput, ExtractionOutput } from '../extraction';
|
|
16
|
-
import { ReferencedQuotes, insertReferences } from '../quotes';
|
|
17
|
-
|
|
18
|
-
import PROMPT from './instructions.tpl?raw';
|
|
19
|
-
|
|
20
|
-
export const extractionAnthropicFn: FunctionDefinition<ExtractionInput, ExtractionOutput> = defineFunction({
|
|
21
|
-
description: 'Extract entities from the transcript message and add them to the message.',
|
|
22
|
-
inputSchema: ExtractionInput,
|
|
23
|
-
outputSchema: ExtractionOutput,
|
|
24
|
-
handler: async ({ data: { message, objects }, context }) => {
|
|
25
|
-
const startTime = performance.now();
|
|
26
|
-
const ai = context.getService(AiService.AiService);
|
|
27
|
-
const session = new AiSession({ operationModel: 'configured' });
|
|
28
|
-
const result = await session.runStructured(ReferencedQuotes, {
|
|
29
|
-
generationOptions: {
|
|
30
|
-
model: '@anthropic/claude-3-5-haiku-20241022',
|
|
31
|
-
},
|
|
32
|
-
client: ai.client,
|
|
33
|
-
systemPrompt: PROMPT,
|
|
34
|
-
history: [
|
|
35
|
-
Obj.make(DataType.Message, {
|
|
36
|
-
created: new Date().toISOString(),
|
|
37
|
-
sender: { role: 'user' },
|
|
38
|
-
blocks: [
|
|
39
|
-
{
|
|
40
|
-
_tag: 'text',
|
|
41
|
-
text: `<context>${JSON.stringify(objects)}</context>`,
|
|
42
|
-
} satisfies ContentBlock.Text,
|
|
43
|
-
{
|
|
44
|
-
_tag: 'text',
|
|
45
|
-
text: `<transcript>${JSON.stringify(message.blocks)}</transcript>`,
|
|
46
|
-
} satisfies ContentBlock.Text,
|
|
47
|
-
],
|
|
48
|
-
}),
|
|
49
|
-
],
|
|
50
|
-
artifacts: [],
|
|
51
|
-
prompt: '',
|
|
52
|
-
tools: [],
|
|
53
|
-
toolResolver: new ToolRegistry([]),
|
|
54
|
-
} as any); // TODO(burdon): Rewrite test.
|
|
55
|
-
|
|
56
|
-
return {
|
|
57
|
-
message: create(DataType.Message, {
|
|
58
|
-
...message,
|
|
59
|
-
blocks: message.blocks.map((block, i) =>
|
|
60
|
-
block._tag !== 'transcript'
|
|
61
|
-
? block
|
|
62
|
-
: {
|
|
63
|
-
...block,
|
|
64
|
-
text: insertReferences(block.text, result),
|
|
65
|
-
},
|
|
66
|
-
),
|
|
67
|
-
}),
|
|
68
|
-
timeElapsed: performance.now() - startTime,
|
|
69
|
-
};
|
|
70
|
-
},
|
|
71
|
-
});
|