@dbx-tools/genie 0.1.40 → 0.1.42
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/src/chat.d.ts +5 -4
- package/dist/src/chat.js +27 -7
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/chat.ts +46 -20
package/dist/src/chat.d.ts
CHANGED
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
* the next turn's `options.conversationId`).
|
|
8
8
|
*
|
|
9
9
|
* Two layers serve two kinds of consumer. The low-level layer
|
|
10
|
-
* yields every poll-observed `GenieMessage`
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
10
|
+
* yields every poll-observed `GenieMessage` (validated against
|
|
11
|
+
* `GenieMessageSchema`, falling back to the raw snapshot on a schema
|
|
12
|
+
* miss) and owns the messy parts - cancellation, conversation
|
|
13
|
+
* seeding, distinct-filtering, and SDK quirks (Waiter stripping);
|
|
14
|
+
* reach for it when you want the raw stream. The high-level layer wraps it
|
|
14
15
|
* and emits semantic, deduplicated `{ type, payload }` events
|
|
15
16
|
* (see {@link GenieChatEvent}), always closing a successful turn
|
|
16
17
|
* with a terminal `result` event carrying the final
|
package/dist/src/chat.js
CHANGED
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
* the next turn's `options.conversationId`).
|
|
8
8
|
*
|
|
9
9
|
* Two layers serve two kinds of consumer. The low-level layer
|
|
10
|
-
* yields every poll-observed `GenieMessage`
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
10
|
+
* yields every poll-observed `GenieMessage` (validated against
|
|
11
|
+
* `GenieMessageSchema`, falling back to the raw snapshot on a schema
|
|
12
|
+
* miss) and owns the messy parts - cancellation, conversation
|
|
13
|
+
* seeding, distinct-filtering, and SDK quirks (Waiter stripping);
|
|
14
|
+
* reach for it when you want the raw stream. The high-level layer wraps it
|
|
14
15
|
* and emits semantic, deduplicated `{ type, payload }` events
|
|
15
16
|
* (see {@link GenieChatEvent}), always closing a successful turn
|
|
16
17
|
* with a terminal `result` event carrying the final
|
|
@@ -21,8 +22,27 @@
|
|
|
21
22
|
* event layer.
|
|
22
23
|
*/
|
|
23
24
|
import { WorkspaceClient } from "@databricks/sdk-experimental";
|
|
24
|
-
import { eventsFromMessage, isTerminalStatus, } from "@dbx-tools/genie-shared";
|
|
25
|
-
import { apiUtils, commonUtils } from "@dbx-tools/shared";
|
|
25
|
+
import { eventsFromMessage, GenieMessageSchema, isTerminalStatus, } from "@dbx-tools/genie-shared";
|
|
26
|
+
import { apiUtils, commonUtils, logUtils } from "@dbx-tools/shared";
|
|
27
|
+
const log = logUtils.logger("genie/chat");
|
|
28
|
+
/**
|
|
29
|
+
* Validate a polled wire snapshot against {@link GenieMessageSchema}
|
|
30
|
+
* and return the schema-normalized message. Genie's wire occasionally
|
|
31
|
+
* ships a shape the (SDK-derived) schema doesn't model exactly - e.g.
|
|
32
|
+
* an early poll that omits the SDK-required `message_id` - so a miss
|
|
33
|
+
* degrades to the raw snapshot rather than throwing, keeping a single
|
|
34
|
+
* odd poll from aborting the whole turn.
|
|
35
|
+
*/
|
|
36
|
+
function validateMessage(raw) {
|
|
37
|
+
const result = GenieMessageSchema.safeParse(raw);
|
|
38
|
+
if (result.success)
|
|
39
|
+
return result.data;
|
|
40
|
+
log.debug("wire-message:schema-miss", {
|
|
41
|
+
message_id: raw.message_id ?? raw.id,
|
|
42
|
+
issues: result.error.issues.length,
|
|
43
|
+
});
|
|
44
|
+
return raw;
|
|
45
|
+
}
|
|
26
46
|
/* ----------------------- low-level: genieChat ----------------------- */
|
|
27
47
|
/**
|
|
28
48
|
* One turn against a Genie space, yielded as a stream of
|
|
@@ -108,7 +128,7 @@ export async function* genieChat(space_id, content, options) {
|
|
|
108
128
|
message_id: messageId,
|
|
109
129
|
}, context);
|
|
110
130
|
};
|
|
111
|
-
yield* commonUtils.poll(pollProducer, {
|
|
131
|
+
yield* commonUtils.poll(async (ctx) => validateMessage(await pollProducer(ctx)), {
|
|
112
132
|
intervalMs: options?.pollIntervalMs ?? 500,
|
|
113
133
|
// Skip yielding identical consecutive snapshots; Genie
|
|
114
134
|
// often returns the exact same payload twice during quiet
|