@theokit/agents 0.27.0 → 0.28.0

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.
@@ -578,37 +578,6 @@ interface SdkMessage {
578
578
  */
579
579
  declare function translateSdkEvent(msg: SdkMessage, runId: string): StreamEvent[];
580
580
 
581
- /**
582
- * M0 (theokit-ai-first) — translate a theokit `AgentStreamEvent` stream into the
583
- * Vercel ai-sdk `UIMessageStream` protocol, TEXT ONLY.
584
- *
585
- * This is a PURE mapping (D1): it consumes the ALREADY-deduped bridge event
586
- * stream (downstream of `mergeDeltaStream`) and yields `UIMessageChunk`s. It
587
- * NEVER calls an LLM and does NOT re-run the agent loop (sdk-runtime.md / G2) —
588
- * `@theokit/sdk` remains the only runtime.
589
- *
590
- * Chunk sequence for a text run:
591
- *
592
- * start → text-start{id} → text-delta{id,delta}* → text-end{id} → finish
593
- *
594
- * Invariants:
595
- * - Exactly one `start` and one `finish` per run.
596
- * - `text-end` is emitted ONLY if a `text-start` was emitted (no orphan close).
597
- * - A single shared `id` (`opts.textId`) for the whole text block — injected for
598
- * deterministic tests (D3).
599
- * - Every emitted chunk carries ONLY the fields required by ai-sdk's
600
- * `uiMessageChunkSchema` (a z.strictObject union — extra keys are rejected).
601
- *
602
- * Error handling (error-handling.md — fail-clear, surface don't swallow, never
603
- * throw past the boundary): an `error` event OR a thrown/aborted underlying
604
- * iterable is SURFACED as an ai-sdk `error` chunk (`{ type: 'error', errorText }`),
605
- * then closes an open text (`text-end`) and terminates with `finish`. The error is
606
- * not re-thrown — the transport still produces a well-formed, terminated stream the
607
- * client can render as a failed turn.
608
- *
609
- * Tool / reasoning / file chunks are intentionally out of scope for M0 (YAGNI);
610
- * non-text events are ignored here and widen the mapping in M1.
611
- */
612
581
  declare function translateToUIMessageStream(events: AsyncIterable<AgentStreamEvent>, opts: {
613
582
  textId: string;
614
583
  }): AsyncGenerator<UIMessageChunk, void, unknown>;
package/dist/bridge.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as AgentExecutionContext, b as AgentManifest, c as AgentManifestEntry, d as AgentManifestTool, e as AgentRoute, f as AgentRouteContext, g as AgentRunInfo, h as AgentStreamEvent, i as AgentWalkResult, j as AgentWarningCode, k as AgentsPluginOptions, l as ApprovalRequiredEvent, m as ArtifactChunkEvent, n as ArtifactStartEvent, B as BudgetExceededError, o as CheckpointSavedEvent, C as CompiledAgentOptions, p as CompiledContextWindow, a as CompiledTool, r as DelegateOptions, s as DelegationError, D as DelegationResult, t as DoneEvent, E as ErrorEvent, F as FileEditEvent, I as IterationEvent, P as PartialToolCallEvent, G as RunStartedEvent, H as SdkMessage, J as Segment, K as StateUpdateEvent, S as StreamEvent, T as TextDeltaEvent, M as ThinkingEvent, N as ToolCallEvent, O as ToolResultEvent, Q as ToolWalkResult, U as ToolboxWalkResult, V as agentsPlugin, W as buildModelSelection, X as compileAgent, Y as compileContextWindow, Z as compileProjectContext, _ as compileSkills, $ as compileTools, a0 as createAgentExecutionContext, a1 as createSdkAgentStream, a2 as createThinkTagExtractor, a3 as delegate, a4 as extractThinkTagStream, a5 as generateAgentManifest, a6 as generateAgentRoutes, a7 as isAgentContext, a8 as isApprovalRequired, a9 as isDone, aa as isError, ab as isPartialToolCall, ac as isTextDelta, ad as isToolCall, ae as isToolResult, ai as projectContextMetadataOnlyKnobs, al as streamAgentResponse, am as translateSdkEvent, an as translateToUIMessageStream, ao as validateUniqueRoutes, ap as walkAgentMetadata } from './bridge-entry-QmUEnkn7.js';
1
+ export { A as AgentExecutionContext, b as AgentManifest, c as AgentManifestEntry, d as AgentManifestTool, e as AgentRoute, f as AgentRouteContext, g as AgentRunInfo, h as AgentStreamEvent, i as AgentWalkResult, j as AgentWarningCode, k as AgentsPluginOptions, l as ApprovalRequiredEvent, m as ArtifactChunkEvent, n as ArtifactStartEvent, B as BudgetExceededError, o as CheckpointSavedEvent, C as CompiledAgentOptions, p as CompiledContextWindow, a as CompiledTool, r as DelegateOptions, s as DelegationError, D as DelegationResult, t as DoneEvent, E as ErrorEvent, F as FileEditEvent, I as IterationEvent, P as PartialToolCallEvent, G as RunStartedEvent, H as SdkMessage, J as Segment, K as StateUpdateEvent, S as StreamEvent, T as TextDeltaEvent, M as ThinkingEvent, N as ToolCallEvent, O as ToolResultEvent, Q as ToolWalkResult, U as ToolboxWalkResult, V as agentsPlugin, W as buildModelSelection, X as compileAgent, Y as compileContextWindow, Z as compileProjectContext, _ as compileSkills, $ as compileTools, a0 as createAgentExecutionContext, a1 as createSdkAgentStream, a2 as createThinkTagExtractor, a3 as delegate, a4 as extractThinkTagStream, a5 as generateAgentManifest, a6 as generateAgentRoutes, a7 as isAgentContext, a8 as isApprovalRequired, a9 as isDone, aa as isError, ab as isPartialToolCall, ac as isTextDelta, ad as isToolCall, ae as isToolResult, ai as projectContextMetadataOnlyKnobs, al as streamAgentResponse, am as translateSdkEvent, an as translateToUIMessageStream, ao as validateUniqueRoutes, ap as walkAgentMetadata } from './bridge-entry-CsUiO2YU.js';
2
2
  import '@theokit/http';
3
3
  import './skills-FcUdNDbn.js';
4
4
  import '@theokit/sdk';
package/dist/bridge.js CHANGED
@@ -30,7 +30,7 @@ import {
30
30
  translateToUIMessageStream,
31
31
  validateUniqueRoutes,
32
32
  walkAgentMetadata
33
- } from "./chunk-QR5PFBYT.js";
33
+ } from "./chunk-DA7HHFL5.js";
34
34
  import "./chunk-GVPUUKKE.js";
35
35
  import "./chunk-7QVYU63E.js";
36
36
  export {
@@ -1167,32 +1167,115 @@ function createSdkAgentStream(compiled, compiledTools, apiKey, overrides = {}) {
1167
1167
  __name(createSdkAgentStream, "createSdkAgentStream");
1168
1168
 
1169
1169
  // src/bridge/ui-message-stream-translator.ts
1170
+ function* closeOpenBlock(state, textId) {
1171
+ if (state.openBlock === "text") {
1172
+ yield {
1173
+ type: "text-end",
1174
+ id: textId
1175
+ };
1176
+ } else if (state.openBlock === "reasoning" && state.reasoningId) {
1177
+ yield {
1178
+ type: "reasoning-end",
1179
+ id: state.reasoningId
1180
+ };
1181
+ }
1182
+ state.openBlock = null;
1183
+ state.reasoningId = null;
1184
+ }
1185
+ __name(closeOpenBlock, "closeOpenBlock");
1186
+ function* emitToolCall(event, seen) {
1187
+ seen.add(event.callId);
1188
+ yield {
1189
+ type: "tool-input-available",
1190
+ toolCallId: event.callId,
1191
+ toolName: event.toolName,
1192
+ input: event.input,
1193
+ dynamic: true
1194
+ };
1195
+ }
1196
+ __name(emitToolCall, "emitToolCall");
1197
+ function* emitToolResult(event, seen) {
1198
+ if (!seen.has(event.callId)) {
1199
+ seen.add(event.callId);
1200
+ yield {
1201
+ type: "tool-input-available",
1202
+ toolCallId: event.callId,
1203
+ toolName: event.toolName,
1204
+ input: {},
1205
+ dynamic: true
1206
+ };
1207
+ }
1208
+ if (event.isError) {
1209
+ yield {
1210
+ type: "tool-output-error",
1211
+ toolCallId: event.callId,
1212
+ errorText: event.output
1213
+ };
1214
+ } else {
1215
+ yield {
1216
+ type: "tool-output-available",
1217
+ toolCallId: event.callId,
1218
+ output: event.output
1219
+ };
1220
+ }
1221
+ }
1222
+ __name(emitToolResult, "emitToolResult");
1170
1223
  async function* translateToUIMessageStream(events, opts) {
1171
1224
  yield {
1172
1225
  type: "start"
1173
1226
  };
1174
- let textOpen = false;
1227
+ const state = {
1228
+ openBlock: null,
1229
+ reasoningId: null
1230
+ };
1231
+ const seenToolCallIds = /* @__PURE__ */ new Set();
1175
1232
  try {
1176
1233
  for await (const event of events) {
1177
1234
  if (event.type === "text_delta") {
1178
- if (!textOpen) {
1235
+ if (state.openBlock !== "text") {
1236
+ yield* closeOpenBlock(state, opts.textId);
1179
1237
  yield {
1180
1238
  type: "text-start",
1181
1239
  id: opts.textId
1182
1240
  };
1183
- textOpen = true;
1241
+ state.openBlock = "text";
1184
1242
  }
1185
1243
  yield {
1186
1244
  type: "text-delta",
1187
1245
  id: opts.textId,
1188
1246
  delta: event.content
1189
1247
  };
1248
+ } else if (event.type === "thinking") {
1249
+ let reasoningId = state.openBlock === "reasoning" ? state.reasoningId : null;
1250
+ if (reasoningId === null) {
1251
+ yield* closeOpenBlock(state, opts.textId);
1252
+ reasoningId = crypto.randomUUID();
1253
+ state.reasoningId = reasoningId;
1254
+ yield {
1255
+ type: "reasoning-start",
1256
+ id: reasoningId
1257
+ };
1258
+ state.openBlock = "reasoning";
1259
+ }
1260
+ yield {
1261
+ type: "reasoning-delta",
1262
+ id: reasoningId,
1263
+ delta: event.content
1264
+ };
1265
+ } else if (event.type === "tool_call") {
1266
+ yield* closeOpenBlock(state, opts.textId);
1267
+ yield* emitToolCall(event, seenToolCallIds);
1268
+ } else if (event.type === "tool_result") {
1269
+ yield* closeOpenBlock(state, opts.textId);
1270
+ yield* emitToolResult(event, seenToolCallIds);
1190
1271
  } else if (event.type === "error") {
1191
1272
  yield {
1192
1273
  type: "error",
1193
1274
  errorText: event.message
1194
1275
  };
1195
1276
  break;
1277
+ } else if (event.type === "done") {
1278
+ break;
1196
1279
  }
1197
1280
  }
1198
1281
  } catch (err) {
@@ -1201,12 +1284,7 @@ async function* translateToUIMessageStream(events, opts) {
1201
1284
  errorText: String(err)
1202
1285
  };
1203
1286
  }
1204
- if (textOpen) {
1205
- yield {
1206
- type: "text-end",
1207
- id: opts.textId
1208
- };
1209
- }
1287
+ yield* closeOpenBlock(state, opts.textId);
1210
1288
  yield {
1211
1289
  type: "finish"
1212
1290
  };
@@ -1951,4 +2029,4 @@ export {
1951
2029
  generateAgentManifest,
1952
2030
  agentsPlugin
1953
2031
  };
1954
- //# sourceMappingURL=chunk-QR5PFBYT.js.map
2032
+ //# sourceMappingURL=chunk-DA7HHFL5.js.map