@dxos/assistant 0.9.0 → 0.9.1-main.c7dcc2e112
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/neutral/extraction/index.mjs +108 -119
- package/dist/lib/neutral/extraction/index.mjs.map +4 -4
- package/dist/lib/neutral/index.mjs +17 -13
- package/dist/lib/neutral/index.mjs.map +4 -4
- package/dist/lib/neutral/meta.json +1 -1
- package/dist/types/src/extraction/extraction-llm-function/index.d.ts +2 -0
- package/dist/types/src/extraction/extraction-llm-function/index.d.ts.map +1 -0
- package/dist/types/src/extraction/extraction-llm-function/proper-noun-extraction.d.ts +227 -0
- package/dist/types/src/extraction/extraction-llm-function/proper-noun-extraction.d.ts.map +1 -0
- package/dist/types/src/extraction/index.d.ts +1 -1
- package/dist/types/src/extraction/index.d.ts.map +1 -1
- package/dist/types/src/extraction/quotes.d.ts +8 -1
- package/dist/types/src/extraction/quotes.d.ts.map +1 -1
- package/dist/types/src/request/AiRequest.d.ts +6 -0
- package/dist/types/src/request/AiRequest.d.ts.map +1 -1
- package/dist/types/src/session/AiSession.d.ts +6 -0
- package/dist/types/src/session/AiSession.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +21 -21
- package/src/extraction/extraction-llm-function/index.ts +5 -0
- package/src/extraction/extraction-llm-function/proper-noun-extraction.ts +78 -0
- package/src/extraction/index.ts +1 -1
- package/src/extraction/quotes.test.ts +67 -2
- package/src/extraction/quotes.ts +47 -13
- package/src/request/AiRequest.ts +10 -0
- package/src/session/AiSession.ts +8 -0
- package/dist/types/src/extraction/extraction.d.ts +0 -1677
- package/dist/types/src/extraction/extraction.d.ts.map +0 -1
- package/src/extraction/extraction-llm-function/transcription-instructions.tpl +0 -28
- package/src/extraction/extraction.ts +0 -105
|
@@ -1,78 +1,120 @@
|
|
|
1
1
|
import "../chunk-J5LGTIGS.mjs";
|
|
2
2
|
|
|
3
|
-
// src/extraction/extraction.ts
|
|
4
|
-
import * as
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
3
|
+
// src/extraction/extraction-llm-function/proper-noun-extraction.ts
|
|
4
|
+
import * as LanguageModel from "@effect/ai/LanguageModel";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
6
|
+
import * as Schema2 from "effect/Schema";
|
|
7
|
+
import { AiService } from "@dxos/ai";
|
|
8
|
+
import { Obj } from "@dxos/echo";
|
|
9
9
|
import { Message } from "@dxos/types";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
name: "Entity Extraction (Anthropic)",
|
|
27
|
-
description: "Extract entities from transcript using Anthropic LLM.",
|
|
28
|
-
icon: "ph--text-t--regular"
|
|
29
|
-
},
|
|
30
|
-
input: ExtractionInput,
|
|
31
|
-
output: ExtractionOutput
|
|
32
|
-
});
|
|
33
|
-
var extractionNerFunction = Operation.make({
|
|
34
|
-
meta: {
|
|
35
|
-
key: DXN.make("org.dxos.function.extraction.ner"),
|
|
36
|
-
name: "Entity Extraction (NER)",
|
|
37
|
-
description: "Extract entities from transcript using Named Entity Recognition.",
|
|
38
|
-
icon: "ph--text-t--regular"
|
|
39
|
-
},
|
|
40
|
-
input: ExtractionInput,
|
|
41
|
-
output: ExtractionOutput
|
|
10
|
+
|
|
11
|
+
// src/extraction/quotes.ts
|
|
12
|
+
import * as Schema from "effect/Schema";
|
|
13
|
+
import { Filter, Query } from "@dxos/echo";
|
|
14
|
+
import { EID, EntityId } from "@dxos/keys";
|
|
15
|
+
var ReferencedQuotes = Schema.Struct({
|
|
16
|
+
references: Schema.Array(Schema.Struct({
|
|
17
|
+
id: Schema.String,
|
|
18
|
+
quote: Schema.String
|
|
19
|
+
})).pipe(Schema.mutable).annotations({
|
|
20
|
+
// TODO(burdon): Does this description make sense?
|
|
21
|
+
description: `
|
|
22
|
+
The references to the context objects that are mentioned in the transcript.
|
|
23
|
+
Quote should match the original transcript text exactly, while id is the id of the context object.
|
|
24
|
+
`
|
|
25
|
+
})
|
|
42
26
|
});
|
|
43
|
-
var
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
};
|
|
57
|
-
} else {
|
|
58
|
-
throw error;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
27
|
+
var findReferences = async (nouns, db, { searchKind = "full-text" } = {}) => {
|
|
28
|
+
const normalizedNouns = Array.from(new Set(nouns.map((noun) => noun.trim()).filter((noun) => noun.length > 0))).sort((leftNoun, rightNoun) => rightNoun.length - leftNoun.length);
|
|
29
|
+
const references = await Promise.all(normalizedNouns.map(async (noun) => {
|
|
30
|
+
const objects = await db.query(Query.select(Filter.text(noun, {
|
|
31
|
+
type: searchKind
|
|
32
|
+
}))).run();
|
|
33
|
+
return objects.length > 0 ? [
|
|
34
|
+
{
|
|
35
|
+
id: objects[0].id.toString(),
|
|
36
|
+
quote: noun
|
|
37
|
+
}
|
|
38
|
+
] : [];
|
|
39
|
+
}));
|
|
61
40
|
return {
|
|
62
|
-
|
|
63
|
-
timeElapsed: 0
|
|
41
|
+
references: references.flat()
|
|
64
42
|
};
|
|
65
43
|
};
|
|
44
|
+
var insertReferences = (text, quotes) => {
|
|
45
|
+
const references = quotes.references.filter((quote) => EntityId.isValid(quote.id)).sort((left, right) => right.quote.length - left.quote.length);
|
|
46
|
+
for (const quote of references) {
|
|
47
|
+
const regex = new RegExp(quote.quote.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "gi");
|
|
48
|
+
text = replaceOutsideLinks(text, regex, `[${quote.quote}](${EID.make({
|
|
49
|
+
entityId: quote.id
|
|
50
|
+
})})`);
|
|
51
|
+
}
|
|
52
|
+
return text;
|
|
53
|
+
};
|
|
54
|
+
var MARKDOWN_LINK = /\[[^\]]*\]\([^)]*\)/g;
|
|
55
|
+
var replaceOutsideLinks = (text, regex, replacement) => {
|
|
56
|
+
let result = "";
|
|
57
|
+
let plainStart = 0;
|
|
58
|
+
for (const link of text.matchAll(MARKDOWN_LINK)) {
|
|
59
|
+
const index = link.index ?? 0;
|
|
60
|
+
result += text.slice(plainStart, index).replace(regex, replacement) + link[0];
|
|
61
|
+
plainStart = index + link[0].length;
|
|
62
|
+
}
|
|
63
|
+
return result + text.slice(plainStart).replace(regex, replacement);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// src/extraction/extraction-llm-function/proper-noun-extraction.ts
|
|
67
|
+
var EXTRACTION_MODEL = "ai.claude.model.claude-haiku-4-5";
|
|
68
|
+
var ProperNouns = Schema2.Struct({
|
|
69
|
+
properNouns: Schema2.Array(Schema2.String).annotations({
|
|
70
|
+
description: "Proper nouns (names of people, organizations, places, products) mentioned in the text."
|
|
71
|
+
})
|
|
72
|
+
});
|
|
73
|
+
var extractProperNouns = (text) => Effect.gen(function* () {
|
|
74
|
+
const { value } = yield* Effect.scoped(LanguageModel.generateObject({
|
|
75
|
+
schema: ProperNouns,
|
|
76
|
+
prompt: [
|
|
77
|
+
"Extract every proper noun (people, organizations, places, products) mentioned in the transcript text below.",
|
|
78
|
+
"Return only the surface strings exactly as they appear. Exclude common nouns and pronouns.",
|
|
79
|
+
"",
|
|
80
|
+
"Transcript:",
|
|
81
|
+
text
|
|
82
|
+
].join("\n")
|
|
83
|
+
}));
|
|
84
|
+
return value.properNouns.map((noun) => noun.trim()).filter((noun) => noun.length >= 3);
|
|
85
|
+
}).pipe(Effect.provide(AiService.model(EXTRACTION_MODEL)));
|
|
86
|
+
var enrichTranscriptMessage = (message, { db }) => Effect.gen(function* () {
|
|
87
|
+
const blocks = yield* Effect.forEach(message.blocks, (block) => Effect.gen(function* () {
|
|
88
|
+
if (block._tag !== "transcript") {
|
|
89
|
+
return block;
|
|
90
|
+
}
|
|
91
|
+
const nouns = yield* extractProperNouns(block.text);
|
|
92
|
+
const references = yield* Effect.promise(() => findReferences([
|
|
93
|
+
...nouns
|
|
94
|
+
], db));
|
|
95
|
+
return {
|
|
96
|
+
...block,
|
|
97
|
+
text: insertReferences(block.text, references)
|
|
98
|
+
};
|
|
99
|
+
}));
|
|
100
|
+
return Obj.make(Message.Message, {
|
|
101
|
+
id: message.id,
|
|
102
|
+
sender: message.sender,
|
|
103
|
+
created: message.created,
|
|
104
|
+
properties: message.properties,
|
|
105
|
+
blocks
|
|
106
|
+
});
|
|
107
|
+
});
|
|
66
108
|
|
|
67
109
|
// src/extraction/extraction-ner-function/named-entity-recognition.ts
|
|
68
110
|
import { pipeline } from "@xenova/transformers";
|
|
69
|
-
import { log
|
|
70
|
-
var
|
|
111
|
+
import { log } from "@dxos/log";
|
|
112
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/core/compute/assistant/src/extraction/extraction-ner-function/named-entity-recognition.ts";
|
|
71
113
|
var _ner;
|
|
72
114
|
var getNer = () => {
|
|
73
115
|
if (!_ner) {
|
|
74
116
|
_ner = pipeline("ner", "Xenova/bert-base-NER").then((ner) => {
|
|
75
|
-
|
|
117
|
+
log.info("NER model is ready", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 14, S: void 0 });
|
|
76
118
|
return ner;
|
|
77
119
|
});
|
|
78
120
|
}
|
|
@@ -140,69 +182,16 @@ var combineNerTokens = (group) => {
|
|
|
140
182
|
}
|
|
141
183
|
return combinedToken;
|
|
142
184
|
};
|
|
143
|
-
|
|
144
|
-
// src/extraction/quotes.ts
|
|
145
|
-
import * as Schema2 from "effect/Schema";
|
|
146
|
-
import { Filter, Query } from "@dxos/echo";
|
|
147
|
-
import { EID, EntityId } from "@dxos/keys";
|
|
148
|
-
import { log as log3 } from "@dxos/log";
|
|
149
|
-
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/compute/assistant/src/extraction/quotes.ts";
|
|
150
|
-
var ReferencedQuotes = Schema2.Struct({
|
|
151
|
-
references: Schema2.Array(Schema2.Struct({
|
|
152
|
-
id: Schema2.String,
|
|
153
|
-
quote: Schema2.String
|
|
154
|
-
})).pipe(Schema2.mutable).annotations({
|
|
155
|
-
// TODO(burdon): Does this description make sense?
|
|
156
|
-
description: `
|
|
157
|
-
The references to the context objects that are mentioned in the transcript.
|
|
158
|
-
Quote should match the original transcript text exactly, while id is the id of the context object.
|
|
159
|
-
`
|
|
160
|
-
})
|
|
161
|
-
});
|
|
162
|
-
var findQuotes = async (quotes, db) => {
|
|
163
|
-
const references = await Promise.all(quotes.map(async (quote) => {
|
|
164
|
-
const objects = await db.query(Query.select(Filter.text(quote, {
|
|
165
|
-
type: "vector"
|
|
166
|
-
}))).run();
|
|
167
|
-
log3.info("found quotes in vector index", {
|
|
168
|
-
objects,
|
|
169
|
-
quote
|
|
170
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 25, S: void 0 });
|
|
171
|
-
return objects.length > 0 ? [
|
|
172
|
-
{
|
|
173
|
-
id: objects[0].id.toString(),
|
|
174
|
-
quote
|
|
175
|
-
}
|
|
176
|
-
] : [];
|
|
177
|
-
}));
|
|
178
|
-
return {
|
|
179
|
-
references: references.flat()
|
|
180
|
-
};
|
|
181
|
-
};
|
|
182
|
-
var insertReferences = (text, quotes) => {
|
|
183
|
-
for (const quote of quotes.references) {
|
|
184
|
-
if (!EntityId.isValid(quote.id)) {
|
|
185
|
-
continue;
|
|
186
|
-
}
|
|
187
|
-
const regex = new RegExp(quote.quote.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "gi");
|
|
188
|
-
text = text.replace(regex, `[${quote.quote}](${EID.make({
|
|
189
|
-
entityId: quote.id
|
|
190
|
-
})})`);
|
|
191
|
-
}
|
|
192
|
-
return text;
|
|
193
|
-
};
|
|
194
185
|
export {
|
|
195
|
-
|
|
196
|
-
ExtractionOutput,
|
|
186
|
+
ProperNouns,
|
|
197
187
|
ReferencedQuotes,
|
|
198
188
|
combineNerTokens,
|
|
199
189
|
createTokenGroups,
|
|
190
|
+
enrichTranscriptMessage,
|
|
200
191
|
extractFullEntities,
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
findQuotes,
|
|
192
|
+
extractProperNouns,
|
|
193
|
+
findReferences,
|
|
204
194
|
getNer,
|
|
205
|
-
insertReferences
|
|
206
|
-
processTranscriptMessage
|
|
195
|
+
insertReferences
|
|
207
196
|
};
|
|
208
197
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../../src/extraction/extraction.ts", "../../../../src/extraction/extraction-ner-function/named-entity-recognition.ts"
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport {
|
|
5
|
-
"mappings": ";;;AAIA,YAAYA,YAAY;AAExB,SAASC,iBAAiB;AAC1B,SAASC,
|
|
6
|
-
"names": ["Schema", "
|
|
3
|
+
"sources": ["../../../../src/extraction/extraction-llm-function/proper-noun-extraction.ts", "../../../../src/extraction/quotes.ts", "../../../../src/extraction/extraction-ner-function/named-entity-recognition.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as LanguageModel from '@effect/ai/LanguageModel';\nimport * as Effect from 'effect/Effect';\nimport * as Schema from 'effect/Schema';\n\nimport { AiService } from '@dxos/ai';\nimport { type Database, Obj } from '@dxos/echo';\nimport { Message } from '@dxos/types';\n\nimport { findReferences, insertReferences } from '../quotes';\n\nconst EXTRACTION_MODEL = 'ai.claude.model.claude-haiku-4-5';\n\n/**\n * Proper nouns extracted from transcript text.\n */\nexport const ProperNouns = Schema.Struct({\n properNouns: Schema.Array(Schema.String).annotations({\n description: 'Proper nouns (names of people, organizations, places, products) mentioned in the text.',\n }),\n});\nexport type ProperNouns = Schema.Schema.Type<typeof ProperNouns>;\n\n/**\n * Extracts proper nouns from transcript text using a small LLM (Haiku). Provides the LanguageModel\n * internally so the residual requirement is just {@link AiService.AiService}.\n */\nexport const extractProperNouns = (text: string) =>\n Effect.gen(function* () {\n const { value } = yield* Effect.scoped(\n LanguageModel.generateObject({\n schema: ProperNouns,\n prompt: [\n 'Extract every proper noun (people, organizations, places, products) mentioned in the transcript text below.',\n 'Return only the surface strings exactly as they appear. Exclude common nouns and pronouns.',\n '',\n 'Transcript:',\n text,\n ].join('\\n'),\n }),\n );\n\n // Drop short tokens (e.g. \"IT\"): insertReferences replaces case-insensitive substrings, so a\n // short noun would match inside unrelated words (\"secur[IT]y\") and corrupt neighbouring links.\n return value.properNouns.map((noun) => noun.trim()).filter((noun) => noun.length >= 3);\n }).pipe(Effect.provide(AiService.model(EXTRACTION_MODEL)));\n\n/**\n * Enriches a transcript message: for each transcript block, extracts proper nouns, links them to\n * objects in the space via full-text search, and rewrites the text with `[noun](dxn)` references.\n * Requires {@link AiService.AiService}; takes the space database handle.\n */\nexport const enrichTranscriptMessage = (message: Message.Message, { db }: { db: Database.Database }) =>\n Effect.gen(function* () {\n const blocks = yield* Effect.forEach(message.blocks, (block) =>\n Effect.gen(function* () {\n if (block._tag !== 'transcript') {\n return block;\n }\n\n const nouns = yield* extractProperNouns(block.text);\n const references = yield* Effect.promise(() => findReferences([...nouns], db));\n return { ...block, text: insertReferences(block.text, references) };\n }),\n );\n\n // Preserve the message identity and metadata; enrichment only rewrites transcript block text.\n return Obj.make(Message.Message, {\n id: message.id,\n sender: message.sender,\n created: message.created,\n properties: message.properties,\n blocks,\n });\n });\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { type Database, Filter, Query } from '@dxos/echo';\nimport { EID, EntityId } from '@dxos/keys';\n\nexport const ReferencedQuotes = Schema.Struct({\n references: Schema.Array(\n Schema.Struct({\n id: Schema.String,\n quote: Schema.String, // TODO(burdon): Quote?\n }),\n )\n .pipe(Schema.mutable)\n .annotations({\n // TODO(burdon): Does this description make sense?\n description: `\n The references to the context objects that are mentioned in the transcript. \n Quote should match the original transcript text exactly, while id is the id of the context object.\n `,\n }),\n});\nexport type ReferencedQuotes = Schema.Schema.Type<typeof ReferencedQuotes>;\n\nexport type FindReferencesOptions = {\n /** Search backend. Full-text matches proper nouns precisely; vector matches semantically. */\n searchKind?: 'full-text' | 'vector';\n};\n\n/**\n * Finds the best-matching context object for each noun and returns it as a reference.\n */\nexport const findReferences = async (\n nouns: string[],\n db: Database.Database,\n { searchKind = 'full-text' }: FindReferencesOptions = {},\n): Promise<ReferencedQuotes> => {\n // Deduplicate and process longer nouns first: `insertReferences` rewrites case-insensitive\n // substrings, so a repeated or shorter overlapping noun would re-replace already-linked text and\n // produce nested/broken markdown links.\n const normalizedNouns = Array.from(new Set(nouns.map((noun) => noun.trim()).filter((noun) => noun.length > 0))).sort(\n (leftNoun, rightNoun) => rightNoun.length - leftNoun.length,\n );\n\n const references = await Promise.all(\n normalizedNouns.map(async (noun) => {\n const objects = await db.query(Query.select(Filter.text(noun, { type: searchKind }))).run();\n return objects.length > 0 ? [{ id: objects[0].id.toString(), quote: noun }] : [];\n }),\n );\n return { references: references.flat() };\n};\n\n/**\n * Finds and replaces all quotes with DXNs references.\n */\n// TODO(dmaretskyi): Lookup and verifiy ids from provided context.\nexport const insertReferences = (text: string, quotes: ReferencedQuotes): string => {\n // Process longer quotes first so e.g. \"Sarah Johnson\" is linked before \"Sarah\". Combined with the\n // link-aware replacement below this stops a shorter or overlapping quote from rewriting text that\n // is already part of an inserted link (which would produce nested `[[..](..)](..)` markdown).\n const references = quotes.references\n .filter((quote) => EntityId.isValid(quote.id))\n .sort((left, right) => right.quote.length - left.quote.length);\n\n for (const quote of references) {\n // Case-insensitive match of the (regex-escaped) quote.\n const regex = new RegExp(quote.quote.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&'), 'gi');\n text = replaceOutsideLinks(text, regex, `[${quote.quote}](${EID.make({ entityId: quote.id })})`);\n }\n\n return text;\n};\n\nconst MARKDOWN_LINK = /\\[[^\\]]*\\]\\([^)]*\\)/g;\n\n/** Applies a replacement to every span of `text` that is not already inside a `[label](url)` link. */\nconst replaceOutsideLinks = (text: string, regex: RegExp, replacement: string): string => {\n let result = '';\n let plainStart = 0;\n for (const link of text.matchAll(MARKDOWN_LINK)) {\n const index = link.index ?? 0;\n result += text.slice(plainStart, index).replace(regex, replacement) + link[0];\n plainStart = index + link[0].length;\n }\n return result + text.slice(plainStart).replace(regex, replacement);\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport {\n type TokenClassificationOutput,\n type TokenClassificationPipelineType,\n type TokenClassificationSingle,\n pipeline,\n} from '@xenova/transformers';\n\nimport { log } from '@dxos/log';\n\nlet _ner: Promise<TokenClassificationPipelineType>;\n\n/**\n * Named Entity Recognition pipeline.\n * Initializes the pipeline on first call.\n * @returns The singleton promise that resolves to a token classification pipeline.\n */\nexport const getNer = () => {\n if (!_ner) {\n _ner = pipeline('ner', 'Xenova/bert-base-NER').then((ner) => {\n log.info('NER model is ready');\n return ner;\n });\n }\n\n return _ner;\n};\n\n/**\n * Extracts entities from text using the named entity recognition pipeline and does simple grouping of tokens.\n */\nexport const extractFullEntities = async (text: string): Promise<TokenClassificationSingle[]> => {\n const ner = await getNer();\n const entities = (await ner(text)) as TokenClassificationOutput;\n const tokenGroups = createTokenGroups(entities);\n const combinedEntities = tokenGroups.map(combineNerTokens);\n return combinedEntities;\n};\n\nexport const createTokenGroups = (tokens: TokenClassificationSingle[]): TokenClassificationSingle[][] => {\n const tokenGroups: TokenClassificationSingle[][] = [];\n\n const canBeCombined = (prevToken: TokenClassificationSingle, currentToken: TokenClassificationSingle) => {\n const [currentState, currentEntity] = currentToken.entity.split('-'); // B, I, O\n const [prevState, prevEntity] = prevToken.entity.split('-'); // B, I, O\n if (prevEntity !== currentEntity) {\n return false;\n }\n if (prevState === 'O') {\n return false;\n }\n if (currentState === 'I') {\n return true;\n }\n if ((prevState === 'B' || prevState === 'I') && currentState === 'B') {\n return currentToken.word.startsWith('#');\n }\n return false;\n };\n\n for (const token of tokens) {\n if (tokenGroups.length === 0) {\n tokenGroups.push([token]);\n continue;\n }\n const lastTokenGroup = tokenGroups.at(-1)!;\n if (canBeCombined(lastTokenGroup.at(-1)!, token)) {\n lastTokenGroup.push(token);\n continue;\n }\n tokenGroups.push([token]);\n }\n\n return tokenGroups;\n};\n\nexport const combineNerTokens = (group: TokenClassificationSingle[]): TokenClassificationSingle => {\n const combinedToken: TokenClassificationSingle = {\n entity: group.at(0)!.entity.split('-')[1],\n score: group.reduce((acc, token) => acc + token.score, 0) / group.length,\n index: group.at(0)!.index,\n word: group.at(0)!.word,\n start: group.at(0)!.start,\n end: group.at(-1)!.end,\n };\n\n for (const token of group.slice(1)) {\n if (token.word.startsWith('#')) {\n combinedToken.word += token.word.replace(/^#+/, '');\n } else {\n combinedToken.word += ' ' + token.word;\n }\n }\n\n return combinedToken;\n};\n"],
|
|
5
|
+
"mappings": ";;;AAIA,YAAYA,mBAAmB;AAC/B,YAAYC,YAAY;AACxB,YAAYC,aAAY;AAExB,SAASC,iBAAiB;AAC1B,SAAwBC,WAAW;AACnC,SAASC,eAAe;;;ACNxB,YAAYC,YAAY;AAExB,SAAwBC,QAAQC,aAAa;AAC7C,SAASC,KAAKC,gBAAgB;AAEvB,IAAMC,mBAA0BC,cAAO;EAC5CC,YAAmBC,aACVF,cAAO;IACZG,IAAWC;IACXC,OAAcD;EAChB,CAAA,CAAA,EAECE,KAAYC,cAAO,EACnBC,YAAY;;IAEXC,aAAa;;;;EAIf,CAAA;AACJ,CAAA;AAWO,IAAMC,iBAAiB,OAC5BC,OACAC,IACA,EAAEC,aAAa,YAAW,IAA4B,CAAC,MAAC;AAKxD,QAAMC,kBAAkBZ,MAAMa,KAAK,IAAIC,IAAIL,MAAMM,IAAI,C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AAA;MAC1B;IAEA,CAAA;EACA;AAEF,SAAO;;IAEHQ,mBAAqBA,CAAAA,UAAa;QAClCM,gBAAaC;IACbC,QAAOC,MAAMC,GAAG,CAAA,EAAIF,OAAK,MAAA,GAAA,EAAA,CAAA;IACzBG,OAAMF,MAAMC,OAAOC,CAAAA,KAAI,UAAA,MAAA,MAAA,OAAA,CAAA,IAAA,MAAA;IACvBC,OAAOH,MAAMC,GAAG,CAAA,EAAIE;IACpBC,MAAKJ,MAAMC,GAAI,CAAA,EAAIG;IACrB,OAAA,MAAA,GAAA,CAAA,EAAA;IAEA,KAAK,MAAMV,GAAAA,EAASM,EAAAA;;aAEhBK,SAAAA,MAAkB,MAAIX,CAAAA,GAAAA;AACxB,QAAA,MAAO,KAAA,WAAA,GAAA,GAAA;AACLW,oBAAcH,QAAQ,MAAMR,KAAAA,QAAU,OAAA,EAAA;IACxC,OAAA;AACF,oBAAA,QAAA,MAAA,MAAA;IAEA;EACA;;;",
|
|
6
|
+
"names": ["LanguageModel", "Effect", "Schema", "AiService", "Obj", "Message", "Schema", "Filter", "Query", "EID", "EntityId", "ReferencedQuotes", "Struct", "references", "Array", "id", "String", "quote", "pipe", "mutable", "annotations", "description", "findReferences", "nouns", "db", "searchKind", "normalizedNouns", "from", "Set", "map", "noun", "trim", "filter", "length", "sort", "leftNoun", "rightNoun", "Promise", "all", "objects", "query", "select", "text", "type", "run", "toString", "flat", "insertReferences", "quotes", "isValid", "left", "right", "regex", "RegExp", "replace", "replaceOutsideLinks", "make", "entityId", "MARKDOWN_LINK", "replacement", "result", "plainStart", "link", "matchAll", "index", "slice", "EXTRACTION_MODEL", "ProperNouns", "Struct", "properNouns", "Array", "String", "annotations", "description", "extractProperNouns", "text", "gen", "value", "scoped", "generateObject", "schema", "prompt", "join", "map", "noun", "trim", "filter", "length", "pipe", "provide", "AiService", "model", "enrichTranscriptMessage", "message", "db", "blocks", "forEach", "block", "_tag", "nouns", "references", "promise", "findReferences", "insertReferences", "Obj", "make", "Message", "id", "sender", "created", "properties", "pipeline", "log", "_ner", "ner", "entities", "text", "tokenGroups", "createTokenGroups", "combinedEntities", "canBeCombined", "prevToken", "currentToken", "currentState", "prevEntity", "entity", "currentEntity", "prevState", "token", "push", "lastTokenGroup", "score", "reduce", "index", "group", "at", "word", "start", "end", "combinedToken"]
|
|
7
7
|
}
|
|
@@ -947,12 +947,15 @@ var Request = class {
|
|
|
947
947
|
_submitMessage = (message) => Effect5.gen(this, function* () {
|
|
948
948
|
this._pending.push(message);
|
|
949
949
|
yield* this._observer.onMessage(message);
|
|
950
|
+
if (this._options.persist === false) {
|
|
951
|
+
return message;
|
|
952
|
+
}
|
|
950
953
|
for (const block of message.blocks) {
|
|
951
954
|
log3("write complete block", {
|
|
952
955
|
messageId: message.id,
|
|
953
956
|
role: message.sender.role,
|
|
954
957
|
block: JSON.stringify(block)
|
|
955
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L:
|
|
958
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 62, S: this });
|
|
956
959
|
yield* Trace2.write(CompleteBlock, {
|
|
957
960
|
messageId: message.id,
|
|
958
961
|
role: message.sender.role,
|
|
@@ -1014,7 +1017,7 @@ var Request = class {
|
|
|
1014
1017
|
},
|
|
1015
1018
|
pending: this._pending.length,
|
|
1016
1019
|
history: this._history.length
|
|
1017
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L:
|
|
1020
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 119, S: this });
|
|
1018
1021
|
const prompt = yield* AiPreprocessor.preprocessPrompt([
|
|
1019
1022
|
...this._history,
|
|
1020
1023
|
...this._pending
|
|
@@ -1041,7 +1044,7 @@ var Request = class {
|
|
|
1041
1044
|
log3("emit ephemeral message", {
|
|
1042
1045
|
id: currentMessageId,
|
|
1043
1046
|
type: block._tag
|
|
1044
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L:
|
|
1047
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 150, S: this });
|
|
1045
1048
|
yield* Trace2.write(PartialBlock, {
|
|
1046
1049
|
messageId: currentMessageId,
|
|
1047
1050
|
role: "assistant",
|
|
@@ -1055,7 +1058,7 @@ var Request = class {
|
|
|
1055
1058
|
log3("emit complete message", {
|
|
1056
1059
|
id,
|
|
1057
1060
|
type: block._tag
|
|
1058
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L:
|
|
1061
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 164, S: this });
|
|
1059
1062
|
const message = Obj5.make(Message3.Message, {
|
|
1060
1063
|
id,
|
|
1061
1064
|
created: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -1074,7 +1077,7 @@ var Request = class {
|
|
|
1074
1077
|
}), Stream.filterMap((_) => _), Stream.runCollect, Effect5.map(Chunk.toArray));
|
|
1075
1078
|
log3("messages", {
|
|
1076
1079
|
messages
|
|
1077
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L:
|
|
1080
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 184, S: this });
|
|
1078
1081
|
const toolCalls = this.getToolCalls();
|
|
1079
1082
|
if (toolCalls.length === 0) {
|
|
1080
1083
|
this._ended = Date.now();
|
|
@@ -1140,7 +1143,7 @@ var Request = class {
|
|
|
1140
1143
|
pending: this._pending.length,
|
|
1141
1144
|
duration: this.duration,
|
|
1142
1145
|
tools: this._toolCalls
|
|
1143
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L:
|
|
1146
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 247, S: this });
|
|
1144
1147
|
return this._pending;
|
|
1145
1148
|
}).pipe(this._semaphore.withPermits(1), Effect5.withSpan("AiRequest.run"));
|
|
1146
1149
|
};
|
|
@@ -1685,6 +1688,7 @@ var Session = class extends Resource2 {
|
|
|
1685
1688
|
const request = new AiRequest_exports.Request({
|
|
1686
1689
|
summarizationThreshold: SUMMARY_THRESHOLD,
|
|
1687
1690
|
observer: params.observer,
|
|
1691
|
+
persist: params.persist,
|
|
1688
1692
|
onOutput: (message) => Effect9.promise(() => Runtime2.runPromise(this._runtime)(Feed4.append(this._feed, [
|
|
1689
1693
|
message
|
|
1690
1694
|
])))
|
|
@@ -1707,7 +1711,7 @@ var Session = class extends Resource2 {
|
|
|
1707
1711
|
});
|
|
1708
1712
|
log5("toolkit", {
|
|
1709
1713
|
tools: Record2.keys(toolkit.toolkit.tools)
|
|
1710
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L:
|
|
1714
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 120, S: this });
|
|
1711
1715
|
const system = yield* formatSystemPrompt({
|
|
1712
1716
|
system: params.system,
|
|
1713
1717
|
blueprints: currentBlueprints,
|
|
@@ -1728,7 +1732,7 @@ var Session = class extends Resource2 {
|
|
|
1728
1732
|
messages: request.pending.length,
|
|
1729
1733
|
duration: request.duration,
|
|
1730
1734
|
toolCalls: request.toolCalls
|
|
1731
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L:
|
|
1735
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 139, S: this });
|
|
1732
1736
|
return [
|
|
1733
1737
|
...request.pending
|
|
1734
1738
|
];
|
|
@@ -1793,14 +1797,14 @@ var connectMcpServers = (blueprints, spaceMcpServers = []) => {
|
|
|
1793
1797
|
Effect9.tap((toolkit) => log5.info("Connected to MCP server", {
|
|
1794
1798
|
url: options.url,
|
|
1795
1799
|
tools: Object.keys(toolkit.toolkit.tools).length
|
|
1796
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L:
|
|
1800
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 203, S: void 0 })),
|
|
1797
1801
|
// Surface typed connection failures via ephemeral trace + warn log, then drop the server.
|
|
1798
1802
|
Effect9.tapError((error) => Effect9.gen(function* () {
|
|
1799
1803
|
log5.warn("Failed to connect to MCP server", {
|
|
1800
1804
|
url: error.url,
|
|
1801
1805
|
protocol: error.protocol,
|
|
1802
1806
|
message: error.message
|
|
1803
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L:
|
|
1807
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 208, S: this });
|
|
1804
1808
|
yield* Trace3.write(McpServerError, {
|
|
1805
1809
|
url: error.url,
|
|
1806
1810
|
protocol: error.protocol,
|
|
@@ -1814,7 +1818,7 @@ var connectMcpServers = (blueprints, spaceMcpServers = []) => {
|
|
|
1814
1818
|
log5.warn("Unexpected MCP defect", {
|
|
1815
1819
|
url: options.url,
|
|
1816
1820
|
message
|
|
1817
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L:
|
|
1821
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 222, S: this });
|
|
1818
1822
|
yield* Trace3.write(McpServerError, {
|
|
1819
1823
|
url: options.url,
|
|
1820
1824
|
protocol: options.protocol,
|
|
@@ -1834,10 +1838,10 @@ var connectMcpServers = (blueprints, spaceMcpServers = []) => {
|
|
|
1834
1838
|
import defaultsDeep from "lodash.defaultsdeep";
|
|
1835
1839
|
import { Template as Template2 } from "@dxos/compute";
|
|
1836
1840
|
|
|
1837
|
-
// raw-loader:/__w/dxos/dxos/packages/core/compute/assistant/src/templates/instructions/format.tpl
|
|
1841
|
+
// raw-loader:/__w/dxos/dxos/packages/core/compute/assistant/src/templates/instructions/format.tpl
|
|
1838
1842
|
var format_default = "{{! System Core }}\n\n## Input Formats\n\n### Blueprints\n\nYou may be provided with Blueprint definitions that include specific instructions and tools for a given set of tasks.\nBlue print instructions will be enclosed in a <blueprint> tag.\n\n### Context objects\n\nYou may be provided with references to objects that are relevant to the current prompt.\nObjects will be in the form of a <object> tag with a <dxn> element that is the unique key of the object required by many tools.\nThe <typename> element is the type of the object.\n\n<object>\n <dxn>object-id</dxn>\n <typename>example.com/type/TypeName</typename>\n</object>\n\n## Response Formats\n\nIt is very important to respond in the correct format.\nYou response must be valid Markdown.\nIn some cases you should respond with well-formed XML tags along with the content.\nCode snippets should use 2-space indents.\n\n{{#if cot}}\nBefore responding, explain your reasoning and include your detailed chain-of-thought enclosed in a <cot> tag.\nThe <cot> tag should be the first thing in your response.\n{{/if}}\n\n## Block references\n\nYou can reply with a block reference for objects if you have the DXN. For example:\n\n<object>\n <dxn>dxn:queue:data:B6INSIBY3CBEF4M5VZRYBCMAHQMPYK5AJ:01K24XMVHSZHS97SG1VTVQDM5Z:01K24XPK464FSCKVQJAB2H662M</dxn>\n</object>\n<object>\n <dxn>dxn:echo:@:01K24XPK464FSCKVQJAB2H662M</dxn>\n</object>\n\n### Suggestions\n\nEach suggestion must in the form of a proposed action enclosed in a <suggestion> tag.\nExample: <suggestion>Show on a map</suggestion>\nDo not use bullets when listing suggestions.\n\n### Multiple choice questions\n\nYou may ask multiple choice questions by wrapping consise options inside <option> tags inside a well formed <select> tag.\nExample: <select><option>Yes</option><option>No</option></select>\n\n## Context\n\nThe current date and time is {{DATETIME}}.\n";
|
|
1839
1843
|
|
|
1840
|
-
// raw-loader:/__w/dxos/dxos/packages/core/compute/assistant/src/templates/instructions/system.tpl
|
|
1844
|
+
// raw-loader:/__w/dxos/dxos/packages/core/compute/assistant/src/templates/instructions/system.tpl
|
|
1841
1845
|
var system_default = "{{! System Prompt }}\n\n- You are a helpful assistant called Kai. \n- Your name is Kai and you are powered by different language models.\n- You were created by DXOS and operate inside of Composer and on the DXOS EDGE network.\n- In your initial greeting state your name and make some suggestions based on the current context objects.\n- You are an advanced AI assistant capable of creating and managing artifacts from provided data and tools.\n- Your task is to process user commands and questions and decide how best to respond.\n- In general be concise and direct.\n- Follow all instructions carefully.\n\n## Planning\n\n- Analyze the structure and type of the content in the user's message.\n- Determine if you complete the task using the available blueprint definitions?\n- If you can't complete the task using the available blueprint definitions, query the list of available blueprint definitions using the appropriate tool.\n- Identify which blueprint definitions are relevant to the user's request.\n- Evaluate the potential benefits of creating an artifact vs. normal processing for each identified element.\n- Make a final decision on whether to create an artifact and explain your reasoning.\n- Are the required blueprint definitions already available?\n- If not, select which blueprint definition(s) will be the most relevant and require them using the require_artifact_definitions tool.\n- The require'd artifact tools will be available for use after require.\n- If creating an artifact, outline how you will structure it within the response.\n- Decide if the artifact needs to be shown to the user.\n- Call the show tool to show the artifact to the user.\n- Your reasoning must include: whether to use artifacts or not, to create one or query, whether to show the artifact to the user, and how to structure the response.\n\n## Blueprints and Artifacts\n\n- Determine if the interaction involves an artifact. Prefer artifacts for tables, lists, spreadsheets, kanbans, games, images, and other structured data.\n- Determine if the user is explicitly talking about creating a new artifact, or wants to use an existing artifact.\n- If it is ambiguous, query for existing artifacts first and then decide.\n- If you decide to create an artifact, call the associated tool to create the artifact.\n- Artifacts are stored in the database. Tools are used to create and query artifacts.\n- If you are unsure about creating an artifact ask the user for clarification.\n- Artifacts are mutable objects that can change over the course of the conversation.\n- Always re-query the artifact using the tool (like query or inspect) to get the latest state of the artifact before answering the user.\n- You must never generate the id of the artifact; only recall the ids that are already in the history.\n- Artifacts are created by requiring the specific artifact using the require_artifact tool and creating it by calling the associated tool.\n- You can add suggested actions at the end of your response.\n- Suggested actions should be very concise and start with a verb and be phrased as a command to an agent -- not a question to the user.\n- Suggested actions must be in the form of a user instruction that you can follow.\n- Suggested actions could include actions that create artifacts.\n- After creating an artifact use a tool to add it to the chat context.\n\n## Navigation\n\n- When the user asks to open, go to, navigate to, or show a specific document, page, or object, use the navigation tools instead of loading content inline.\n- First, call the Resolve navigation targets tool to find the navigation path for the requested item.\n - Without arguments, it returns available pages that can be navigated to.\n - With a DXN in the query, it resolves that specific object to a navigation path.\n- If you know the object's DXN (e.g. from a database query or context objects), pass it in the query to get the exact navigation path.\n- Then, call the Open tool with the resolved navigation path(s) in the subject array to navigate the user to that item.\n- Do not respond with the document's content when the user asks to open it \u2014 open it in the main content area instead.\n- If multiple targets match, present the options to the user and let them choose which to open.\n\n## Response format\n\n- NEVER output narration text outside `<status>` tags or the final user-facing answer. Any progress update, transition sentence, or \"let me\u2026\" lead-in MUST be wrapped in `<status>...</status>`. Violating this is an error.\n- When updating the user about the progress of the work you are doing, put the update in a <status> XML tag.\n- Only when you need to show the result to the user or ask a question use a text block without status tags.\n- After a `</status>` tag, the next output must be either another `<status>` tag, a tool call, or the final user-facing answer \u2014 never a transition sentence.\n\n<example>\n// reasoning...\n<status>Looking for emails from Depot</status>\n// tool call..\n<status>Found 2 emails from Depot.</status>\n<status>Loading email details</status>\n// tool call\n<status>Located mailbox</status>\nI found **2 emails from Depot**:\n</example>\n\nDo not do (no status tags):\n\n<incorrect_example>\n// reasoning...\n// tool call..\nI found 2 emails from Depot. Let me load their details:\n// tool call\nI found **2 emails from Depot**:\n</incorrect_example>\n\nDo not do (transition sentence after a status tag, before tool calls):\n\n<incorrect_example>\n<status>Doing X</status>\nLet me start by doing X:\n// tool call\n</incorrect_example>\n\n- NEVER write a lead-in sentence before a tool call. Use a `<status>` tag instead.\n- Avoid using plain text to tell the user what you are about to do; instead, use status blocks.\n- WRONG: Let me get...\n- CORRECT: <status>Getting...</status>";
|
|
1842
1846
|
|
|
1843
1847
|
// src/templates/system.ts
|