assistant-cloud 0.2.1 → 0.2.3
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/README.md +24 -8
- package/dist/AssistantCloud.d.ts +16 -19
- package/dist/AssistantCloud.d.ts.map +1 -1
- package/dist/AssistantCloud.js +7 -2
- package/dist/AssistantCloud.js.map +1 -1
- package/dist/AssistantCloudAPI.d.ts +74 -72
- package/dist/AssistantCloudAPI.d.ts.map +1 -1
- package/dist/AssistantCloudAPI.js.map +1 -1
- package/dist/AssistantCloudAuthStrategy.d.ts +29 -32
- package/dist/AssistantCloudAuthStrategy.d.ts.map +1 -1
- package/dist/AssistantCloudAuthTokens.d.ts +7 -9
- package/dist/AssistantCloudAuthTokens.d.ts.map +1 -1
- package/dist/AssistantCloudEvents.d.ts +35 -29
- package/dist/AssistantCloudEvents.d.ts.map +1 -1
- package/dist/AssistantCloudEvents.js +66 -17
- package/dist/AssistantCloudEvents.js.map +1 -1
- package/dist/AssistantCloudFiles.d.ts +27 -29
- package/dist/AssistantCloudFiles.d.ts.map +1 -1
- package/dist/AssistantCloudProjectThreadMessages.d.ts +11 -13
- package/dist/AssistantCloudProjectThreadMessages.d.ts.map +1 -1
- package/dist/AssistantCloudProjectThreads.d.ts +12 -14
- package/dist/AssistantCloudProjectThreads.d.ts.map +1 -1
- package/dist/AssistantCloudProjects.d.ts +4 -7
- package/dist/AssistantCloudProjects.d.ts.map +1 -1
- package/dist/AssistantCloudRuns.d.ts +67 -56
- package/dist/AssistantCloudRuns.d.ts.map +1 -1
- package/dist/AssistantCloudRuns.js +9 -4
- package/dist/AssistantCloudRuns.js.map +1 -1
- package/dist/AssistantCloudScores.d.ts +20 -23
- package/dist/AssistantCloudScores.d.ts.map +1 -1
- package/dist/AssistantCloudThreadMessages.d.ts +41 -38
- package/dist/AssistantCloudThreadMessages.d.ts.map +1 -1
- package/dist/AssistantCloudThreadMessages.js +16 -4
- package/dist/AssistantCloudThreadMessages.js.map +1 -1
- package/dist/AssistantCloudThreads.d.ts +42 -44
- package/dist/AssistantCloudThreads.d.ts.map +1 -1
- package/dist/CloudEngagementReporter.d.ts +56 -58
- package/dist/CloudEngagementReporter.d.ts.map +1 -1
- package/dist/CloudEngagementReporter.js +4 -1
- package/dist/CloudEngagementReporter.js.map +1 -1
- package/dist/CloudMessagePersistence.d.ts +56 -58
- package/dist/CloudMessagePersistence.d.ts.map +1 -1
- package/dist/CloudMessagePersistence.js +3 -0
- package/dist/CloudMessagePersistence.js.map +1 -1
- package/dist/CloudRunReporter.d.ts +10 -13
- package/dist/CloudRunReporter.d.ts.map +1 -1
- package/dist/CloudRunReporter.js +13 -4
- package/dist/CloudRunReporter.js.map +1 -1
- package/dist/FormattedCloudPersistence.d.ts +36 -39
- package/dist/FormattedCloudPersistence.d.ts.map +1 -1
- package/dist/ai-sdk/index.d.ts +14 -17
- package/dist/ai-sdk/index.d.ts.map +1 -1
- package/dist/cloudResponse.d.ts +14 -17
- package/dist/cloudResponse.d.ts.map +1 -1
- package/dist/generateThreadTitle.d.ts +9 -12
- package/dist/generateThreadTitle.d.ts.map +1 -1
- package/dist/index.d.ts +18 -17
- package/dist/index.d.ts.map +1 -0
- package/dist/instrumentMcpSampling.d.ts +36 -39
- package/dist/instrumentMcpSampling.d.ts.map +1 -1
- package/dist/runTelemetry.d.ts +101 -94
- package/dist/runTelemetry.d.ts.map +1 -1
- package/dist/runTelemetry.js +57 -15
- package/dist/runTelemetry.js.map +1 -1
- package/dist/telemetry/index.d.ts +20 -23
- package/dist/telemetry/index.d.ts.map +1 -1
- package/dist/version.d.ts +1 -4
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/package.json +10 -9
- package/src/AssistantCloud.ts +17 -2
- package/src/AssistantCloudAPI.ts +4 -0
- package/src/AssistantCloudEvents.test.ts +157 -0
- package/src/AssistantCloudEvents.ts +82 -20
- package/src/AssistantCloudRuns.ts +35 -5
- package/src/AssistantCloudThreadMessages.test.ts +53 -2
- package/src/AssistantCloudThreadMessages.ts +34 -2
- package/src/BackendTranscriptCopy.test.ts +79 -0
- package/src/CloudEngagementReporter.ts +9 -3
- package/src/CloudMessagePersistence.ts +4 -0
- package/src/CloudRunReporter.ts +16 -4
- package/src/ai-sdk/index.test.ts +2 -2
- package/src/runTelemetry.test.ts +226 -2
- package/src/runTelemetry.ts +121 -17
- package/src/tests/AssistantCloud.test.ts +22 -0
- package/src/tests/AssistantCloudRuns.test.ts +28 -0
- package/src/tests/CloudEngagementReporter.test.ts +45 -0
- package/src/tests/CloudRunReporter.test.ts +49 -2
- package/dist/tests/setup.d.ts +0 -1
- package/dist/tests/setup.js +0 -7
- package/dist/tests/setup.js.map +0 -1
|
@@ -1,65 +1,63 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AssistantCloud } from "./AssistantCloud.js";
|
|
3
|
-
import {
|
|
4
|
-
//#region src/CloudMessagePersistence.d.ts
|
|
1
|
+
import type { ReadonlyJSONObject } from "assistant-stream/utils";
|
|
2
|
+
import type { AssistantCloud } from "./AssistantCloud.js";
|
|
3
|
+
import type { CloudMessage } from "./AssistantCloudThreadMessages.js";
|
|
5
4
|
/**
|
|
6
5
|
* Appends, updates and loads cloud messages while mapping local ids to cloud
|
|
7
6
|
* ids and chaining parent_id. A parent that is still being created is awaited,
|
|
8
7
|
* so concurrent appends land under the right parent.
|
|
9
8
|
*/
|
|
10
|
-
declare class CloudMessagePersistence {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
9
|
+
export declare class CloudMessagePersistence {
|
|
10
|
+
private idMapping;
|
|
11
|
+
private getCloud;
|
|
12
|
+
constructor(cloud: AssistantCloud);
|
|
13
|
+
constructor(getCloud: () => AssistantCloud);
|
|
14
|
+
/**
|
|
15
|
+
* Persist a message to the cloud.
|
|
16
|
+
*
|
|
17
|
+
* @param threadId - Remote thread ID
|
|
18
|
+
* @param messageId - Local message ID (used for tracking)
|
|
19
|
+
* @param parentId - Local parent message ID (or null for first message)
|
|
20
|
+
* @param format - Message format (e.g., "aui/v0", "ai-sdk/v6")
|
|
21
|
+
* @param content - Message content (format-specific)
|
|
22
|
+
*/
|
|
23
|
+
append(threadId: string, messageId: string, parentId: string | null, format: string, content: ReadonlyJSONObject): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Update an already-persisted message in the cloud.
|
|
26
|
+
*/
|
|
27
|
+
update(threadId: string, messageId: string, _format: string, content: ReadonlyJSONObject): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Check if a message has been persisted (or is currently being persisted).
|
|
30
|
+
*/
|
|
31
|
+
isPersisted(messageId: string): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Get the remote ID for a local message ID (resolved).
|
|
34
|
+
* Returns undefined if not persisted.
|
|
35
|
+
*/
|
|
36
|
+
getRemoteId(messageId: string): Promise<string | undefined>;
|
|
37
|
+
getResolvedRemoteId(messageId: string): string | undefined;
|
|
38
|
+
record(localId: string, remoteId: string): void;
|
|
39
|
+
/**
|
|
40
|
+
* Load messages from the cloud and populate the ID mapping.
|
|
41
|
+
*
|
|
42
|
+
* The list endpoint caps a response at 200 rows, so pages are followed by
|
|
43
|
+
* message ID cursor until a short page and concatenated in server order.
|
|
44
|
+
*
|
|
45
|
+
* The ID mapping is populated so that `isPersisted()` returns true for
|
|
46
|
+
* loaded messages, preventing re-persistence of already-stored messages.
|
|
47
|
+
*
|
|
48
|
+
* A loaded ID that an append already maps keeps the remote ID from that append, and falls back to the loaded ID if the append fails.
|
|
49
|
+
*
|
|
50
|
+
* @param threadId - Remote thread ID
|
|
51
|
+
* @param format - Optional format filter
|
|
52
|
+
* @returns Array of cloud messages
|
|
53
|
+
*/
|
|
54
|
+
load(threadId: string, format?: string): Promise<CloudMessage[]>;
|
|
55
|
+
/**
|
|
56
|
+
* Reset the ID mapping (call when switching threads).
|
|
57
|
+
*
|
|
58
|
+
* Pending `load()` and `append()` calls are not cancelled and still settle
|
|
59
|
+
* normally, but their results no longer populate the ID mapping.
|
|
60
|
+
*/
|
|
61
|
+
reset(): void;
|
|
62
62
|
}
|
|
63
|
-
//#endregion
|
|
64
|
-
export { CloudMessagePersistence };
|
|
65
63
|
//# sourceMappingURL=CloudMessagePersistence.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CloudMessagePersistence.d.ts","
|
|
1
|
+
{"version":3,"file":"CloudMessagePersistence.d.ts","sourceRoot":"","sources":["../src/CloudMessagePersistence.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,4BAAyB;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,0CAAuC;AAInE;;;;GAIG;AACH,qBAAa,uBAAuB;IAClC,OAAO,CAAC,SAAS,CAA+C;IAChE,OAAO,CAAC,QAAQ,CAAuB;gBAE3B,KAAK,EAAE,cAAc;gBACrB,QAAQ,EAAE,MAAM,cAAc;IAK1C;;;;;;;;OAQG;IACG,MAAM,CACV,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GAAG,IAAI,EACvB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,IAAI,CAAC;IAmChB;;OAEG;IACG,MAAM,CACV,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,IAAI,CAAC;IAYhB;;OAEG;IACH,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;IAIvC;;;OAGG;IACG,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAMjE,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAK1D,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IAI/C;;;;;;;;;;;;;;OAcG;IACG,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;IA6C5C;;;;;OAKG;IACH,KAAK;CAGN"}
|
|
@@ -77,6 +77,9 @@ var CloudMessagePersistence = class {
|
|
|
77
77
|
const entry = this.idMapping.get(messageId);
|
|
78
78
|
return typeof entry === "string" ? entry : void 0;
|
|
79
79
|
}
|
|
80
|
+
record(localId, remoteId) {
|
|
81
|
+
this.idMapping.set(localId, remoteId);
|
|
82
|
+
}
|
|
80
83
|
/**
|
|
81
84
|
* Load messages from the cloud and populate the ID mapping.
|
|
82
85
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CloudMessagePersistence.js","names":[],"sources":["../src/CloudMessagePersistence.ts"],"sourcesContent":["import type { ReadonlyJSONObject } from \"assistant-stream/utils\";\nimport type { AssistantCloud } from \"./AssistantCloud\";\nimport type { CloudMessage } from \"./AssistantCloudThreadMessages\";\n\nconst CLOUD_MESSAGE_PAGE_SIZE = 200;\n\n/**\n * Appends, updates and loads cloud messages while mapping local ids to cloud\n * ids and chaining parent_id. A parent that is still being created is awaited,\n * so concurrent appends land under the right parent.\n */\nexport class CloudMessagePersistence {\n private idMapping = new Map<string, string | Promise<string>>();\n private getCloud: () => AssistantCloud;\n\n constructor(cloud: AssistantCloud);\n constructor(getCloud: () => AssistantCloud);\n constructor(cloud: AssistantCloud | (() => AssistantCloud)) {\n this.getCloud = typeof cloud === \"function\" ? cloud : () => cloud;\n }\n\n /**\n * Persist a message to the cloud.\n *\n * @param threadId - Remote thread ID\n * @param messageId - Local message ID (used for tracking)\n * @param parentId - Local parent message ID (or null for first message)\n * @param format - Message format (e.g., \"aui/v0\", \"ai-sdk/v6\")\n * @param content - Message content (format-specific)\n */\n async append(\n threadId: string,\n messageId: string,\n parentId: string | null,\n format: string,\n content: ReadonlyJSONObject,\n ): Promise<void> {\n const cloud = this.getCloud();\n const existing = this.idMapping.get(messageId);\n if (existing instanceof Promise) {\n await existing;\n return;\n }\n\n const task = (async () => {\n const parentEntry = parentId ? this.idMapping.get(parentId) : undefined;\n const resolvedParentId = parentId\n ? ((await parentEntry) ?? parentId)\n : null;\n const { message_id } = await cloud.threads.messages.create(threadId, {\n parent_id: resolvedParentId,\n format,\n content,\n });\n return message_id;\n })();\n\n this.idMapping.set(messageId, task);\n try {\n const remoteId = await task;\n if (this.idMapping.get(messageId) === task) {\n this.idMapping.set(messageId, remoteId);\n }\n } catch (err) {\n if (this.idMapping.get(messageId) === task) {\n this.idMapping.delete(messageId);\n }\n throw err;\n }\n }\n\n /**\n * Update an already-persisted message in the cloud.\n */\n async update(\n threadId: string,\n messageId: string,\n _format: string,\n content: ReadonlyJSONObject,\n ): Promise<void> {\n const cloud = this.getCloud();\n const remoteId = await this.getRemoteId(messageId);\n if (!remoteId) {\n console.warn(\n `Skipping update for message ${messageId}: no remote id is mapped.`,\n );\n return;\n }\n await cloud.threads.messages.update(threadId, remoteId, { content });\n }\n\n /**\n * Check if a message has been persisted (or is currently being persisted).\n */\n isPersisted(messageId: string): boolean {\n return this.idMapping.has(messageId);\n }\n\n /**\n * Get the remote ID for a local message ID (resolved).\n * Returns undefined if not persisted.\n */\n async getRemoteId(messageId: string): Promise<string | undefined> {\n const entry = this.idMapping.get(messageId);\n if (!entry) return undefined;\n return entry;\n }\n\n getResolvedRemoteId(messageId: string): string | undefined {\n const entry = this.idMapping.get(messageId);\n return typeof entry === \"string\" ? entry : undefined;\n }\n\n /**\n * Load messages from the cloud and populate the ID mapping.\n *\n * The list endpoint caps a response at 200 rows, so pages are followed by\n * message ID cursor until a short page and concatenated in server order.\n *\n * The ID mapping is populated so that `isPersisted()` returns true for\n * loaded messages, preventing re-persistence of already-stored messages.\n *\n * A loaded ID that an append already maps keeps the remote ID from that append, and falls back to the loaded ID if the append fails.\n *\n * @param threadId - Remote thread ID\n * @param format - Optional format filter\n * @returns Array of cloud messages\n */\n async load(threadId: string, format?: string) {\n const idMapping = this.idMapping;\n const cloud = this.getCloud();\n const messages: CloudMessage[] = [];\n const seen = new Set<string>();\n let after: string | undefined;\n\n while (true) {\n const page = await cloud.threads.messages.list(threadId, {\n ...(format ? { format } : undefined),\n limit: CLOUD_MESSAGE_PAGE_SIZE,\n ...(after ? { after } : undefined),\n });\n const last = page.messages.at(-1);\n if (!last) break;\n\n // A cursor the server cannot resolve drops the keyset filter and replays\n // an earlier page, so already-seen rows end the walk instead of repeating.\n const fresh = page.messages.filter((m) => !seen.has(m.id));\n if (fresh.length === 0) break;\n for (const m of fresh) seen.add(m.id);\n\n messages.push(...fresh);\n if (page.messages.length < CLOUD_MESSAGE_PAGE_SIZE) break;\n after = last.id;\n }\n\n if (this.idMapping === idMapping) {\n for (const m of messages) {\n const entry = idMapping.get(m.id);\n if (entry === undefined) {\n idMapping.set(m.id, m.id);\n } else if (entry instanceof Promise) {\n void entry.catch(() => {\n const current = idMapping.get(m.id);\n if (current === undefined || current === entry) {\n idMapping.set(m.id, m.id);\n }\n });\n }\n }\n }\n return messages;\n }\n\n /**\n * Reset the ID mapping (call when switching threads).\n *\n * Pending `load()` and `append()` calls are not cancelled and still settle\n * normally, but their results no longer populate the ID mapping.\n */\n reset() {\n this.idMapping = new Map();\n }\n}\n"],"mappings":";AAIA,MAAM,0BAA0B;;;;;;AAOhC,IAAa,0BAAb,MAAqC;CACnC,4BAAoB,IAAI,IAAsC;CAC9D;CAIA,YAAY,OAAgD;EAC1D,KAAK,WAAW,OAAO,UAAU,aAAa,cAAc;CAC9D;;;;;;;;;;CAWA,MAAM,OACJ,UACA,WACA,UACA,QACA,SACe;EACf,MAAM,QAAQ,KAAK,SAAS;EAC5B,MAAM,WAAW,KAAK,UAAU,IAAI,SAAS;EAC7C,IAAI,oBAAoB,SAAS;GAC/B,MAAM;GACN;EACF;EAEA,MAAM,QAAQ,YAAY;GACxB,MAAM,cAAc,WAAW,KAAK,UAAU,IAAI,QAAQ,IAAI,KAAA;GAC9D,MAAM,mBAAmB,WACnB,MAAM,eAAgB,WACxB;GACJ,MAAM,EAAE,eAAe,MAAM,MAAM,QAAQ,SAAS,OAAO,UAAU;IACnE,WAAW;IACX;IACA;GACF,CAAC;GACD,OAAO;EACT,EAAA,CAAG;EAEH,KAAK,UAAU,IAAI,WAAW,IAAI;EAClC,IAAI;GACF,MAAM,WAAW,MAAM;GACvB,IAAI,KAAK,UAAU,IAAI,SAAS,MAAM,MACpC,KAAK,UAAU,IAAI,WAAW,QAAQ;EAE1C,SAAS,KAAK;GACZ,IAAI,KAAK,UAAU,IAAI,SAAS,MAAM,MACpC,KAAK,UAAU,OAAO,SAAS;GAEjC,MAAM;EACR;CACF;;;;CAKA,MAAM,OACJ,UACA,WACA,SACA,SACe;EACf,MAAM,QAAQ,KAAK,SAAS;EAC5B,MAAM,WAAW,MAAM,KAAK,YAAY,SAAS;EACjD,IAAI,CAAC,UAAU;GACb,QAAQ,KACN,+BAA+B,UAAU,0BAC3C;GACA;EACF;EACA,MAAM,MAAM,QAAQ,SA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B,MAAW,YAAY;IACrB,MAAM,UAAU,UAAU,IAAI,EAAE,EAAE;IAClC,IAAI,YAAY,KAAA,KAAa,YAAY,OACvC,UAAU,IAAI,EAAE,IAAI,EAAE,EAAE;GAE5B,CAAC;EAEL;EAEF,OAAO;CACT;;;;;;;CAQA,QAAQ;EACN,KAAK,4BAAY,IAAI,IAAI;CAC3B;AACF"}
|
|
1
|
+
{"version":3,"file":"CloudMessagePersistence.js","names":[],"sources":["../src/CloudMessagePersistence.ts"],"sourcesContent":["import type { ReadonlyJSONObject } from \"assistant-stream/utils\";\nimport type { AssistantCloud } from \"./AssistantCloud\";\nimport type { CloudMessage } from \"./AssistantCloudThreadMessages\";\n\nconst CLOUD_MESSAGE_PAGE_SIZE = 200;\n\n/**\n * Appends, updates and loads cloud messages while mapping local ids to cloud\n * ids and chaining parent_id. A parent that is still being created is awaited,\n * so concurrent appends land under the right parent.\n */\nexport class CloudMessagePersistence {\n private idMapping = new Map<string, string | Promise<string>>();\n private getCloud: () => AssistantCloud;\n\n constructor(cloud: AssistantCloud);\n constructor(getCloud: () => AssistantCloud);\n constructor(cloud: AssistantCloud | (() => AssistantCloud)) {\n this.getCloud = typeof cloud === \"function\" ? cloud : () => cloud;\n }\n\n /**\n * Persist a message to the cloud.\n *\n * @param threadId - Remote thread ID\n * @param messageId - Local message ID (used for tracking)\n * @param parentId - Local parent message ID (or null for first message)\n * @param format - Message format (e.g., \"aui/v0\", \"ai-sdk/v6\")\n * @param content - Message content (format-specific)\n */\n async append(\n threadId: string,\n messageId: string,\n parentId: string | null,\n format: string,\n content: ReadonlyJSONObject,\n ): Promise<void> {\n const cloud = this.getCloud();\n const existing = this.idMapping.get(messageId);\n if (existing instanceof Promise) {\n await existing;\n return;\n }\n\n const task = (async () => {\n const parentEntry = parentId ? this.idMapping.get(parentId) : undefined;\n const resolvedParentId = parentId\n ? ((await parentEntry) ?? parentId)\n : null;\n const { message_id } = await cloud.threads.messages.create(threadId, {\n parent_id: resolvedParentId,\n format,\n content,\n });\n return message_id;\n })();\n\n this.idMapping.set(messageId, task);\n try {\n const remoteId = await task;\n if (this.idMapping.get(messageId) === task) {\n this.idMapping.set(messageId, remoteId);\n }\n } catch (err) {\n if (this.idMapping.get(messageId) === task) {\n this.idMapping.delete(messageId);\n }\n throw err;\n }\n }\n\n /**\n * Update an already-persisted message in the cloud.\n */\n async update(\n threadId: string,\n messageId: string,\n _format: string,\n content: ReadonlyJSONObject,\n ): Promise<void> {\n const cloud = this.getCloud();\n const remoteId = await this.getRemoteId(messageId);\n if (!remoteId) {\n console.warn(\n `Skipping update for message ${messageId}: no remote id is mapped.`,\n );\n return;\n }\n await cloud.threads.messages.update(threadId, remoteId, { content });\n }\n\n /**\n * Check if a message has been persisted (or is currently being persisted).\n */\n isPersisted(messageId: string): boolean {\n return this.idMapping.has(messageId);\n }\n\n /**\n * Get the remote ID for a local message ID (resolved).\n * Returns undefined if not persisted.\n */\n async getRemoteId(messageId: string): Promise<string | undefined> {\n const entry = this.idMapping.get(messageId);\n if (!entry) return undefined;\n return entry;\n }\n\n getResolvedRemoteId(messageId: string): string | undefined {\n const entry = this.idMapping.get(messageId);\n return typeof entry === \"string\" ? entry : undefined;\n }\n\n record(localId: string, remoteId: string): void {\n this.idMapping.set(localId, remoteId);\n }\n\n /**\n * Load messages from the cloud and populate the ID mapping.\n *\n * The list endpoint caps a response at 200 rows, so pages are followed by\n * message ID cursor until a short page and concatenated in server order.\n *\n * The ID mapping is populated so that `isPersisted()` returns true for\n * loaded messages, preventing re-persistence of already-stored messages.\n *\n * A loaded ID that an append already maps keeps the remote ID from that append, and falls back to the loaded ID if the append fails.\n *\n * @param threadId - Remote thread ID\n * @param format - Optional format filter\n * @returns Array of cloud messages\n */\n async load(threadId: string, format?: string) {\n const idMapping = this.idMapping;\n const cloud = this.getCloud();\n const messages: CloudMessage[] = [];\n const seen = new Set<string>();\n let after: string | undefined;\n\n while (true) {\n const page = await cloud.threads.messages.list(threadId, {\n ...(format ? { format } : undefined),\n limit: CLOUD_MESSAGE_PAGE_SIZE,\n ...(after ? { after } : undefined),\n });\n const last = page.messages.at(-1);\n if (!last) break;\n\n // A cursor the server cannot resolve drops the keyset filter and replays\n // an earlier page, so already-seen rows end the walk instead of repeating.\n const fresh = page.messages.filter((m) => !seen.has(m.id));\n if (fresh.length === 0) break;\n for (const m of fresh) seen.add(m.id);\n\n messages.push(...fresh);\n if (page.messages.length < CLOUD_MESSAGE_PAGE_SIZE) break;\n after = last.id;\n }\n\n if (this.idMapping === idMapping) {\n for (const m of messages) {\n const entry = idMapping.get(m.id);\n if (entry === undefined) {\n idMapping.set(m.id, m.id);\n } else if (entry instanceof Promise) {\n void entry.catch(() => {\n const current = idMapping.get(m.id);\n if (current === undefined || current === entry) {\n idMapping.set(m.id, m.id);\n }\n });\n }\n }\n }\n return messages;\n }\n\n /**\n * Reset the ID mapping (call when switching threads).\n *\n * Pending `load()` and `append()` calls are not cancelled and still settle\n * normally, but their results no longer populate the ID mapping.\n */\n reset() {\n this.idMapping = new Map();\n }\n}\n"],"mappings":";AAIA,MAAM,0BAA0B;;;;;;AAOhC,IAAa,0BAAb,MAAqC;CACnC,4BAAoB,IAAI,IAAsC;CAC9D;CAIA,YAAY,OAAgD;EAC1D,KAAK,WAAW,OAAO,UAAU,aAAa,cAAc;CAC9D;;;;;;;;;;CAWA,MAAM,OACJ,UACA,WACA,UACA,QACA,SACe;EACf,MAAM,QAAQ,KAAK,SAAS;EAC5B,MAAM,WAAW,KAAK,UAAU,IAAI,SAAS;EAC7C,IAAI,oBAAoB,SAAS;GAC/B,MAAM;GACN;EACF;EAEA,MAAM,QAAQ,YAAY;GACxB,MAAM,cAAc,WAAW,KAAK,UAAU,IAAI,QAAQ,IAAI,KAAA;GAC9D,MAAM,mBAAmB,WACnB,MAAM,eAAgB,WACxB;GACJ,MAAM,EAAE,eAAe,MAAM,MAAM,QAAQ,SAAS,OAAO,UAAU;IACnE,WAAW;IACX;IACA;GACF,CAAC;GACD,OAAO;EACT,E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AI,QAAQ,EAAE,MAAM,IAAI,KAAA;GAC1B,CAAC;GACD,MAAM,OAAO,KAAK,SAAS,GAAG,EAAE;GAChC,IAAI,CAAC,MAAM;GAIX,MAAM,QAAQ,KAAK,SAAS,QAAQ,MAAM,CAAC,KAAK,IAAI,EAAE,EAAE,CAAC;GACzD,IAAI,MAAM,WAAW,GAAG;GACxB,KAAK,MAAM,KAAK,OAAO,KAAK,IAAI,EAAE,EAAE;GAEpC,SAAS,KAAK,GAAG,KAAK;GACtB,IAAI,KAAK,SAAS,SAAS,yBAAyB;GACpD,QAAQ,KAAK;EACf;EAEA,IAAI,KAAK,cAAc,WACrB,KAAK,MAAM,KAAK,UAAU;GACxB,MAAM,QAAQ,UAAU,IAAI,EAAE,EAAE;GAChC,IAAI,UAAU,KAAA,GACZ,UAAU,IAAI,EAAE,IAAI,EAAE,EAAE;QACnB,IAAI,iBAAiB,SAC1B,MAAW,YAAY;IACrB,MAAM,UAAU,UAAU,IAAI,EAAE,EAAE;IAClC,IAAI,YAAY,KAAA,KAAa,YAAY,OACvC,UAAU,IAAI,EAAE,IAAI,EAAE,EAAE;GAE5B,CAAC;EAEL;EAEF,OAAO;CACT;;;;;;;CAQA,QAAQ;EACN,KAAK,4BAAY,IAAI,IAAI;CAC3B;AACF"}
|
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
type CloudRunReportInit = Omit<RunReportInit, "telemetry">;
|
|
1
|
+
import type { AssistantCloud } from "./AssistantCloud.js";
|
|
2
|
+
import { type RunReportInit } from "./runTelemetry.js";
|
|
3
|
+
export type CloudRunReportInit = Omit<RunReportInit, "telemetry">;
|
|
5
4
|
/**
|
|
6
5
|
* Sends run reports the way every client integration has to: nothing while
|
|
7
6
|
* telemetry is off, the cloud's environment, release and tags on every report,
|
|
8
7
|
* the `beforeReport` hook applied last, and a failed send that never surfaces.
|
|
9
|
-
* A report
|
|
10
|
-
* the
|
|
8
|
+
* A keyed report is deduplicated while in flight and after an attempt. A
|
|
9
|
+
* rate-limited attempt releases the key so a later observation can try again.
|
|
11
10
|
*/
|
|
12
|
-
declare class CloudRunReporter {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
export declare class CloudRunReporter {
|
|
12
|
+
private readonly reported;
|
|
13
|
+
private readonly getCloud;
|
|
14
|
+
constructor(cloud: AssistantCloud | (() => AssistantCloud));
|
|
15
|
+
report(init: CloudRunReportInit, key?: string): Promise<void>;
|
|
17
16
|
}
|
|
18
|
-
//#endregion
|
|
19
|
-
export { CloudRunReportInit, CloudRunReporter };
|
|
20
17
|
//# sourceMappingURL=CloudRunReporter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CloudRunReporter.d.ts","
|
|
1
|
+
{"version":3,"file":"CloudRunReporter.d.ts","sourceRoot":"","sources":["../src/CloudRunReporter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,4BAAyB;AAEvD,OAAO,EAAmB,KAAK,aAAa,EAAE,0BAAuB;AAErE,MAAM,MAAM,kBAAkB,GAAG,IAAI,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;AAElE;;;;;;GAMG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqB;IAC9C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAuB;gBAEpC,KAAK,EAAE,cAAc,GAAG,CAAC,MAAM,cAAc,CAAC;IAI7C,MAAM,CAAC,IAAI,EAAE,kBAAkB,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAwB3E"}
|
package/dist/CloudRunReporter.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import { CloudAPIError } from "./AssistantCloudAPI.js";
|
|
1
2
|
import { createRunReport } from "./runTelemetry.js";
|
|
2
3
|
//#region src/CloudRunReporter.ts
|
|
3
4
|
/**
|
|
4
5
|
* Sends run reports the way every client integration has to: nothing while
|
|
5
6
|
* telemetry is off, the cloud's environment, release and tags on every report,
|
|
6
7
|
* the `beforeReport` hook applied last, and a failed send that never surfaces.
|
|
7
|
-
* A report
|
|
8
|
-
* the
|
|
8
|
+
* A keyed report is deduplicated while in flight and after an attempt. A
|
|
9
|
+
* rate-limited attempt releases the key so a later observation can try again.
|
|
9
10
|
*/
|
|
10
11
|
var CloudRunReporter = class {
|
|
11
12
|
reported = /* @__PURE__ */ new Set();
|
|
@@ -14,6 +15,7 @@ var CloudRunReporter = class {
|
|
|
14
15
|
this.getCloud = typeof cloud === "function" ? cloud : () => cloud;
|
|
15
16
|
}
|
|
16
17
|
async report(init, key) {
|
|
18
|
+
let claimedKey;
|
|
17
19
|
try {
|
|
18
20
|
const cloud = this.getCloud();
|
|
19
21
|
if (!cloud.telemetry.enabled) return;
|
|
@@ -25,13 +27,20 @@ var CloudRunReporter = class {
|
|
|
25
27
|
const { beforeReport } = cloud.telemetry;
|
|
26
28
|
const report = beforeReport ? beforeReport(initial) : initial;
|
|
27
29
|
if (!report) return;
|
|
28
|
-
if (key !== void 0)
|
|
30
|
+
if (key !== void 0) {
|
|
31
|
+
this.reported.add(key);
|
|
32
|
+
claimedKey = key;
|
|
33
|
+
}
|
|
29
34
|
await cloud.runs.report(report);
|
|
30
|
-
} catch {
|
|
35
|
+
} catch (error) {
|
|
36
|
+
if (claimedKey !== void 0 && isRetryableReportError(error)) this.reported.delete(claimedKey);
|
|
31
37
|
return;
|
|
32
38
|
}
|
|
33
39
|
}
|
|
34
40
|
};
|
|
41
|
+
const isRetryableReportError = (error) => {
|
|
42
|
+
return error instanceof CloudAPIError && error.status === 429;
|
|
43
|
+
};
|
|
35
44
|
//#endregion
|
|
36
45
|
export { CloudRunReporter };
|
|
37
46
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CloudRunReporter.js","names":[],"sources":["../src/CloudRunReporter.ts"],"sourcesContent":["import type { AssistantCloud } from \"./AssistantCloud\";\nimport { createRunReport, type RunReportInit } from \"./runTelemetry\";\n\nexport type CloudRunReportInit = Omit<RunReportInit, \"telemetry\">;\n\n/**\n * Sends run reports the way every client integration has to: nothing while\n * telemetry is off, the cloud's environment, release and tags on every report,\n * the `beforeReport` hook applied last, and a failed send that never surfaces.\n * A report
|
|
1
|
+
{"version":3,"file":"CloudRunReporter.js","names":[],"sources":["../src/CloudRunReporter.ts"],"sourcesContent":["import type { AssistantCloud } from \"./AssistantCloud\";\nimport { CloudAPIError } from \"./AssistantCloudAPI\";\nimport { createRunReport, type RunReportInit } from \"./runTelemetry\";\n\nexport type CloudRunReportInit = Omit<RunReportInit, \"telemetry\">;\n\n/**\n * Sends run reports the way every client integration has to: nothing while\n * telemetry is off, the cloud's environment, release and tags on every report,\n * the `beforeReport` hook applied last, and a failed send that never surfaces.\n * A keyed report is deduplicated while in flight and after an attempt. A\n * rate-limited attempt releases the key so a later observation can try again.\n */\nexport class CloudRunReporter {\n private readonly reported = new Set<string>();\n private readonly getCloud: () => AssistantCloud;\n\n constructor(cloud: AssistantCloud | (() => AssistantCloud)) {\n this.getCloud = typeof cloud === \"function\" ? cloud : () => cloud;\n }\n\n public async report(init: CloudRunReportInit, key?: string): Promise<void> {\n let claimedKey: string | undefined;\n try {\n const cloud = this.getCloud();\n if (!cloud.telemetry.enabled) return;\n if (key !== undefined && this.reported.has(key)) return;\n\n const initial = createRunReport({ ...init, telemetry: cloud.telemetry });\n const { beforeReport } = cloud.telemetry;\n const report = beforeReport ? beforeReport(initial) : initial;\n if (!report) return;\n\n if (key !== undefined) {\n this.reported.add(key);\n claimedKey = key;\n }\n await cloud.runs.report(report);\n } catch (error) {\n if (claimedKey !== undefined && isRetryableReportError(error)) {\n this.reported.delete(claimedKey);\n }\n return;\n }\n }\n}\n\nconst isRetryableReportError = (error: unknown): boolean => {\n return error instanceof CloudAPIError && error.status === 429;\n};\n"],"mappings":";;;;;;;;;;AAaA,IAAa,mBAAb,MAA8B;CAC5B,2BAA4B,IAAI,IAAY;CAC5C;CAEA,YAAY,OAAgD;EAC1D,KAAK,WAAW,OAAO,UAAU,aAAa,cAAc;CAC9D;CAEA,MAAa,OAAO,MAA0B,KAA6B;EACzE,IAAI;EACJ,IAAI;GACF,MAAM,QAAQ,KAAK,SAAS;GAC5B,IAAI,CAAC,MAAM,UAAU,SAAS;GAC9B,IAAI,QAAQ,KAAA,KAAa,KAAK,SAAS,IAAI,GAAG,GAAG;GAEjD,MAAM,UAAU,gBAAgB;IAAE,GAAG;IAAM,WAAW,MAAM;GAAU,CAAC;GACvE,MAAM,EAAE,iBAAiB,MAAM;GAC/B,MAAM,SAAS,eAAe,aAAa,OAAO,IAAI;GACtD,IAAI,CAAC,QAAQ;GAEb,IAAI,QAAQ,KAAA,GAAW;IACrB,KAAK,SAAS,IAAI,GAAG;IACrB,aAAa;GACf;GACA,MAAM,MAAM,KAAK,OAAO,MAAM;EAChC,SAAS,OAAO;GACd,IAAI,eAAe,KAAA,KAAa,uBAAuB,KAAK,GAC1D,KAAK,SAAS,OAAO,UAAU;GAEjC;EACF;CACF;AACF;AAEA,MAAM,0BAA0B,UAA4B;CAC1D,OAAO,iBAAiB,iBAAiB,MAAM,WAAW;AAC5D"}
|
|
@@ -1,54 +1,51 @@
|
|
|
1
|
-
import { ReadonlyJSONObject } from "assistant-stream/utils";
|
|
2
|
-
//#region src/FormattedCloudPersistence.d.ts
|
|
1
|
+
import type { ReadonlyJSONObject } from "assistant-stream/utils";
|
|
3
2
|
/**
|
|
4
3
|
* Format adapter shape — structurally identical to the MessageFormatAdapter
|
|
5
4
|
* in @assistant-ui/react, but defined here to avoid cross-package type moves.
|
|
6
5
|
* TypeScript's structural typing ensures these are interchangeable.
|
|
7
6
|
*/
|
|
8
|
-
type MessageFormatAdapter<TMessage, TStorageFormat> = {
|
|
9
|
-
format: string;
|
|
10
|
-
encode(item: {
|
|
11
|
-
parentId: string | null;
|
|
12
|
-
message: TMessage;
|
|
13
|
-
}): TStorageFormat;
|
|
14
|
-
decode(stored: {
|
|
15
|
-
id: string;
|
|
16
|
-
parent_id: string | null;
|
|
7
|
+
export type MessageFormatAdapter<TMessage, TStorageFormat> = {
|
|
17
8
|
format: string;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
9
|
+
encode(item: {
|
|
10
|
+
parentId: string | null;
|
|
11
|
+
message: TMessage;
|
|
12
|
+
}): TStorageFormat;
|
|
13
|
+
decode(stored: {
|
|
14
|
+
id: string;
|
|
15
|
+
parent_id: string | null;
|
|
16
|
+
format: string;
|
|
17
|
+
content: TStorageFormat;
|
|
18
|
+
}): {
|
|
19
|
+
parentId: string | null;
|
|
20
|
+
message: TMessage;
|
|
21
|
+
};
|
|
22
|
+
getId(message: TMessage): string;
|
|
24
23
|
};
|
|
25
24
|
/**
|
|
26
25
|
* Wraps a CloudMessagePersistence with a MessageFormatAdapter's encode and
|
|
27
26
|
* decode. The persistence parameter is typed structurally, so a caller does
|
|
28
27
|
* not need to import the class.
|
|
29
28
|
*/
|
|
30
|
-
declare const createFormattedPersistence: <TMessage, TStorageFormat>(persistence: {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
export declare const createFormattedPersistence: <TMessage, TStorageFormat>(persistence: {
|
|
30
|
+
append: (threadId: string, messageId: string, parentId: string | null, format: string, content: ReadonlyJSONObject) => Promise<void>;
|
|
31
|
+
load: (threadId: string, format?: string) => Promise<any[]>;
|
|
32
|
+
isPersisted: (messageId: string) => boolean;
|
|
33
|
+
update?: (threadId: string, messageId: string, format: string, content: ReadonlyJSONObject) => Promise<void>;
|
|
35
34
|
}, adapter: MessageFormatAdapter<TMessage, TStorageFormat>) => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
35
|
+
append: (threadId: string, item: {
|
|
36
|
+
parentId: string | null;
|
|
37
|
+
message: TMessage;
|
|
38
|
+
}) => Promise<void>;
|
|
39
|
+
update: ((threadId: string, item: {
|
|
40
|
+
parentId: string | null;
|
|
41
|
+
message: TMessage;
|
|
42
|
+
}, messageId: string) => Promise<void>) | undefined;
|
|
43
|
+
load: (threadId: string) => Promise<{
|
|
44
|
+
messages: {
|
|
45
|
+
parentId: string | null;
|
|
46
|
+
message: TMessage;
|
|
47
|
+
}[];
|
|
48
|
+
}>;
|
|
49
|
+
isPersisted: (messageId: string) => boolean;
|
|
51
50
|
};
|
|
52
|
-
//#endregion
|
|
53
|
-
export { MessageFormatAdapter, createFormattedPersistence };
|
|
54
51
|
//# sourceMappingURL=FormattedCloudPersistence.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormattedCloudPersistence.d.ts","
|
|
1
|
+
{"version":3,"file":"FormattedCloudPersistence.d.ts","sourceRoot":"","sources":["../src/FormattedCloudPersistence.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAEjE;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,CAAC,QAAQ,EAAE,cAAc,IAAI;IAC3D,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,IAAI,EAAE;QAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,OAAO,EAAE,QAAQ,CAAA;KAAE,GAAG,cAAc,CAAC;IAC7E,MAAM,CAAC,MAAM,EAAE;QACb,EAAE,EAAE,MAAM,CAAC;QACX,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;QACzB,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,cAAc,CAAC;KACzB,GAAG;QAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,OAAO,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|
-
import {
|
|
4
|
-
|
|
5
|
-
type AISDKStorageFormat = Omit<UIMessage, "id">;
|
|
1
|
+
import type { UIMessage } from "ai";
|
|
2
|
+
import type { MessageFormatAdapter } from "../FormattedCloudPersistence.js";
|
|
3
|
+
import { type RunMessageTelemetry } from "../runTelemetry.js";
|
|
4
|
+
export type AISDKStorageFormat = Omit<UIMessage, "id">;
|
|
6
5
|
/** The stored form of an AI SDK message: the message without its id. */
|
|
7
|
-
declare const aiSDKV6FormatAdapter: MessageFormatAdapter<UIMessage, AISDKStorageFormat>;
|
|
6
|
+
export declare const aiSDKV6FormatAdapter: MessageFormatAdapter<UIMessage, AISDKStorageFormat>;
|
|
8
7
|
/**
|
|
9
8
|
* A message as an AI SDK integration holds it, or as the cloud stored it under
|
|
10
9
|
* the ai-sdk/v6 format, which drops the id. Parts are typed by their `type`
|
|
11
10
|
* alone, so this shape and the telemetry read from it need nothing from `ai`.
|
|
12
11
|
*/
|
|
13
|
-
type AISDKMessageLike = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
export type AISDKMessageLike = {
|
|
13
|
+
id?: string | undefined;
|
|
14
|
+
role: string;
|
|
15
|
+
parts: readonly {
|
|
16
|
+
type: string;
|
|
17
|
+
[key: string]: unknown;
|
|
18
|
+
}[];
|
|
19
|
+
metadata?: unknown;
|
|
21
20
|
};
|
|
22
21
|
/**
|
|
23
22
|
* Reads the run report fields out of the assistant messages of one run. A run
|
|
@@ -27,7 +26,5 @@ type AISDKMessageLike = {
|
|
|
27
26
|
* produced text or tool calls, as a live finish with reason `tool-calls` does;
|
|
28
27
|
* an integration that observed the finish event overrides it.
|
|
29
28
|
*/
|
|
30
|
-
declare function extractAISDKRunTelemetry(messages: readonly AISDKMessageLike[]): RunMessageTelemetry | null;
|
|
31
|
-
//#endregion
|
|
32
|
-
export { AISDKMessageLike, AISDKStorageFormat, aiSDKV6FormatAdapter, extractAISDKRunTelemetry };
|
|
29
|
+
export declare function extractAISDKRunTelemetry(messages: readonly AISDKMessageLike[]): RunMessageTelemetry | null;
|
|
33
30
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ai-sdk/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,KAAK,EAAE,oBAAoB,EAAE,wCAAqC;AAEzE,OAAO,EAKL,KAAK,mBAAmB,EAKzB,2BAAwB;AAEzB,MAAM,MAAM,kBAAkB,GAAG,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;AAEvD,wEAAwE;AACxE,eAAO,MAAM,oBAAoB,EAAE,oBAAoB,CACrD,SAAS,EACT,kBAAkB,CASnB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,EAAE,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,SAAS;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,EAAE,CAAC;IAC3D,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAuGF;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,SAAS,gBAAgB,EAAE,GACpC,mBAAmB,GAAG,IAAI,CAmE5B"}
|
package/dist/cloudResponse.d.ts
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
import { ReadonlyJSONObject } from "assistant-stream/utils";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
constructor(message: string);
|
|
1
|
+
import type { ReadonlyJSONObject } from "assistant-stream/utils";
|
|
2
|
+
export declare class CloudResponseError extends Error {
|
|
3
|
+
constructor(message: string);
|
|
5
4
|
}
|
|
6
|
-
declare const readCloudRecord: (value: unknown, field: string) => Record<string, unknown>;
|
|
7
|
-
declare const readCloudArray: (value: unknown, field: string) => unknown[];
|
|
8
|
-
declare const readCloudString: (value: unknown, field: string) => string;
|
|
9
|
-
declare const readCloudNumber: (value: unknown, field: string) => number;
|
|
10
|
-
declare const readCloudNullableNumber: (value: unknown, field: string) => number | null;
|
|
11
|
-
declare const readCloudEnum: <const T extends readonly string[]>(value: unknown, field: string, allowed: T) => T[number];
|
|
12
|
-
declare const readCloudNullableString: (value: unknown, field: string) => string | null;
|
|
13
|
-
declare const readCloudBoolean: (value: unknown, field: string) => boolean;
|
|
14
|
-
declare const readCloudInteger: (value: unknown, field: string) => number;
|
|
15
|
-
declare const readCloudTimestamp: (value: unknown, field: string) => Date;
|
|
16
|
-
declare const readCloudJSONObject: (value: unknown, field: string) => ReadonlyJSONObject;
|
|
17
|
-
//#endregion
|
|
18
|
-
export { CloudResponseError, readCloudArray, readCloudBoolean, readCloudEnum, readCloudInteger, readCloudJSONObject, readCloudNullableNumber, readCloudNullableString, readCloudNumber, readCloudRecord, readCloudString, readCloudTimestamp };
|
|
5
|
+
export declare const readCloudRecord: (value: unknown, field: string) => Record<string, unknown>;
|
|
6
|
+
export declare const readCloudArray: (value: unknown, field: string) => unknown[];
|
|
7
|
+
export declare const readCloudString: (value: unknown, field: string) => string;
|
|
8
|
+
export declare const readCloudNumber: (value: unknown, field: string) => number;
|
|
9
|
+
export declare const readCloudNullableNumber: (value: unknown, field: string) => number | null;
|
|
10
|
+
export declare const readCloudEnum: <const T extends readonly string[]>(value: unknown, field: string, allowed: T) => T[number];
|
|
11
|
+
export declare const readCloudNullableString: (value: unknown, field: string) => string | null;
|
|
12
|
+
export declare const readCloudBoolean: (value: unknown, field: string) => boolean;
|
|
13
|
+
export declare const readCloudInteger: (value: unknown, field: string) => number;
|
|
14
|
+
export declare const readCloudTimestamp: (value: unknown, field: string) => Date;
|
|
15
|
+
export declare const readCloudJSONObject: (value: unknown, field: string) => ReadonlyJSONObject;
|
|
19
16
|
//# sourceMappingURL=cloudResponse.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cloudResponse.d.ts","
|
|
1
|
+
{"version":3,"file":"cloudResponse.d.ts","sourceRoot":"","sources":["../src/cloudResponse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAEjE,qBAAa,kBAAmB,SAAQ,KAAK;gBAC/B,OAAO,EAAE,MAAM;CAI5B;AAOD,eAAO,MAAM,eAAe,GAC1B,OAAO,OAAO,EACd,OAAO,MAAM,KACZ,MAAM,CAAC,MAAM,EAAE,OAAO,CAKxB,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,OAAO,OAAO,EAAE,OAAO,MAAM,KAAG,OAAO,EAGrE,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,OAAO,OAAO,EAAE,OAAO,MAAM,KAAG,MAG/D,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,OAAO,OAAO,EAAE,OAAO,MAAM,KAAG,MAK/D,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAClC,OAAO,OAAO,EACd,OAAO,MAAM,KACZ,MAAM,GAAG,IAGX,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,KAAK,CAAC,CAAC,SAAS,SAAS,MAAM,EAAE,EAC7D,OAAO,OAAO,EACd,OAAO,MAAM,EACb,SAAS,CAAC,KACT,CAAC,CAAC,MAAM,CASV,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAClC,OAAO,OAAO,EACd,OAAO,MAAM,KACZ,MAAM,GAAG,IAGX,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,OAAO,OAAO,EAAE,OAAO,MAAM,KAAG,OAKhE,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,OAAO,OAAO,EAAE,OAAO,MAAM,KAAG,MAGhE,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,OAAO,OAAO,EAAE,OAAO,MAAM,KAAG,IAYlE,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAC9B,OAAO,OAAO,EACd,OAAO,MAAM,KACZ,kBAAyE,CAAC"}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import { AssistantCloud } from "./AssistantCloud.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import type { AssistantCloud } from "./AssistantCloud.js";
|
|
2
|
+
export declare function generateThreadTitle(cloud: AssistantCloud, options: {
|
|
3
|
+
threadId: string;
|
|
4
|
+
messages: readonly {
|
|
5
|
+
role: string;
|
|
6
|
+
content: readonly {
|
|
7
|
+
type: "text";
|
|
8
|
+
text: string;
|
|
9
|
+
}[];
|
|
10
10
|
}[];
|
|
11
|
-
}[];
|
|
12
11
|
}): Promise<string | null>;
|
|
13
|
-
//#endregion
|
|
14
|
-
export { generateThreadTitle };
|
|
15
12
|
//# sourceMappingURL=generateThreadTitle.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateThreadTitle.d.ts","
|
|
1
|
+
{"version":3,"file":"generateThreadTitle.d.ts","sourceRoot":"","sources":["../src/generateThreadTitle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,4BAAyB;AAEvD,wBAAsB,mBAAmB,CACvC,KAAK,EAAE,cAAc,EACrB,OAAO,EAAE;IACP,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,SAAS;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,SAAS;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,EAAE,CAAC;KACpD,EAAE,CAAC;CACL,GACA,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CA2BxB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export {
|
|
1
|
+
export type { CloudMessage, AssistantCloudThreadMessageFeedbackBody, AssistantCloudThreadMessageFeedbackResponse, } from "./AssistantCloudThreadMessages.js";
|
|
2
|
+
export type { AssistantCloudTelemetryConfig, SdkIdentity, } from "./AssistantCloudAPI.js";
|
|
3
|
+
export { AssistantCloudEvents, type AssistantCloudEvent, type AssistantCloudEventKind, } from "./AssistantCloudEvents.js";
|
|
4
|
+
export { AssistantCloudScores, type AssistantCloudScoreBody, type AssistantCloudScoreResponse, } from "./AssistantCloudScores.js";
|
|
5
|
+
export type { GeneratePresignedDownloadUrlResponse } from "./AssistantCloudFiles.js";
|
|
6
|
+
export { CloudAPIError } from "./AssistantCloudAPI.js";
|
|
7
|
+
export { CloudResponseError } from "./cloudResponse.js";
|
|
8
|
+
export { generateThreadTitle } from "./generateThreadTitle.js";
|
|
9
|
+
export type { AssistantCloudRunReport } from "./AssistantCloudRuns.js";
|
|
10
|
+
export { createRunReport, createRunTelemetryToolCall, deriveRunOutcome, describeRunError, extractRunTelemetryModelId, normalizeRunTelemetryUsage, truncateRunTelemetryText, type AssistantCloudRunReportToolCall, type RunMessageTelemetry, type RunReportInit, type RunReportOutcome, type RunReportStepInit, type RunTelemetryToolCallInit, type RunTelemetryUsage, type RunTelemetryUsageInit, } from "./runTelemetry.js";
|
|
11
|
+
export { AssistantCloud } from "./AssistantCloud.js";
|
|
12
|
+
export { CloudRunReporter, type CloudRunReportInit } from "./CloudRunReporter.js";
|
|
13
|
+
export { CloudEngagementReporter, type EngagementEventIds, type EngagementIdResolver, } from "./CloudEngagementReporter.js";
|
|
14
|
+
export { readAnonymousRefreshToken } from "./AssistantCloudAuthStrategy.js";
|
|
15
|
+
export { CloudMessagePersistence } from "./CloudMessagePersistence.js";
|
|
16
|
+
export { createFormattedPersistence, type MessageFormatAdapter, } from "./FormattedCloudPersistence.js";
|
|
17
|
+
export { wrapSamplingHandler, createSamplingCollector, type SamplingCallData, type McpSamplingHandler, } from "./instrumentMcpSampling.js";
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,YAAY,EACZ,uCAAuC,EACvC,2CAA2C,GAC5C,0CAAuC;AACxC,YAAY,EACV,6BAA6B,EAC7B,WAAW,GACZ,+BAA4B;AAC7B,OAAO,EACL,oBAAoB,EACpB,KAAK,mBAAmB,EACxB,KAAK,uBAAuB,GAC7B,kCAA+B;AAChC,OAAO,EACL,oBAAoB,EACpB,KAAK,uBAAuB,EAC5B,KAAK,2BAA2B,GACjC,kCAA+B;AAChC,YAAY,EAAE,oCAAoC,EAAE,iCAA8B;AAClF,OAAO,EAAE,aAAa,EAAE,+BAA4B;AACpD,OAAO,EAAE,kBAAkB,EAAE,2BAAwB;AACrD,OAAO,EAAE,mBAAmB,EAAE,iCAA8B;AAC5D,YAAY,EAAE,uBAAuB,EAAE,gCAA6B;AACpE,OAAO,EACL,eAAe,EACf,0BAA0B,EAC1B,gBAAgB,EAChB,gBAAgB,EAChB,0BAA0B,EAC1B,0BAA0B,EAC1B,wBAAwB,EACxB,KAAK,+BAA+B,EACpC,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,EAC7B,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,GAC3B,0BAAuB;AACxB,OAAO,EAAE,cAAc,EAAE,4BAAyB;AAClD,OAAO,EAAE,gBAAgB,EAAE,KAAK,k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