@axiom-lattice/protocols 4.1.3 → 4.1.4

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/index.mjs CHANGED
@@ -451,6 +451,85 @@ function hasOnlyKeys(value, required, optional) {
451
451
  return required.every((key) => key in value) && keys.every((key) => required.includes(key) || optional.includes(key));
452
452
  }
453
453
 
454
+ // src/AgentWebAppStreamProjection.ts
455
+ function createAgentWebAppStreamProjectionContext(options = {}) {
456
+ return { startedToolIds: /* @__PURE__ */ new Set(), allowInterrupts: options.allowInterrupts ?? true, allowGenUI: options.allowGenUI ?? false };
457
+ }
458
+ function projectAgentWebAppChunk(chunk, context) {
459
+ if (chunk.type === MessageChunkTypes.AI) {
460
+ const events = [];
461
+ const startedToolIds = context?.startedToolIds ?? /* @__PURE__ */ new Set();
462
+ if (typeof chunk.data.content === "string" && chunk.data.content) events.push({ type: "message.delta", text: chunk.data.content });
463
+ if (context?.allowGenUI && Array.isArray(chunk.data.content)) {
464
+ for (const value of chunk.data.content) {
465
+ const block = parseAgentWebAppGenUIBlock(value);
466
+ if (block) events.push({ type: "genui.render", block });
467
+ }
468
+ }
469
+ for (const call of chunk.data.tool_call_chunks ?? []) {
470
+ if (call.id && call.name && !startedToolIds.has(call.id)) {
471
+ startedToolIds.add(call.id);
472
+ events.push({ type: "tool.started", id: call.id, name: call.name });
473
+ }
474
+ }
475
+ for (const call of chunk.data.tool_calls ?? []) {
476
+ if (!startedToolIds.has(call.id)) {
477
+ startedToolIds.add(call.id);
478
+ events.push({ type: "tool.started", id: call.id, name: call.name });
479
+ }
480
+ }
481
+ return events;
482
+ }
483
+ if (chunk.type === MessageChunkTypes.TOOL && chunk.data.tool_call_id) {
484
+ return [{ type: "tool.completed", id: chunk.data.tool_call_id }];
485
+ }
486
+ if (chunk.type === MessageChunkTypes.INTERRUPT) {
487
+ if (context && !context.allowInterrupts) return [{ type: "stream.completed" }];
488
+ const interrupt = publicInterrupt(chunk);
489
+ return interrupt ? [{ type: "interrupt.created", interrupt }, { type: "stream.completed" }] : [{ type: "stream.completed" }];
490
+ }
491
+ if (chunk.type === MessageChunkTypes.MESSAGE_COMPLETED) {
492
+ return [
493
+ { type: "message.completed", messageId: chunk.data.id },
494
+ { type: "stream.completed" }
495
+ ];
496
+ }
497
+ if (chunk.type === MessageChunkTypes.MESSAGE_FAILED) {
498
+ return [
499
+ { type: "error", error: { code: "STREAM_FAILED", message: "Stream failed", retryable: true } },
500
+ { type: "stream.completed" }
501
+ ];
502
+ }
503
+ return [];
504
+ }
505
+ function publicInterrupt(chunk) {
506
+ const value = parseInterruptContent(chunk.data.content);
507
+ if (!value) return void 0;
508
+ const topLevelId = chunk.id;
509
+ const id = typeof topLevelId === "string" ? topLevelId : chunk.data.id;
510
+ if (!id) return void 0;
511
+ return {
512
+ id,
513
+ type: typeof value.type === "string" ? value.type : "input",
514
+ prompt: typeof value.prompt === "string" ? value.prompt : typeof value.message === "string" ? value.message : "Input required",
515
+ ...isRecord2(value.data) ? { data: value.data } : {}
516
+ };
517
+ }
518
+ function parseInterruptContent(content) {
519
+ if (!content) return {};
520
+ if (isRecord2(content)) return content;
521
+ if (typeof content !== "string") return void 0;
522
+ try {
523
+ const parsed = JSON.parse(content);
524
+ return isRecord2(parsed) ? parsed : { prompt: content };
525
+ } catch {
526
+ return { prompt: content };
527
+ }
528
+ }
529
+ function isRecord2(value) {
530
+ return typeof value === "object" && value !== null && !Array.isArray(value);
531
+ }
532
+
454
533
  // src/ExactDataSnapshot.ts
455
534
  function ownDescriptorField(descriptor, key) {
456
535
  const field = Object.getOwnPropertyDescriptor(descriptor, key);
@@ -796,6 +875,7 @@ export {
796
875
  ScheduledTaskStatus,
797
876
  UIComponentType,
798
877
  assertGenericProjectConfig,
878
+ createAgentWebAppStreamProjectionContext,
799
879
  descriptorDataValue,
800
880
  getSubAgentsFromConfig,
801
881
  getToolsFromConfig,
@@ -812,6 +892,7 @@ export {
812
892
  parseQueuedExecutionMode,
813
893
  parseTaskBeliefState,
814
894
  parseTrustedRunContext,
895
+ projectAgentWebAppChunk,
815
896
  replaceTaskBeliefState,
816
897
  requireProjectTaskWorkItemStore,
817
898
  snapshotExactArray,