@effect-uai/ui 0.19.0 → 0.19.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"RunView-nHfJwN8t.d.mts","names":[],"sources":["../src/RunView.ts"],"mappings":";;;;;;cAiCa,YAAU,OAAA;KAQX,oBAAoB,WAAW;cAE9B,cAAY,OAAA;KACb,sBAAsB,aAAa;;cAMzC,WAAS,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAET,cAAY,OAAA;;;;;;cAEZ,YAAU,OAAA;;;;;;cAKV,gBAAc,OAAA;;;;;KAMR,mBAAmB,UAAU;KAC7B,sBAAsB,aAAa;KACnC,oBAAoB,WAAW;KAC/B,wBAAwB,eAAe;;;;;KAMvC,UAAU,UAAU,WAAW,WAAW,yBAAwB,KAC1E,UAAU;WAEG;WACA;WACA,MAAM;WACN,QAAQ;WACR,QAAQ;WACR;WACA,UAAU;WACV,UAAU,QAAQ,aAAa;;KAK3C;WACM;WACA;WACA;WACA,QAAQ;WACR,UAAU;WACV,QAAQ;WACR,SAAS,cAAc;;;KAItB,YAAY,UAAU,WAAW,WACzC,iBACC,2BAA0B,KACvB,UAAU;WAEG;WACA;WACA,MAAM;WACN,QAAQ;WACR,UAAU;WACV,QAAQ;WACR,SAAS,cAAc;;;KAMhC,UAAU,UAAU,WAAW,WAAW,yBAAwB,KAC1E,UAAU;WAEG;WACA;WACA,MAAM;WACN,OAAO;;KAKZ,MAAM,UAAU,WAAW,WACnC,YACA,eACA,aACA,iBACA,UAAU,KACV,YAAY,KACZ,UAAU;;KAGF,KAAK,UAAU,WAAW,0BAA0B;YAChD,eAAe;gBACf,KAAK,aAAa,aAAa;cAElC,QAAM,OAAA;KASP,gBAAgB,OAAO;cAE7B,UAAQ,OAAA;;;;KAKF,QAAQ,UAAU,WAAW;WAC9B,QAAQ;WACR;WACA,QAAQ,cAAc;WACtB,QAAQ;WACR,QAAQ,cAA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,QAAQ;;iBAMvC,QAAQ,UAAU,UAAU,MAAM,QAAQ"}
package/dist/RunView.mjs CHANGED
@@ -15,9 +15,13 @@ import * as Items from "@effect-uai/core/Items";
15
15
  * payloads are the JSON the server sent.
16
16
  */
17
17
  var RunView_exports = /* @__PURE__ */ __exportAll({
18
+ ImageBlock: () => ImageBlock,
18
19
  ObjectStatus: () => ObjectStatus,
20
+ ReasoningBlock: () => ReasoningBlock,
21
+ RefusalBlock: () => RefusalBlock,
19
22
  RunView: () => RunView,
20
23
  Status: () => Status,
24
+ TextBlock: () => TextBlock,
21
25
  ToolStatus: () => ToolStatus,
22
26
  applyToolUpdate: () => applyToolUpdate,
23
27
  contentBlocks: () => contentBlocks,
@@ -447,6 +451,6 @@ function refusal(view) {
447
451
  return parts.length === 0 ? void 0 : parts.join("");
448
452
  }
449
453
  //#endregion
450
- export { ObjectStatus, RunView, Status, ToolStatus, applyToolUpdate, contentBlocks, dataBlock, initial, isBusy, isTerminal, isToolUpdate, objectBlock, refusal, schema, step, RunView_exports as t, text, toolBlock, unnamedObject };
454
+ export { ImageBlock, ObjectStatus, ReasoningBlock, RefusalBlock, RunView, Status, TextBlock, ToolStatus, applyToolUpdate, contentBlocks, dataBlock, initial, isBusy, isTerminal, isToolUpdate, objectBlock, refusal, schema, step, RunView_exports as t, text, toolBlock, unnamedObject };
451
455
 
452
456
  //# sourceMappingURL=RunView.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"RunView.mjs","names":["InterruptSchema","Arr"],"sources":["../src/RunView.ts"],"sourcesContent":["/**\n * The client's view of one server run: plain data folded from envelopes.\n * `initial` + `step` plug into `Stream.scan` (live states) or\n * `Stream.runFold` (final state). `step` is pure, total and idempotent on\n * `seq`, so replaying a stream from any point is safe. A delta replaces only\n * the block it touches; every other block keeps its identity.\n *\n * `P` types the payloads (see `UiContract`): with a contract, a tool block\n * narrows by `name` to its decoded input and output. Without one (`Untyped`),\n * payloads are the JSON the server sent.\n */\nimport * as Items from \"@effect-uai/core/Items\"\nimport { Array as Arr, JsonPatch, Match, Option, Schema } from \"effect\"\nimport {\n type Envelope,\n InputId,\n Interrupt as InterruptSchema,\n type Interrupt,\n type Json,\n type NamedPayload,\n outcome,\n type Outcome,\n type Payloads,\n RunId,\n type RunEvent,\n type ToolPayload,\n type Untyped,\n} from \"./RunEvent.js\"\n\n// ---------------------------------------------------------------------------\n// Data\n// ---------------------------------------------------------------------------\n\nexport const ToolStatus = Schema.Literals([\n \"input-streaming\",\n \"ready\",\n \"awaiting-approval\",\n \"running\",\n \"done\",\n \"failed\",\n])\nexport type ToolStatus = typeof ToolStatus.Type\n\nexport const ObjectStatus = Schema.Literals([\"streaming\", \"done\", \"failed\"])\nexport type ObjectStatus = typeof ObjectStatus.Type\n\n// Settled content reuses core's shapes (plus a block `id`), so a view's text,\n// citations, images and refusals read like the turn's own content blocks.\n\n/** Core's `output_text`; citations attach to the text they cite. */\nconst TextBlock = Schema.Struct({ ...Items.OutputText.fields, id: Schema.String })\n/** Core's `refusal`: the model declined to answer. */\nconst RefusalBlock = Schema.Struct({ ...Items.Refusal.fields, id: Schema.String })\n/** Core's `output_image`; `partialIndex` marks a preview the final image replaces. */\nconst ImageBlock = Schema.Struct({\n ...Items.OutputImage.fields,\n id: Schema.String,\n partialIndex: Schema.optionalKey(Schema.Number),\n})\nconst ReasoningBlock = Schema.Struct({\n type: Schema.Literal(\"reasoning\"),\n id: Schema.String,\n text: Schema.String,\n})\n\nexport type TextBlock = typeof TextBlock.Type\nexport type RefusalBlock = typeof RefusalBlock.Type\nexport type ImageBlock = typeof ImageBlock.Type\nexport type ReasoningBlock = typeof ReasoningBlock.Type\n\n/**\n * A tool call; `id` is the call id. `partial` is the latest intermediate value\n * of a streaming tool; `outcome` is how the call ended (`done` or `failed`).\n */\nexport type ToolBlock<P extends Payloads = Untyped> = P[\"tool\"] extends infer T\n ? T extends ToolPayload\n ? {\n readonly type: \"tool\"\n readonly id: string\n readonly name: T[\"name\"]\n readonly status: ToolStatus\n readonly input?: T[\"input\"]\n readonly argsText?: string\n readonly partial?: T[\"output\"]\n readonly outcome?: Outcome<T[\"output\"], T[\"failure\"]>\n }\n : never\n : never\n\ntype UnnamedObject = {\n readonly type: \"object\"\n readonly id: string\n readonly name?: undefined\n readonly status: ObjectStatus\n readonly partial?: Json\n readonly value?: Json\n readonly issues?: ReadonlyArray<Json>\n}\n\n/** A structured object: `partial` while it streams, the typed `value` once done. */\nexport type ObjectBlock<P extends Payloads = Untyped> =\n | UnnamedObject\n | (P[\"object\"] extends infer T\n ? T extends NamedPayload\n ? {\n readonly type: \"object\"\n readonly id: string\n readonly name: T[\"name\"]\n readonly status: ObjectStatus\n readonly partial?: Json\n readonly value?: T[\"value\"]\n readonly issues?: ReadonlyArray<Json>\n }\n : never\n : never)\n\n/** A persisted app payload; a repeated id replaces it in place. */\nexport type DataBlock<P extends Payloads = Untyped> = P[\"data\"] extends infer T\n ? T extends NamedPayload\n ? {\n readonly type: \"data\"\n readonly id: string\n readonly name: T[\"name\"]\n readonly value: T[\"value\"]\n }\n : never\n : never\n\nexport type Block<P extends Payloads = Untyped> =\n | TextBlock\n | RefusalBlock\n | ImageBlock\n | ReasoningBlock\n | ToolBlock<P>\n | ObjectBlock<P>\n | DataBlock<P>\n\n/** Transient payloads by name; the latest value wins. A contract's names are optional keys. */\nexport type Live<P extends Payloads = Untyped> = string extends P[\"live\"][\"name\"]\n ? { readonly [name: string]: P[\"live\"][\"value\"] }\n : { readonly [T in P[\"live\"] as T[\"name\"]]?: T[\"value\"] }\n\nexport const Status = Schema.Literals([\n \"idle\",\n \"submitted\",\n \"streaming\",\n \"completed\",\n \"interrupted\",\n \"failed\",\n \"stopped\",\n])\nexport type Status = typeof Status.Type\n\nconst RunError = Schema.Struct({\n reason: Schema.String,\n message: Schema.optionalKey(Schema.String),\n})\n\nexport type RunView<P extends Payloads = Untyped> = {\n readonly runId?: RunId\n readonly name?: string\n readonly inputs: ReadonlyArray<InputId>\n readonly status: Status\n readonly blocks: ReadonlyArray<Block<P>>\n readonly interrupts: ReadonlyArray<Interrupt<P>>\n readonly live: Live<P>\n readonly usage?: Items.Usage\n readonly metadata?: P[\"metadata\"]\n readonly error?: typeof RunError.Type\n /** Highest applied `seq`; envelopes at or below it are ignored. */\n readonly lastSeq: number\n /** Index of the current step's first block (for `step-reset`). */\n readonly stepStart: number\n readonly nextBlock: number\n}\n\n// ---------------------------------------------------------------------------\n// Schemas: built from payload codecs, so `UiContract` builds the typed ones\n// ---------------------------------------------------------------------------\n\n/** Block schemas for one tool, object or data name; `UiContract` makes one per name. */\nexport const toolBlock = <\n N extends Schema.Top,\n I extends Schema.Top,\n O extends Schema.Top,\n F extends Schema.Top,\n>(\n name: N,\n input: I,\n output: O,\n failure: F,\n) =>\n Schema.Struct({\n type: Schema.Literal(\"tool\"),\n id: Schema.String,\n name,\n status: ToolStatus,\n input: Schema.optionalKey(input),\n argsText: Schema.optionalKey(Schema.String),\n partial: Schema.optionalKey(output),\n outcome: Schema.optionalKey(outcome(output, failure)),\n })\n\nexport const objectBlock = <N extends Schema.Top, V extends Schema.Top>(name: N, value: V) =>\n Schema.Struct({\n type: Schema.Literal(\"object\"),\n id: Schema.String,\n name,\n status: ObjectStatus,\n partial: Schema.optionalKey(Schema.Json),\n value: Schema.optionalKey(value),\n issues: Schema.optionalKey(Schema.Array(Schema.Json)),\n })\n\nexport const dataBlock = <N extends Schema.Top, V extends Schema.Top>(name: N, value: V) =>\n Schema.Struct({ type: Schema.Literal(\"data\"), id: Schema.String, name, value })\n\n/** Blocks without payloads: the same in every view. */\nexport const contentBlocks = [TextBlock, RefusalBlock, ImageBlock, ReasoningBlock] as const\n\n/** A view's schema from its payload-dependent parts; `block` is the whole block union. */\nexport const schema = <\n B extends Schema.Top,\n I extends Schema.Top,\n L extends Schema.Top,\n M extends Schema.Top,\n>(parts: {\n readonly block: B\n readonly interrupt: I\n readonly live: L\n readonly metadata: M\n}) =>\n Schema.Struct({\n runId: Schema.optionalKey(RunId),\n name: Schema.optionalKey(Schema.String),\n inputs: Schema.Array(InputId),\n status: Status,\n blocks: Schema.Array(parts.block),\n interrupts: Schema.Array(parts.interrupt),\n live: parts.live,\n usage: Schema.optionalKey(Items.Usage),\n metadata: Schema.optionalKey(parts.metadata),\n error: Schema.optionalKey(RunError),\n lastSeq: Schema.Number,\n stepStart: Schema.Number,\n nextBlock: Schema.Number,\n })\n\n/** An object without a name: no contract entry, so its value stays JSON. */\nexport const unnamedObject = Schema.Struct({\n type: Schema.Literal(\"object\"),\n id: Schema.String,\n status: ObjectStatus,\n partial: Schema.optionalKey(Schema.Json),\n value: Schema.optionalKey(Schema.Json),\n issues: Schema.optionalKey(Schema.Array(Schema.Json)),\n})\n\nconst untypedObject = Schema.Union([objectBlock(Schema.String, Schema.Json), unnamedObject])\n\n/** The untyped view's schema: payloads are JSON. */\nexport const RunView = schema({\n block: Schema.Union([\n ...contentBlocks,\n toolBlock(Schema.String, Schema.Json, Schema.Json, Schema.Json),\n untypedObject,\n dataBlock(Schema.String, Schema.Json),\n ]),\n interrupt: InterruptSchema,\n live: Schema.Record(Schema.String, Schema.Json),\n metadata: Schema.Json,\n})\n\n/** An empty view (a contract's `initial` is the typed one). */\nexport const initial: RunView = {\n inputs: [],\n status: \"idle\",\n blocks: [],\n interrupts: [],\n live: {},\n lastSeq: 0,\n stepStart: 0,\n nextBlock: 0,\n}\n\n// ---------------------------------------------------------------------------\n// Fold: written once over `Payloads` (names are strings, payloads `unknown`);\n// the exported signatures carry the caller's `P`.\n// ---------------------------------------------------------------------------\n\ntype View = RunView<Payloads>\ntype AnyBlock = Block<Payloads>\ntype AnyTool = ToolBlock<Payloads>\ntype AnyObject = ObjectBlock<Payloads>\n\nconst replaceAt = (blocks: ReadonlyArray<AnyBlock>, index: number, block: AnyBlock) =>\n blocks.map((b, i) => (i === index ? block : b))\n\nconst push = (v: View, make: (id: string) => AnyBlock): View => ({\n ...v,\n blocks: [...v.blocks, make(`b${v.nextBlock}`)],\n nextBlock: v.nextBlock + 1,\n})\n\nconst appendText = (v: View, kind: \"output_text\" | \"refusal\" | \"reasoning\", text: string): View => {\n const index = v.blocks.length - 1\n const last = v.blocks[index]\n if (last !== undefined && last.type === kind && index >= v.stepStart) {\n return { ...v, blocks: replaceAt(v.blocks, index, { ...last, text: last.text + text }) }\n }\n return push(v, (id) => ({ type: kind, id, text }))\n}\n\n// A citation joins the step's latest text; one that arrives before any text\n// starts an empty text block, which the following text extends.\nconst cite = (v: View, annotation: Items.Annotation): View =>\n Arr.findLastIndex(v.blocks, (b, i) => b.type === \"output_text\" && i >= v.stepStart).pipe(\n Option.flatMap((index) =>\n Option.fromNullishOr(v.blocks[index]).pipe(\n Option.filter((b): b is TextBlock => b.type === \"output_text\"),\n Option.map((b) => ({ index, block: b })),\n ),\n ),\n Option.match({\n onNone: () =>\n push(v, (id) => ({ type: \"output_text\", id, text: \"\", annotations: [annotation] })),\n onSome: ({ index, block }) => ({\n ...v,\n blocks: replaceAt(v.blocks, index, {\n ...block,\n annotations: [...(block.annotations ?? []), annotation],\n }),\n }),\n }),\n )\n\nconst updateTool = (\n v: View,\n callId: string,\n name: string,\n f: (block: AnyTool) => AnyTool,\n): View => {\n const index = v.blocks.findIndex((b) => b.type === \"tool\" && b.id === callId)\n const current = v.blocks[index]\n if (current !== undefined && current.type === \"tool\") {\n return { ...v, blocks: replaceAt(v.blocks, index, f(current)) }\n }\n const created: AnyTool = {\n type: \"tool\",\n id: callId,\n name,\n status: \"input-streaming\",\n }\n return { ...v, blocks: [...v.blocks, f(created)] }\n}\n\nconst updateObject = (v: View, id: string, f: (block: AnyObject) => AnyObject): View => {\n const index = v.blocks.findIndex((b) => b.type === \"object\" && b.id === id)\n const current = v.blocks[index]\n if (current !== undefined && current.type === \"object\") {\n return { ...v, blocks: replaceAt(v.blocks, index, f(current)) }\n }\n return { ...v, blocks: [...v.blocks, f({ type: \"object\", id, status: \"streaming\" })] }\n}\n\nconst applyPatch = Option.liftThrowable(JsonPatch.apply)\n// An unnamed object has no contract entry, so its value stays JSON.\nconst isJson = Schema.is(Schema.Json)\n\n// A bad patch leaves the partial value as is; the next snapshot or `object-done` repairs it.\nconst objectDelta = (\n block: AnyObject,\n e: Extract<RunEvent, { type: \"object-delta\" }>,\n): AnyObject => {\n if (e.value !== undefined) return { ...block, partial: e.value }\n const patch = e.patch\n if (patch === undefined) return block\n return applyPatch(patch, block.partial ?? {}).pipe(\n Option.match({ onNone: () => block, onSome: (partial) => ({ ...block, partial }) }),\n )\n}\n\nconst sum = (a: number | undefined, b: number | undefined): number | undefined =>\n a === undefined && b === undefined ? undefined : (a ?? 0) + (b ?? 0)\n\nconst addUsage = (\n total: Items.Usage | undefined,\n step: Items.Usage | undefined,\n): Items.Usage | undefined => {\n if (step === undefined) return total\n if (total === undefined) return step\n const input = sum(total.input_tokens, step.input_tokens)\n const output = sum(total.output_tokens, step.output_tokens)\n const all = sum(total.total_tokens, step.total_tokens)\n return {\n ...(input !== undefined ? { input_tokens: input } : {}),\n ...(output !== undefined ? { output_tokens: output } : {}),\n ...(all !== undefined ? { total_tokens: all } : {}),\n }\n}\n\nconst withUsage = (v: View, usage: Items.Usage | undefined): View => {\n const total = addUsage(v.usage, usage)\n return total === undefined ? v : { ...v, usage: total }\n}\n\nconst apply = (v: View, event: RunEvent<Payloads>): View =>\n Match.value(event).pipe(\n Match.discriminatorsExhaustive(\"type\")({\n \"run-started\": (e): View => ({\n ...v,\n status: \"streaming\",\n runId: e.runId,\n inputs: e.inputs,\n ...(e.name !== undefined ? { name: e.name } : {}),\n }),\n \"run-completed\": (e): View => ({\n ...v,\n status: \"completed\",\n ...(e.metadata !== undefined ? { metadata: e.metadata } : {}),\n }),\n \"run-interrupted\": (e): View =>\n e.interrupts.reduce<View>(\n (acc, i) =>\n updateTool(acc, i.callId, i.name, (b) => ({\n ...b,\n status: \"awaiting-approval\",\n input: i.input,\n })),\n { ...v, status: \"interrupted\", interrupts: e.interrupts },\n ),\n \"run-failed\": (e): View => ({\n ...v,\n status: \"failed\",\n error: {\n reason: e.reason,\n ...(e.message !== undefined ? { message: e.message } : {}),\n },\n }),\n \"run-stopped\": (): View => ({ ...v, status: \"stopped\" }),\n \"step-started\": (): View => ({ ...v, stepStart: v.blocks.length }),\n \"step-finished\": (e): View => withUsage(v, e.usage),\n \"step-reset\": (): View => ({ ...v, blocks: v.blocks.slice(0, v.stepStart) }),\n \"text-delta\": (e) => appendText(v, \"output_text\", e.text),\n \"refusal-delta\": (e) => appendText(v, \"refusal\", e.text),\n \"reasoning-started\": (): View =>\n v.blocks.some((b, i) => b.type === \"reasoning\" && i >= v.stepStart)\n ? v\n : push(v, (id) => ({ type: \"reasoning\", id, text: \"\" })),\n \"reasoning-delta\": (e) => appendText(v, \"reasoning\", e.text),\n citation: (e) => cite(v, e.annotation),\n image: (e): View => {\n const index = v.blocks.length - 1\n const last = v.blocks[index]\n const block = (id: string): AnyBlock =>\n e.partialIndex === undefined\n ? { type: \"output_image\", id, source: e.image }\n : { type: \"output_image\", id, source: e.image, partialIndex: e.partialIndex }\n // A preview frame is replaced by the next preview or the final image.\n return last !== undefined && last.type === \"output_image\" && last.partialIndex !== undefined\n ? { ...v, blocks: replaceAt(v.blocks, index, block(last.id)) }\n : push(v, block)\n },\n \"object-started\": (e): View =>\n updateObject(v, e.id, (b) => (e.name === undefined ? b : { ...b, name: e.name })),\n \"object-delta\": (e) => updateObject(v, e.id, (b) => objectDelta(b, e)),\n \"object-done\": (e) =>\n updateObject(v, e.id, (b) =>\n b.name === undefined\n ? { ...b, status: \"done\", ...(isJson(e.value) ? { value: e.value } : {}) }\n : { ...b, status: \"done\", value: e.value },\n ),\n \"object-failed\": (e) =>\n updateObject(v, e.id, (b) => ({ ...b, status: \"failed\", issues: e.issues })),\n \"tool-call-started\": (e) => updateTool(v, e.callId, e.name, (b) => b),\n \"tool-call-args-delta\": (e) =>\n updateTool(v, e.callId, \"\", (b) => ({ ...b, argsText: (b.argsText ?? \"\") + e.delta })),\n \"tool-call-ready\": (e) =>\n updateTool(v, e.callId, e.name, (b) => ({\n ...b,\n name: e.name,\n status: \"ready\",\n input: e.input,\n })),\n \"tool-approval-requested\": (e) =>\n updateTool(v, e.callId, e.name, (b) => ({\n ...b,\n status: \"awaiting-approval\",\n input: e.input,\n })),\n \"tool-partial\": (e) =>\n updateTool(v, e.callId, e.name, (b) => ({ ...b, status: \"running\", partial: e.value })),\n \"tool-result\": (e) =>\n updateTool(v, e.callId, e.name, (b) => ({\n ...b,\n status: e.result._tag === \"Success\" ? \"done\" : \"failed\",\n outcome: e.result,\n })),\n usage: (e): View => ({ ...v, usage: e.usage }),\n data: (e): View => {\n const index =\n e.id === undefined ? -1 : v.blocks.findIndex((b) => b.type === \"data\" && b.id === e.id)\n const existing = v.blocks[index]\n return existing !== undefined\n ? {\n ...v,\n blocks: replaceAt(v.blocks, index, {\n type: \"data\",\n id: existing.id,\n name: e.name,\n value: e.value,\n }),\n }\n : push(v, (id) => ({ type: \"data\", id: e.id ?? id, name: e.name, value: e.value }))\n },\n live: (e): View => ({ ...v, live: { ...v.live, [e.name]: e.value } }),\n // Stream-scoped; a chat fold (`Thread`) shows it, a run view has nothing to add.\n \"input-accepted\": (): View => v,\n }),\n )\n\n/**\n * Fold one envelope into the view. Ignores envelopes already applied\n * (`seq <= lastSeq`) and run-scoped envelopes of a different run.\n */\nexport function step<P extends Payloads = Untyped>(\n view: RunView<P>,\n envelope: Envelope<P>,\n): RunView<P>\nexport function step(view: View, envelope: Envelope<Payloads>): View {\n if (envelope.seq <= view.lastSeq) return view\n const otherRun =\n view.runId !== undefined && envelope.runId !== undefined && envelope.runId !== view.runId\n return { ...(otherRun ? view : apply(view, envelope.event)), lastSeq: envelope.seq }\n}\n\n/** A tool event that can answer a call made in an earlier run (after an approval). */\nexport type ToolUpdate<P extends Payloads = Untyped> = Extract<\n RunEvent<P>,\n { readonly type: \"tool-result\" | \"tool-partial\" }\n>\n\nexport const isToolUpdate = <P extends Payloads>(event: RunEvent<P>): event is ToolUpdate<P> =>\n event.type === \"tool-result\" || event.type === \"tool-partial\"\n\n/**\n * Apply a tool event to the view if it holds that call; `None` if it doesn't.\n * For a run that already ended (an interrupted run whose call was approved\n * later), so `seq` and the run id are not checked.\n */\nexport function applyToolUpdate<P extends Payloads>(\n view: RunView<P>,\n event: ToolUpdate<P>,\n): Option.Option<RunView<P>>\nexport function applyToolUpdate(view: View, event: ToolUpdate<Payloads>): Option.Option<View> {\n const holds = view.blocks.some((b) => b.type === \"tool\" && b.id === event.callId)\n return holds ? Option.some(apply(view, event)) : Option.none()\n}\n\n// ---------------------------------------------------------------------------\n// Selectors\n// ---------------------------------------------------------------------------\n\nconst TERMINAL: ReadonlySet<Status> = new Set([\"completed\", \"interrupted\", \"failed\", \"stopped\"])\n\nexport const isTerminal = <P extends Payloads>(view: RunView<P>): boolean =>\n TERMINAL.has(view.status)\n\nexport const isBusy = <P extends Payloads>(view: RunView<P>): boolean =>\n view.status === \"submitted\" || view.status === \"streaming\"\n\n/** All assistant text of the run, in order (refusals excluded, see `refusal`). */\nexport function text<P extends Payloads>(view: RunView<P>): string\nexport function text(view: View): string {\n return view.blocks.flatMap((b) => (b.type === \"output_text\" ? [b.text] : [])).join(\"\")\n}\n\n/** The refusal text, if the model declined; `undefined` otherwise. */\nexport function refusal<P extends Payloads>(view: RunView<P>): string | undefined\nexport function refusal(view: View): string | undefined {\n const parts = view.blocks.flatMap((b) => (b.type === \"refusal\" ? [b.text] : []))\n return parts.length === 0 ? undefined : parts.join(\"\")\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAa,aAAa,OAAO,SAAS;CACxC;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAGD,MAAa,eAAe,OAAO,SAAS;CAAC;CAAa;CAAQ;AAAQ,CAAC;;AAO3E,MAAM,YAAY,OAAO,OAAO;CAAE,GAAG,MAAM,WAAW;CAAQ,IAAI,OAAO;AAAO,CAAC;;AAEjF,MAAM,eAAe,OAAO,OAAO;C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,EAAE;AACvF;AAIA,SAAgB,QAAQ,MAAgC;CACtD,MAAM,QAAQ,KAAK,OAAO,SAAS,MAAO,EAAE,SAAS,YAAY,CAAC,EAAE,IAAI,IAAI,CAAC,CAAE;CAC/E,OAAO,MAAM,WAAW,IAAI,KAAA,IAAY,MAAM,KAAK,EAAE;AACvD"}
1
+ {"version":3,"file":"RunView.mjs","names":["InterruptSchema","Arr"],"sources":["../src/RunView.ts"],"sourcesContent":["/**\n * The client's view of one server run: plain data folded from envelopes.\n * `initial` + `step` plug into `Stream.scan` (live states) or\n * `Stream.runFold` (final state). `step` is pure, total and idempotent on\n * `seq`, so replaying a stream from any point is safe. A delta replaces only\n * the block it touches; every other block keeps its identity.\n *\n * `P` types the payloads (see `UiContract`): with a contract, a tool block\n * narrows by `name` to its decoded input and output. Without one (`Untyped`),\n * payloads are the JSON the server sent.\n */\nimport * as Items from \"@effect-uai/core/Items\"\nimport { Array as Arr, JsonPatch, Match, Option, Schema } from \"effect\"\nimport {\n type Envelope,\n InputId,\n Interrupt as InterruptSchema,\n type Interrupt,\n type Json,\n type NamedPayload,\n outcome,\n type Outcome,\n type Payloads,\n RunId,\n type RunEvent,\n type ToolPayload,\n type Untyped,\n} from \"./RunEvent.js\"\n\n// ---------------------------------------------------------------------------\n// Data\n// ---------------------------------------------------------------------------\n\nexport const ToolStatus = Schema.Literals([\n \"input-streaming\",\n \"ready\",\n \"awaiting-approval\",\n \"running\",\n \"done\",\n \"failed\",\n])\nexport type ToolStatus = typeof ToolStatus.Type\n\nexport const ObjectStatus = Schema.Literals([\"streaming\", \"done\", \"failed\"])\nexport type ObjectStatus = typeof ObjectStatus.Type\n\n// Settled content reuses core's shapes (plus a block `id`), so a view's text,\n// citations, images and refusals read like the turn's own content blocks.\n\n/** Core's `output_text`; citations attach to the text they cite. */\nexport const TextBlock = Schema.Struct({ ...Items.OutputText.fields, id: Schema.String })\n/** Core's `refusal`: the model declined to answer. */\nexport const RefusalBlock = Schema.Struct({ ...Items.Refusal.fields, id: Schema.String })\n/** Core's `output_image`; `partialIndex` marks a preview the final image replaces. */\nexport const ImageBlock = Schema.Struct({\n ...Items.OutputImage.fields,\n id: Schema.String,\n partialIndex: Schema.optionalKey(Schema.Number),\n})\nexport const ReasoningBlock = Schema.Struct({\n type: Schema.Literal(\"reasoning\"),\n id: Schema.String,\n text: Schema.String,\n})\n\nexport type TextBlock = typeof TextBlock.Type\nexport type RefusalBlock = typeof RefusalBlock.Type\nexport type ImageBlock = typeof ImageBlock.Type\nexport type ReasoningBlock = typeof ReasoningBlock.Type\n\n/**\n * A tool call; `id` is the call id. `partial` is the latest intermediate value\n * of a streaming tool; `outcome` is how the call ended (`done` or `failed`).\n */\nexport type ToolBlock<P extends Payloads = Untyped> = P[\"tool\"] extends infer T\n ? T extends ToolPayload\n ? {\n readonly type: \"tool\"\n readonly id: string\n readonly name: T[\"name\"]\n readonly status: ToolStatus\n readonly input?: T[\"input\"]\n readonly argsText?: string\n readonly partial?: T[\"output\"]\n readonly outcome?: Outcome<T[\"output\"], T[\"failure\"]>\n }\n : never\n : never\n\ntype UnnamedObject = {\n readonly type: \"object\"\n readonly id: string\n readonly name?: undefined\n readonly status: ObjectStatus\n readonly partial?: Json\n readonly value?: Json\n readonly issues?: ReadonlyArray<Json>\n}\n\n/** A structured object: `partial` while it streams, the typed `value` once done. */\nexport type ObjectBlock<P extends Payloads = Untyped> =\n | UnnamedObject\n | (P[\"object\"] extends infer T\n ? T extends NamedPayload\n ? {\n readonly type: \"object\"\n readonly id: string\n readonly name: T[\"name\"]\n readonly status: ObjectStatus\n readonly partial?: Json\n readonly value?: T[\"value\"]\n readonly issues?: ReadonlyArray<Json>\n }\n : never\n : never)\n\n/** A persisted app payload; a repeated id replaces it in place. */\nexport type DataBlock<P extends Payloads = Untyped> = P[\"data\"] extends infer T\n ? T extends NamedPayload\n ? {\n readonly type: \"data\"\n readonly id: string\n readonly name: T[\"name\"]\n readonly value: T[\"value\"]\n }\n : never\n : never\n\nexport type Block<P extends Payloads = Untyped> =\n | TextBlock\n | RefusalBlock\n | ImageBlock\n | ReasoningBlock\n | ToolBlock<P>\n | ObjectBlock<P>\n | DataBlock<P>\n\n/** Transient payloads by name; the latest value wins. A contract's names are optional keys. */\nexport type Live<P extends Payloads = Untyped> = string extends P[\"live\"][\"name\"]\n ? { readonly [name: string]: P[\"live\"][\"value\"] }\n : { readonly [T in P[\"live\"] as T[\"name\"]]?: T[\"value\"] }\n\nexport const Status = Schema.Literals([\n \"idle\",\n \"submitted\",\n \"streaming\",\n \"completed\",\n \"interrupted\",\n \"failed\",\n \"stopped\",\n])\nexport type Status = typeof Status.Type\n\nconst RunError = Schema.Struct({\n reason: Schema.String,\n message: Schema.optionalKey(Schema.String),\n})\n\nexport type RunView<P extends Payloads = Untyped> = {\n readonly runId?: RunId\n readonly name?: string\n readonly inputs: ReadonlyArray<InputId>\n readonly status: Status\n readonly blocks: ReadonlyArray<Block<P>>\n readonly interrupts: ReadonlyArray<Interrupt<P>>\n readonly live: Live<P>\n readonly usage?: Items.Usage\n readonly metadata?: P[\"metadata\"]\n readonly error?: typeof RunError.Type\n /** Highest applied `seq`; envelopes at or below it are ignored. */\n readonly lastSeq: number\n /** Index of the current step's first block (for `step-reset`). */\n readonly stepStart: number\n readonly nextBlock: number\n}\n\n// ---------------------------------------------------------------------------\n// Schemas: built from payload codecs, so `UiContract` builds the typed ones\n// ---------------------------------------------------------------------------\n\n/** Block schemas for one tool, object or data name; `UiContract` makes one per name. */\nexport const toolBlock = <\n N extends Schema.Top,\n I extends Schema.Top,\n O extends Schema.Top,\n F extends Schema.Top,\n>(\n name: N,\n input: I,\n output: O,\n failure: F,\n) =>\n Schema.Struct({\n type: Schema.Literal(\"tool\"),\n id: Schema.String,\n name,\n status: ToolStatus,\n input: Schema.optionalKey(input),\n argsText: Schema.optionalKey(Schema.String),\n partial: Schema.optionalKey(output),\n outcome: Schema.optionalKey(outcome(output, failure)),\n })\n\nexport const objectBlock = <N extends Schema.Top, V extends Schema.Top>(name: N, value: V) =>\n Schema.Struct({\n type: Schema.Literal(\"object\"),\n id: Schema.String,\n name,\n status: ObjectStatus,\n partial: Schema.optionalKey(Schema.Json),\n value: Schema.optionalKey(value),\n issues: Schema.optionalKey(Schema.Array(Schema.Json)),\n })\n\nexport const dataBlock = <N extends Schema.Top, V extends Schema.Top>(name: N, value: V) =>\n Schema.Struct({ type: Schema.Literal(\"data\"), id: Schema.String, name, value })\n\n/** Blocks without payloads: the same in every view. */\nexport const contentBlocks = [TextBlock, RefusalBlock, ImageBlock, ReasoningBlock] as const\n\n/** A view's schema from its payload-dependent parts; `block` is the whole block union. */\nexport const schema = <\n B extends Schema.Top,\n I extends Schema.Top,\n L extends Schema.Top,\n M extends Schema.Top,\n>(parts: {\n readonly block: B\n readonly interrupt: I\n readonly live: L\n readonly metadata: M\n}) =>\n Schema.Struct({\n runId: Schema.optionalKey(RunId),\n name: Schema.optionalKey(Schema.String),\n inputs: Schema.Array(InputId),\n status: Status,\n blocks: Schema.Array(parts.block),\n interrupts: Schema.Array(parts.interrupt),\n live: parts.live,\n usage: Schema.optionalKey(Items.Usage),\n metadata: Schema.optionalKey(parts.metadata),\n error: Schema.optionalKey(RunError),\n lastSeq: Schema.Number,\n stepStart: Schema.Number,\n nextBlock: Schema.Number,\n })\n\n/** An object without a name: no contract entry, so its value stays JSON. */\nexport const unnamedObject = Schema.Struct({\n type: Schema.Literal(\"object\"),\n id: Schema.String,\n status: ObjectStatus,\n partial: Schema.optionalKey(Schema.Json),\n value: Schema.optionalKey(Schema.Json),\n issues: Schema.optionalKey(Schema.Array(Schema.Json)),\n})\n\nconst untypedObject = Schema.Union([objectBlock(Schema.String, Schema.Json), unnamedObject])\n\n/** The untyped view's schema: payloads are JSON. */\nexport const RunView = schema({\n block: Schema.Union([\n ...contentBlocks,\n toolBlock(Schema.String, Schema.Json, Schema.Json, Schema.Json),\n untypedObject,\n dataBlock(Schema.String, Schema.Json),\n ]),\n interrupt: InterruptSchema,\n live: Schema.Record(Schema.String, Schema.Json),\n metadata: Schema.Json,\n})\n\n/** An empty view (a contract's `initial` is the typed one). */\nexport const initial: RunView = {\n inputs: [],\n status: \"idle\",\n blocks: [],\n interrupts: [],\n live: {},\n lastSeq: 0,\n stepStart: 0,\n nextBlock: 0,\n}\n\n// ---------------------------------------------------------------------------\n// Fold: written once over `Payloads` (names are strings, payloads `unknown`);\n// the exported signatures carry the caller's `P`.\n// ---------------------------------------------------------------------------\n\ntype View = RunView<Payloads>\ntype AnyBlock = Block<Payloads>\ntype AnyTool = ToolBlock<Payloads>\ntype AnyObject = ObjectBlock<Payloads>\n\nconst replaceAt = (blocks: ReadonlyArray<AnyBlock>, index: number, block: AnyBlock) =>\n blocks.map((b, i) => (i === index ? block : b))\n\nconst push = (v: View, make: (id: string) => AnyBlock): View => ({\n ...v,\n blocks: [...v.blocks, make(`b${v.nextBlock}`)],\n nextBlock: v.nextBlock + 1,\n})\n\nconst appendText = (v: View, kind: \"output_text\" | \"refusal\" | \"reasoning\", text: string): View => {\n const index = v.blocks.length - 1\n const last = v.blocks[index]\n if (last !== undefined && last.type === kind && index >= v.stepStart) {\n return { ...v, blocks: replaceAt(v.blocks, index, { ...last, text: last.text + text }) }\n }\n return push(v, (id) => ({ type: kind, id, text }))\n}\n\n// A citation joins the step's latest text; one that arrives before any text\n// starts an empty text block, which the following text extends.\nconst cite = (v: View, annotation: Items.Annotation): View =>\n Arr.findLastIndex(v.blocks, (b, i) => b.type === \"output_text\" && i >= v.stepStart).pipe(\n Option.flatMap((index) =>\n Option.fromNullishOr(v.blocks[index]).pipe(\n Option.filter((b): b is TextBlock => b.type === \"output_text\"),\n Option.map((b) => ({ index, block: b })),\n ),\n ),\n Option.match({\n onNone: () =>\n push(v, (id) => ({ type: \"output_text\", id, text: \"\", annotations: [annotation] })),\n onSome: ({ index, block }) => ({\n ...v,\n blocks: replaceAt(v.blocks, index, {\n ...block,\n annotations: [...(block.annotations ?? []), annotation],\n }),\n }),\n }),\n )\n\nconst updateTool = (\n v: View,\n callId: string,\n name: string,\n f: (block: AnyTool) => AnyTool,\n): View => {\n const index = v.blocks.findIndex((b) => b.type === \"tool\" && b.id === callId)\n const current = v.blocks[index]\n if (current !== undefined && current.type === \"tool\") {\n return { ...v, blocks: replaceAt(v.blocks, index, f(current)) }\n }\n const created: AnyTool = {\n type: \"tool\",\n id: callId,\n name,\n status: \"input-streaming\",\n }\n return { ...v, blocks: [...v.blocks, f(created)] }\n}\n\nconst updateObject = (v: View, id: string, f: (block: AnyObject) => AnyObject): View => {\n const index = v.blocks.findIndex((b) => b.type === \"object\" && b.id === id)\n const current = v.blocks[index]\n if (current !== undefined && current.type === \"object\") {\n return { ...v, blocks: replaceAt(v.blocks, index, f(current)) }\n }\n return { ...v, blocks: [...v.blocks, f({ type: \"object\", id, status: \"streaming\" })] }\n}\n\nconst applyPatch = Option.liftThrowable(JsonPatch.apply)\n// An unnamed object has no contract entry, so its value stays JSON.\nconst isJson = Schema.is(Schema.Json)\n\n// A bad patch leaves the partial value as is; the next snapshot or `object-done` repairs it.\nconst objectDelta = (\n block: AnyObject,\n e: Extract<RunEvent, { type: \"object-delta\" }>,\n): AnyObject => {\n if (e.value !== undefined) return { ...block, partial: e.value }\n const patch = e.patch\n if (patch === undefined) return block\n return applyPatch(patch, block.partial ?? {}).pipe(\n Option.match({ onNone: () => block, onSome: (partial) => ({ ...block, partial }) }),\n )\n}\n\nconst sum = (a: number | undefined, b: number | undefined): number | undefined =>\n a === undefined && b === undefined ? undefined : (a ?? 0) + (b ?? 0)\n\nconst addUsage = (\n total: Items.Usage | undefined,\n step: Items.Usage | undefined,\n): Items.Usage | undefined => {\n if (step === undefined) return total\n if (total === undefined) return step\n const input = sum(total.input_tokens, step.input_tokens)\n const output = sum(total.output_tokens, step.output_tokens)\n const all = sum(total.total_tokens, step.total_tokens)\n return {\n ...(input !== undefined ? { input_tokens: input } : {}),\n ...(output !== undefined ? { output_tokens: output } : {}),\n ...(all !== undefined ? { total_tokens: all } : {}),\n }\n}\n\nconst withUsage = (v: View, usage: Items.Usage | undefined): View => {\n const total = addUsage(v.usage, usage)\n return total === undefined ? v : { ...v, usage: total }\n}\n\nconst apply = (v: View, event: RunEvent<Payloads>): View =>\n Match.value(event).pipe(\n Match.discriminatorsExhaustive(\"type\")({\n \"run-started\": (e): View => ({\n ...v,\n status: \"streaming\",\n runId: e.runId,\n inputs: e.inputs,\n ...(e.name !== undefined ? { name: e.name } : {}),\n }),\n \"run-completed\": (e): View => ({\n ...v,\n status: \"completed\",\n ...(e.metadata !== undefined ? { metadata: e.metadata } : {}),\n }),\n \"run-interrupted\": (e): View =>\n e.interrupts.reduce<View>(\n (acc, i) =>\n updateTool(acc, i.callId, i.name, (b) => ({\n ...b,\n status: \"awaiting-approval\",\n input: i.input,\n })),\n { ...v, status: \"interrupted\", interrupts: e.interrupts },\n ),\n \"run-failed\": (e): View => ({\n ...v,\n status: \"failed\",\n error: {\n reason: e.reason,\n ...(e.message !== undefined ? { message: e.message } : {}),\n },\n }),\n \"run-stopped\": (): View => ({ ...v, status: \"stopped\" }),\n \"step-started\": (): View => ({ ...v, stepStart: v.blocks.length }),\n \"step-finished\": (e): View => withUsage(v, e.usage),\n \"step-reset\": (): View => ({ ...v, blocks: v.blocks.slice(0, v.stepStart) }),\n \"text-delta\": (e) => appendText(v, \"output_text\", e.text),\n \"refusal-delta\": (e) => appendText(v, \"refusal\", e.text),\n \"reasoning-started\": (): View =>\n v.blocks.some((b, i) => b.type === \"reasoning\" && i >= v.stepStart)\n ? v\n : push(v, (id) => ({ type: \"reasoning\", id, text: \"\" })),\n \"reasoning-delta\": (e) => appendText(v, \"reasoning\", e.text),\n citation: (e) => cite(v, e.annotation),\n image: (e): View => {\n const index = v.blocks.length - 1\n const last = v.blocks[index]\n const block = (id: string): AnyBlock =>\n e.partialIndex === undefined\n ? { type: \"output_image\", id, source: e.image }\n : { type: \"output_image\", id, source: e.image, partialIndex: e.partialIndex }\n // A preview frame is replaced by the next preview or the final image.\n return last !== undefined && last.type === \"output_image\" && last.partialIndex !== undefined\n ? { ...v, blocks: replaceAt(v.blocks, index, block(last.id)) }\n : push(v, block)\n },\n \"object-started\": (e): View =>\n updateObject(v, e.id, (b) => (e.name === undefined ? b : { ...b, name: e.name })),\n \"object-delta\": (e) => updateObject(v, e.id, (b) => objectDelta(b, e)),\n \"object-done\": (e) =>\n updateObject(v, e.id, (b) =>\n b.name === undefined\n ? { ...b, status: \"done\", ...(isJson(e.value) ? { value: e.value } : {}) }\n : { ...b, status: \"done\", value: e.value },\n ),\n \"object-failed\": (e) =>\n updateObject(v, e.id, (b) => ({ ...b, status: \"failed\", issues: e.issues })),\n \"tool-call-started\": (e) => updateTool(v, e.callId, e.name, (b) => b),\n \"tool-call-args-delta\": (e) =>\n updateTool(v, e.callId, \"\", (b) => ({ ...b, argsText: (b.argsText ?? \"\") + e.delta })),\n \"tool-call-ready\": (e) =>\n updateTool(v, e.callId, e.name, (b) => ({\n ...b,\n name: e.name,\n status: \"ready\",\n input: e.input,\n })),\n \"tool-approval-requested\": (e) =>\n updateTool(v, e.callId, e.name, (b) => ({\n ...b,\n status: \"awaiting-approval\",\n input: e.input,\n })),\n \"tool-partial\": (e) =>\n updateTool(v, e.callId, e.name, (b) => ({ ...b, status: \"running\", partial: e.value })),\n \"tool-result\": (e) =>\n updateTool(v, e.callId, e.name, (b) => ({\n ...b,\n status: e.result._tag === \"Success\" ? \"done\" : \"failed\",\n outcome: e.result,\n })),\n usage: (e): View => ({ ...v, usage: e.usage }),\n data: (e): View => {\n const index =\n e.id === undefined ? -1 : v.blocks.findIndex((b) => b.type === \"data\" && b.id === e.id)\n const existing = v.blocks[index]\n return existing !== undefined\n ? {\n ...v,\n blocks: replaceAt(v.blocks, index, {\n type: \"data\",\n id: existing.id,\n name: e.name,\n value: e.value,\n }),\n }\n : push(v, (id) => ({ type: \"data\", id: e.id ?? id, name: e.name, value: e.value }))\n },\n live: (e): View => ({ ...v, live: { ...v.live, [e.name]: e.value } }),\n // Stream-scoped; a chat fold (`Thread`) shows it, a run view has nothing to add.\n \"input-accepted\": (): View => v,\n }),\n )\n\n/**\n * Fold one envelope into the view. Ignores envelopes already applied\n * (`seq <= lastSeq`) and run-scoped envelopes of a different run.\n */\nexport function step<P extends Payloads = Untyped>(\n view: RunView<P>,\n envelope: Envelope<P>,\n): RunView<P>\nexport function step(view: View, envelope: Envelope<Payloads>): View {\n if (envelope.seq <= view.lastSeq) return view\n const otherRun =\n view.runId !== undefined && envelope.runId !== undefined && envelope.runId !== view.runId\n return { ...(otherRun ? view : apply(view, envelope.event)), lastSeq: envelope.seq }\n}\n\n/** A tool event that can answer a call made in an earlier run (after an approval). */\nexport type ToolUpdate<P extends Payloads = Untyped> = Extract<\n RunEvent<P>,\n { readonly type: \"tool-result\" | \"tool-partial\" }\n>\n\nexport const isToolUpdate = <P extends Payloads>(event: RunEvent<P>): event is ToolUpdate<P> =>\n event.type === \"tool-result\" || event.type === \"tool-partial\"\n\n/**\n * Apply a tool event to the view if it holds that call; `None` if it doesn't.\n * For a run that already ended (an interrupted run whose call was approved\n * later), so `seq` and the run id are not checked.\n */\nexport function applyToolUpdate<P extends Payloads>(\n view: RunView<P>,\n event: ToolUpdate<P>,\n): Option.Option<RunView<P>>\nexport function applyToolUpdate(view: View, event: ToolUpdate<Payloads>): Option.Option<View> {\n const holds = view.blocks.some((b) => b.type === \"tool\" && b.id === event.callId)\n return holds ? Option.some(apply(view, event)) : Option.none()\n}\n\n// ---------------------------------------------------------------------------\n// Selectors\n// ---------------------------------------------------------------------------\n\nconst TERMINAL: ReadonlySet<Status> = new Set([\"completed\", \"interrupted\", \"failed\", \"stopped\"])\n\nexport const isTerminal = <P extends Payloads>(view: RunView<P>): boolean =>\n TERMINAL.has(view.status)\n\nexport const isBusy = <P extends Payloads>(view: RunView<P>): boolean =>\n view.status === \"submitted\" || view.status === \"streaming\"\n\n/** All assistant text of the run, in order (refusals excluded, see `refusal`). */\nexport function text<P extends Payloads>(view: RunView<P>): string\nexport function text(view: View): string {\n return view.blocks.flatMap((b) => (b.type === \"output_text\" ? [b.text] : [])).join(\"\")\n}\n\n/** The refusal text, if the model declined; `undefined` otherwise. */\nexport function refusal<P extends Payloads>(view: RunView<P>): string | undefined\nexport function refusal(view: View): string | undefined {\n const parts = view.blocks.flatMap((b) => (b.type === \"refusal\" ? [b.text] : []))\n return parts.length === 0 ? undefined : parts.join(\"\")\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAa,aAAa,OAAO,SAAS;CACxC;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAGD,MAAa,eAAe,OAAO,SAAS;CAAC;CAAa;CAAQ;AAAQ,CAAC;;AAO3E,MAAa,YAAY,OAAO,OAAO;CAAE,GAAG,MAAM,WAAW;CAAQ,IAAI,OAAO;AAAO,CAAC;;AAExF,MAAa,eAAe,OAAO,OAAO;CAAE,GAAG,MAAM,QAAQ;CAAQ,IAAI,OAAO;AAAO,CAAC;;AAExF,MAAa,aAAa,OAAO,OAAO;CACtC,GAAG,MAAM,YAAY;CACrB,IAAI,OAAO;CACX,cAAc,OAAO,YAAY,OAAO,MAAM;AAChD,CAAC;AACD,MAAa,iBAAiB,OAAO,OAAO;CAC1C,MAAM,OAAO,QAAQ,WAAW;CAChC,IAAI,OAAO;CACX,MAAM,OAAO;AACf,CAAC;AA+ED,MAAa,SAAS,OAAO,SAAS;CACpC;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAGD,MAAM,WAAW,OAAO,OAAO;CAC7B,QAAQ,OAAO;CACf,SAAS,OAAO,YAAY,OAAO,MAAM;AAC3C,CAAC;;AAyBD,MAAa,aAMX,MACA,OACA,QACA,YAEA,OAAO,OAAO;CACZ,MAAM,OAAO,QAAQ,MAAM;CAC3B,IAAI,OAAO;CACX;CACA,QAAQ;CACR,OAAO,OAAO,YAAY,KAAK;CAC/B,UAAU,OAAO,YAAY,OAAO,MAAM;CAC1C,SAAS,OAAO,Y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AACrF;AAQA,MAAa,gBAAoC,UAC/C,MAAM,SAAS,iBAAiB,MAAM,SAAS;AAWjD,SAAgB,gBAAgB,MAAY,OAAkD;CAE5F,OADc,KAAK,OAAO,MAAM,MAAM,EAAE,SAAS,UAAU,EAAE,OAAO,MAAM,MAC/D,IAAI,OAAO,KAAK,MAAM,MAAM,KAAK,CAAC,IAAI,OAAO,KAAK;AAC/D;AAMA,MAAM,2BAAgC,IAAI,IAAI;CAAC;CAAa;CAAe;CAAU;AAAS,CAAC;AAE/F,MAAa,cAAkC,SAC7C,SAAS,IAAI,KAAK,MAAM;AAE1B,MAAa,UAA8B,SACzC,KAAK,WAAW,eAAe,KAAK,WAAW;AAIjD,SAAgB,KAAK,MAAoB;CACvC,OAAO,KAAK,OAAO,SAAS,MAAO,EAAE,SAAS,gBAAgB,CAAC,EAAE,IAAI,IAAI,CAAC,CAAE,CAAC,CAAC,KAAK,EAAE;AACvF;AAIA,SAAgB,QAAQ,MAAgC;CACtD,MAAM,QAAQ,KAAK,OAAO,SAAS,MAAO,EAAE,SAAS,YAAY,CAAC,EAAE,IAAI,IAAI,CAAC,CAAE;CAC/E,OAAO,MAAM,WAAW,IAAI,KAAA,IAAY,MAAM,KAAK,EAAE;AACvD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect-uai/ui",
3
- "version": "0.19.0",
3
+ "version": "0.19.1",
4
4
  "description": "Agentic UI primitives for @effect-uai/core: a resumable run-event protocol, projection, client folds and Effect atoms.",
5
5
  "keywords": [
6
6
  "agents",
@@ -89,7 +89,7 @@
89
89
  "@effect/vitest": "4.1.2",
90
90
  "effect": "4.1.2",
91
91
  "typescript": "^7.0.2",
92
- "@effect-uai/core": "0.19.0"
92
+ "@effect-uai/core": "0.19.1"
93
93
  },
94
94
  "peerDependencies": {
95
95
  "@effect-uai/core": ">=0.17.0 <1",
package/src/RunView.ts CHANGED
@@ -48,16 +48,16 @@ export type ObjectStatus = typeof ObjectStatus.Type
48
48
  // citations, images and refusals read like the turn's own content blocks.
49
49
 
50
50
  /** Core's `output_text`; citations attach to the text they cite. */
51
- const TextBlock = Schema.Struct({ ...Items.OutputText.fields, id: Schema.String })
51
+ export const TextBlock = Schema.Struct({ ...Items.OutputText.fields, id: Schema.String })
52
52
  /** Core's `refusal`: the model declined to answer. */
53
- const RefusalBlock = Schema.Struct({ ...Items.Refusal.fields, id: Schema.String })
53
+ export const RefusalBlock = Schema.Struct({ ...Items.Refusal.fields, id: Schema.String })
54
54
  /** Core's `output_image`; `partialIndex` marks a preview the final image replaces. */
55
- const ImageBlock = Schema.Struct({
55
+ export const ImageBlock = Schema.Struct({
56
56
  ...Items.OutputImage.fields,
57
57
  id: Schema.String,
58
58
  partialIndex: Schema.optionalKey(Schema.Number),
59
59
  })
60
- const ReasoningBlock = Schema.Struct({
60
+ export const ReasoningBlock = Schema.Struct({
61
61
  type: Schema.Literal("reasoning"),
62
62
  id: Schema.String,
63
63
  text: Schema.String,