@alquimia-ai/tools 2.5.0 → 2.8.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.
- package/README.md +603 -23
- package/dist/actions/index.d.mts +1 -1
- package/dist/actions/index.d.ts +1 -1
- package/dist/adapters/fetch.d.mts +1 -0
- package/dist/adapters/fetch.d.ts +1 -0
- package/dist/adapters/fetch.js +4 -0
- package/dist/adapters/fetch.js.map +1 -1
- package/dist/adapters/fetch.mjs +4 -0
- package/dist/adapters/fetch.mjs.map +1 -1
- package/dist/adapters/index.d.mts +1 -0
- package/dist/adapters/index.d.ts +1 -0
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/next.d.mts +1 -0
- package/dist/adapters/next.d.ts +1 -0
- package/dist/adapters/next.js +4 -0
- package/dist/adapters/next.js.map +1 -1
- package/dist/adapters/next.mjs +4 -0
- package/dist/adapters/next.mjs.map +1 -1
- package/dist/approvals-CcnmqUkQ.d.ts +59 -0
- package/dist/approvals-dn4sd_Ot.d.mts +59 -0
- package/dist/hooks/index.d.mts +36 -5
- package/dist/hooks/index.d.ts +36 -5
- package/dist/hooks/index.js +269 -17
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +269 -17
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/next/index.d.mts +7 -0
- package/dist/next/index.d.ts +7 -0
- package/dist/next/index.js +56 -37
- package/dist/next/index.js.map +1 -1
- package/dist/next/index.mjs +56 -37
- package/dist/next/index.mjs.map +1 -1
- package/dist/providers/index.d.mts +3 -3
- package/dist/providers/index.d.ts +3 -3
- package/dist/{providers-b5_yMyMo.d.ts → providers-J_Z9rQ3Q.d.ts} +1 -1
- package/dist/{providers-DiR9cgyo.d.mts → providers-YKiEag2L.d.mts} +1 -1
- package/dist/proxy.d.mts +2 -0
- package/dist/proxy.d.ts +2 -0
- package/dist/proxy.js +47 -37
- package/dist/proxy.js.map +1 -1
- package/dist/proxy.mjs +47 -37
- package/dist/proxy.mjs.map +1 -1
- package/dist/sdk/index.d.mts +60 -5
- package/dist/sdk/index.d.ts +60 -5
- package/dist/sdk/index.js +115 -15
- package/dist/sdk/index.js.map +1 -1
- package/dist/sdk/index.mjs +115 -15
- package/dist/sdk/index.mjs.map +1 -1
- package/dist/services/index.d.mts +1 -1
- package/dist/services/index.d.ts +1 -1
- package/dist/{type-xksRnBUW.d.ts → type-BFtGEEb4.d.ts} +45 -1
- package/dist/{type-DqX3-9QS.d.mts → type-C_sKpIM1.d.mts} +45 -1
- package/dist/types/index.d.mts +28 -5
- package/dist/types/index.d.ts +28 -5
- package/dist/types/index.js.map +1 -1
- package/dist/types/index.mjs.map +1 -1
- package/dist/{types-C-6fgK1_.d.mts → types-lOliroPw.d.mts} +1 -1
- package/dist/{types-C-6fgK1_.d.ts → types-lOliroPw.d.ts} +1 -1
- package/dist/utils/index.d.mts +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/worklog/index.d.mts +3 -2
- package/dist/worklog/index.d.ts +3 -2
- package/dist/worklog/index.js +94 -2
- package/dist/worklog/index.js.map +1 -1
- package/dist/worklog/index.mjs +94 -2
- package/dist/worklog/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/worklog/index.ts","../../src/worklog/types.ts","../../src/worklog/registry.ts","../../src/worklog/reducer.ts","../../src/worklog/use-worklog.ts","../../src/worklog/from-frame.ts"],"sourcesContent":["export * from \"./types\";\nexport { EVENT_REGISTRY, resolveInterpreter } from \"./registry\";\nexport { reduceWorklog, foldWorklog } from \"./reducer\";\nexport { useWorklog } from \"./use-worklog\";\nexport { frameToRecord, type RawFrame } from \"./from-frame\";\n","/** One granular Runtime worklog record (a `bus_mode` SSE frame or a `/worklog/{task_id}/events` item). */\nexport interface WorklogRecord {\n /** Runtime v0.5.0+ tamper-evident hash chain fields (optional on SSE frames). */\n entry_hash?: string | null;\n previous_hash?: string | null;\n event_class: string;\n control_id: string | null;\n data: unknown;\n status: \"success\" | \"error\" | null;\n date_submitted: string;\n}\n\n/** Runtime v0.5.0 worklog audit summary returned by `GET /worklog/`. */\nexport interface WorklogSummary {\n task_id: string;\n parent_task_id?: string | null;\n session_id?: string | null;\n user_id?: string | null;\n assistant_id?: string | null;\n agentspace_id?: string | null;\n channel_id?: string | null;\n depth?: number;\n final_status?: string | null;\n started_at: string;\n finished_at?: string | null;\n}\n\n/** Runtime v0.5.0 full worklog detail returned by `GET /worklog/{task_id}`. */\nexport interface WorklogDetail extends WorklogSummary {\n final_result?: string | null;\n error_message?: string | null;\n}\n\n/** Runtime v0.5.0 single worklog event returned by `GET /worklog/{task_id}/events`. */\nexport interface WorklogEventDetail {\n id: number;\n task_id: string;\n previous_hash?: string | null;\n entry_hash?: string | null;\n event_class: string;\n control_id?: string | null;\n status?: string | null;\n data?: unknown;\n submitted_at: string;\n}\n\n/** Runtime v0.5.0 paginated list of worklog summaries. */\nexport interface WorklogPage {\n items: WorklogSummary[];\n total: number;\n limit: number;\n offset: number;\n}\n\n/** Runtime v0.5.0 paginated list of worklog events for a single task. */\nexport interface WorklogEventPage {\n task_id: string;\n items: WorklogEventDetail[];\n total: number;\n}\n\n/** Runtime v0.5.0 hash-chain verification result returned by `GET /worklog/{task_id}/verify`. */\nexport interface WorklogVerificationResult {\n valid: boolean;\n task_id: string;\n event_count: number;\n first_broken_event_id?: number | null;\n first_broken_index?: number | null;\n expected_hash?: string | null;\n actual_hash?: string | null;\n message: string;\n}\n\n/** Semantic bucket a node belongs to. */\nexport type NodeKind =\n | \"safeguard\"\n | \"reasoning\"\n | \"tool\"\n | \"a2a\"\n | \"memory\"\n | \"answer\"\n | \"unknown\";\n\n/** Lifecycle state of a single node. */\nexport type NodeStatus = \"pending\" | \"running\" | \"completed\" | \"failed\" | \"skipped\";\n\n/** Overall run status. */\nexport type RunStatus = \"idle\" | \"running\" | \"success\" | \"error\";\n\n/** A single step in the execution chain (command + its response merged by control_id). */\nexport interface WorklogNode {\n id: string;\n kind: NodeKind;\n eventClass: string;\n status: NodeStatus;\n title: string;\n startedAt?: string;\n endedAt?: string;\n depth: number;\n parentId?: string;\n children: WorklogNode[];\n command?: unknown;\n response?: unknown;\n error?: string;\n raw: WorklogRecord[];\n}\n\n/** Normalized execution model produced by the reducer. */\nexport interface WorklogState {\n taskId: string | null;\n status: RunStatus;\n answer: string | null;\n nodes: WorklogNode[];\n index: Record<string, number>;\n raw: WorklogRecord[];\n}\n\n/** How a record acts on the model. */\nexport type EventRole = \"open\" | \"close\" | \"run-open\" | \"run-close\" | \"ignore\";\n\n/** Registry descriptor for one event_class. */\nexport interface EventInterpreter {\n kind: NodeKind;\n role: EventRole;\n title: (_record: WorklogRecord) => string;\n /** If true, an opened node starts in \"pending\" (awaiting external input) rather than \"running\". */\n pending?: boolean;\n}\n\nexport function initialWorklogState(taskId: string | null = null): WorklogState {\n return { taskId, status: \"idle\", answer: null, nodes: [], index: {}, raw: [] };\n}\n","import type { EventInterpreter, WorklogRecord } from \"./types\";\n\nconst asRecord = (data: unknown): Record<string, unknown> =>\n data && typeof data === \"object\" ? (data as Record<string, unknown>) : {};\n\nconst toolTitle = (r: WorklogRecord): string => {\n const name = asRecord(r.data).name;\n return typeof name === \"string\" && name.length > 0 ? `Tool: ${name}` : \"Tool\";\n};\n\nconst agentTitle = (r: WorklogRecord): string => {\n const name = asRecord(r.data).name;\n return typeof name === \"string\" && name.length > 0 ? `Agent: ${name}` : \"Agent-to-agent\";\n};\n\nconst constTitle = (label: string) => () => label;\n\nexport const EVENT_REGISTRY: Record<string, EventInterpreter> = {\n // Run envelope\n AssistantInference: { kind: \"answer\", role: \"run-open\", title: constTitle(\"Inference started\") },\n AssistantInferenceResponse: { kind: \"answer\", role: \"run-close\", title: constTitle(\"Answer\") },\n\n // Safeguard\n ShieldInference: { kind: \"safeguard\", role: \"open\", title: constTitle(\"Safeguard\") },\n ShieldInferenceResponse: { kind: \"safeguard\", role: \"close\", title: constTitle(\"Safeguard\") },\n\n // Reasoning\n ResponseInference: { kind: \"reasoning\", role: \"open\", title: constTitle(\"Reasoning\") },\n ResponseInferenceResponse: { kind: \"reasoning\", role: \"close\", title: constTitle(\"Reasoning\") },\n\n // Tools (server + subclasses) and their responses\n ServerToolExecution: { kind: \"tool\", role: \"open\", title: toolTitle },\n BuiltinToolExecution: { kind: \"tool\", role: \"open\", title: toolTitle },\n UnknownToolExecution: { kind: \"tool\", role: \"open\", title: toolTitle },\n ClientToolExecution: { kind: \"tool\", role: \"open\", title: toolTitle, pending: true },\n ToolExecutionResponse: { kind: \"tool\", role: \"close\", title: toolTitle },\n BuiltinToolExecutionResponse: { kind: \"tool\", role: \"close\", title: toolTitle },\n\n // Tool schema discovery\n ToolSchema: { kind: \"tool\", role: \"open\", title: constTitle(\"Tool schema\") },\n ToolSchemaResponse: { kind: \"tool\", role: \"close\", title: constTitle(\"Tool schema\") },\n\n // Agent-to-agent\n A2AInference: { kind: \"a2a\", role: \"open\", title: agentTitle },\n AgentDiscovery: { kind: \"a2a\", role: \"open\", title: constTitle(\"Agent discovery\") },\n AgentDiscoveryResponse: { kind: \"a2a\", role: \"close\", title: constTitle(\"Agent discovery\") },\n\n // Memory / persistence\n ContextPersistence: { kind: \"memory\", role: \"open\", title: constTitle(\"Memory persistence\") },\n ContextFlush: { kind: \"memory\", role: \"open\", title: constTitle(\"Memory flush\") },\n ContextFlushResponse: { kind: \"memory\", role: \"close\", title: constTitle(\"Memory flush\") },\n\n // Human approval\n HumanApprovalRequired: {\n kind: \"tool\",\n role: \"open\",\n title: constTitle(\"Human approval required\"),\n pending: true,\n },\n HumanApprovalRequiredResponse: { kind: \"tool\", role: \"close\", title: constTitle(\"Human approval\") },\n};\n\nexport function resolveInterpreter(eventClass: string): EventInterpreter {\n if (Object.prototype.hasOwnProperty.call(EVENT_REGISTRY, eventClass)) {\n return EVENT_REGISTRY[eventClass];\n }\n return {\n kind: \"unknown\",\n role: \"open\",\n title: (r: WorklogRecord) => r.event_class,\n };\n}\n","import { resolveInterpreter } from \"./registry\";\nimport type { EventInterpreter, WorklogNode, WorklogRecord, WorklogState } from \"./types\";\nimport { initialWorklogState } from \"./types\";\n\nconst asString = (v: unknown): string =>\n typeof v === \"string\" ? v : v == null ? \"\" : JSON.stringify(v);\n\nconst nodeDepth = (record: WorklogRecord): number => {\n const d = record.data && typeof record.data === \"object\"\n ? (record.data as Record<string, unknown>).depth\n : undefined;\n return typeof d === \"number\" ? d : 0;\n};\n\nconst makeOpenNode = (record: WorklogRecord, interp: EventInterpreter, id: string): WorklogNode => ({\n id,\n kind: interp.kind,\n eventClass: record.event_class,\n status: interp.pending ? \"pending\" : \"running\",\n title: interp.title(record),\n startedAt: record.date_submitted,\n depth: nodeDepth(record),\n children: [],\n command: record.data,\n raw: [record],\n});\n\nconst makeClosedNode = (record: WorklogRecord, interp: EventInterpreter, id: string): WorklogNode => ({\n id,\n kind: interp.kind,\n eventClass: record.event_class,\n status: record.status === \"error\" ? \"failed\" : \"completed\",\n title: interp.title(record),\n startedAt: record.date_submitted,\n endedAt: record.date_submitted,\n depth: nodeDepth(record),\n children: [],\n response: record.data,\n error: record.status === \"error\" ? asString(record.data) : undefined,\n raw: [record],\n});\n\nexport function reduceWorklog(state: WorklogState, record: WorklogRecord): WorklogState {\n const interp = resolveInterpreter(record.event_class);\n const next: WorklogState = {\n ...state,\n nodes: state.nodes.slice(),\n index: { ...state.index },\n raw: [...state.raw, record],\n };\n\n if (interp.role === \"ignore\") return next;\n\n if (interp.role === \"run-open\") {\n next.status = \"running\";\n return next;\n }\n\n if (interp.role === \"run-close\") {\n next.answer = asString(record.data) || null;\n next.status = record.status === \"error\" ? \"error\" : \"success\";\n return next;\n }\n\n const key = record.control_id ?? `${record.event_class}-${next.raw.length}`;\n\n if (interp.role === \"close\") {\n const pos = Object.prototype.hasOwnProperty.call(next.index, key) ? next.index[key] : undefined;\n if (pos != null) {\n const existing = next.nodes[pos];\n next.nodes[pos] = {\n ...existing,\n status: record.status === \"error\" ? \"failed\" : \"completed\",\n endedAt: record.date_submitted,\n response: record.data,\n error: record.status === \"error\" ? asString(record.data) : existing.error,\n raw: [...existing.raw, record],\n };\n } else {\n // response arrived without a seen command — create it already closed\n next.index[key] = next.nodes.length;\n next.nodes.push(makeClosedNode(record, interp, key));\n }\n if (record.status === \"error\") next.status = \"error\";\n return next;\n }\n\n // role === \"open\"\n const pos = Object.prototype.hasOwnProperty.call(next.index, key) ? next.index[key] : undefined;\n if (pos != null) {\n const existing = next.nodes[pos];\n next.nodes[pos] = { ...existing, raw: [...existing.raw, record] };\n } else {\n next.index[key] = next.nodes.length;\n next.nodes.push(makeOpenNode(record, interp, key));\n }\n return next;\n}\n\nexport function foldWorklog(records: WorklogRecord[], taskId: string | null = null): WorklogState {\n return records.reduce(reduceWorklog, initialWorklogState(taskId));\n}\n","import { useCallback, useReducer } from \"react\";\nimport { reduceWorklog } from \"./reducer\";\nimport { initialWorklogState, type WorklogRecord, type WorklogState } from \"./types\";\n\ntype Action =\n | { type: \"ingest\"; record: WorklogRecord }\n | { type: \"ingestMany\"; records: WorklogRecord[] }\n | { type: \"reset\"; taskId: string | null };\n\nfunction hookReducer(state: WorklogState, action: Action): WorklogState {\n switch (action.type) {\n case \"ingest\":\n return reduceWorklog(state, action.record);\n case \"ingestMany\":\n return action.records.reduce(reduceWorklog, state);\n case \"reset\":\n return initialWorklogState(action.taskId);\n }\n}\n\n/** Live worklog accumulator. Feed it `bus_mode` records via `ingest`; use `foldWorklog` for history. */\nexport function useWorklog(taskId: string | null = null) {\n const [worklog, dispatch] = useReducer(hookReducer, taskId, initialWorklogState);\n\n const ingest = useCallback((record: WorklogRecord) => dispatch({ type: \"ingest\", record }), []);\n const ingestMany = useCallback(\n (records: WorklogRecord[]) => dispatch({ type: \"ingestMany\", records }),\n [],\n );\n const reset = useCallback(\n (id: string | null = null) => dispatch({ type: \"reset\", taskId: id }),\n [],\n );\n\n return { worklog, ingest, ingestMany, reset };\n}\n","import type { WorklogRecord } from \"./types\";\n\n/** Loosely-typed shape of a parsed SSE `data:` frame from the granular Runtime stream. */\nexport interface RawFrame {\n event_class?: string;\n control_id?: string | null;\n data?: unknown;\n status?: string | null;\n date_submitted?: string;\n /** Runtime v0.5.0+ tamper-evident hash chain fields. */\n entry_hash?: string | null;\n previous_hash?: string | null;\n}\n\n/** Normalize a parsed SSE frame into a WorklogRecord (defaults missing fields; never throws). */\nexport function frameToRecord(frame: RawFrame): WorklogRecord {\n const status = frame.status === \"success\" || frame.status === \"error\" ? frame.status : null;\n return {\n event_class: typeof frame.event_class === \"string\" && frame.event_class.length > 0\n ? frame.event_class\n : \"Unknown\",\n control_id: frame.control_id ?? null,\n data: frame.data,\n status,\n date_submitted: typeof frame.date_submitted === \"string\" ? frame.date_submitted : \"\",\n entry_hash: frame.entry_hash ?? null,\n previous_hash: frame.previous_hash ?? null,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACiIO,SAAS,oBAAoB,SAAwB,MAAoB;AAC9E,SAAO,EAAE,QAAQ,QAAQ,QAAQ,QAAQ,MAAM,OAAO,CAAC,GAAG,OAAO,CAAC,GAAG,KAAK,CAAC,EAAE;AAC/E;;;ACjIA,IAAM,WAAW,CAAC,SAChB,QAAQ,OAAO,SAAS,WAAY,OAAmC,CAAC;AAE1E,IAAM,YAAY,CAAC,MAA6B;AAC9C,QAAM,OAAO,SAAS,EAAE,IAAI,EAAE;AAC9B,SAAO,OAAO,SAAS,YAAY,KAAK,SAAS,IAAI,SAAS,IAAI,KAAK;AACzE;AAEA,IAAM,aAAa,CAAC,MAA6B;AAC/C,QAAM,OAAO,SAAS,EAAE,IAAI,EAAE;AAC9B,SAAO,OAAO,SAAS,YAAY,KAAK,SAAS,IAAI,UAAU,IAAI,KAAK;AAC1E;AAEA,IAAM,aAAa,CAAC,UAAkB,MAAM;AAErC,IAAM,iBAAmD;AAAA;AAAA,EAE9D,o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E,QAAM,aAAS,0BAAY,CAAC,WAA0B,SAAS,EAAE,MAAM,UAAU,OAAO,CAAC,GAAG,CAAC,CAAC;AAC9F,QAAM,iBAAa;AAAA,IACjB,CAAC,YAA6B,SAAS,EAAE,MAAM,cAAc,QAAQ,CAAC;AAAA,IACtE,CAAC;AAAA,EACH;AACA,QAAM,YAAQ;AAAA,IACZ,CAAC,KAAoB,SAAS,SAAS,EAAE,MAAM,SAAS,QAAQ,GAAG,CAAC;AAAA,IACpE,CAAC;AAAA,EACH;AAEA,SAAO,EAAE,SAAS,QAAQ,YAAY,MAAM;AAC9C;;;ACpBO,SAAS,cAAc,OAAgC;AAC5D,QAAM,SAAS,MAAM,WAAW,aAAa,MAAM,WAAW,UAAU,MAAM,SAAS;AACvF,SAAO;AAAA,IACL,aAAa,OAAO,MAAM,gBAAgB,YAAY,MAAM,YAAY,SAAS,IAC7E,MAAM,cACN;AAAA,IACJ,YAAY,MAAM,cAAc;AAAA,IAChC,MAAM,MAAM;AAAA,IACZ;AAAA,IACA,gBAAgB,OAAO,MAAM,mBAAmB,WAAW,MAAM,iBAAiB;AAAA,IAClF,YAAY,MAAM,cAAc;AAAA,IAChC,eAAe,MAAM,iBAAiB;AAAA,EACxC;AACF;","names":["pos"]}
|
|
1
|
+
{"version":3,"sources":["../../src/worklog/index.ts","../../src/worklog/types.ts","../../src/worklog/registry.ts","../../src/worklog/reducer.ts","../../src/worklog/use-worklog.ts","../../src/worklog/from-frame.ts","../../src/worklog/approvals.ts"],"sourcesContent":["export * from \"./types\";\nexport { EVENT_REGISTRY, resolveInterpreter } from \"./registry\";\nexport { reduceWorklog, foldWorklog } from \"./reducer\";\nexport { useWorklog } from \"./use-worklog\";\nexport { frameToRecord, type RawFrame } from \"./from-frame\";\nexport {\n initialApprovalsState,\n reduceApprovals,\n foldApprovals,\n listApprovals,\n pendingApprovals,\n type ApprovalsState,\n type ApprovalRequest,\n type ApprovalDecision,\n} from \"./approvals\";\n","/** One granular Runtime worklog record (a `bus_mode` SSE frame or a `/worklog/{task_id}/events` item). */\nexport interface WorklogRecord {\n /** Runtime v0.5.0+ tamper-evident hash chain fields (optional on SSE frames). */\n entry_hash?: string | null;\n previous_hash?: string | null;\n event_class: string;\n control_id: string | null;\n data: unknown;\n status: \"success\" | \"error\" | null;\n date_submitted: string;\n}\n\n/** Runtime v0.5.0 worklog audit summary returned by `GET /worklog/`. */\nexport interface WorklogSummary {\n task_id: string;\n parent_task_id?: string | null;\n session_id?: string | null;\n user_id?: string | null;\n assistant_id?: string | null;\n agentspace_id?: string | null;\n channel_id?: string | null;\n depth?: number;\n final_status?: string | null;\n started_at: string;\n finished_at?: string | null;\n}\n\n/** Runtime v0.5.0 full worklog detail returned by `GET /worklog/{task_id}`. */\nexport interface WorklogDetail extends WorklogSummary {\n final_result?: string | null;\n error_message?: string | null;\n}\n\n/** Runtime v0.5.0 single worklog event returned by `GET /worklog/{task_id}/events`. */\nexport interface WorklogEventDetail {\n id: number;\n task_id: string;\n previous_hash?: string | null;\n entry_hash?: string | null;\n event_class: string;\n control_id?: string | null;\n status?: string | null;\n data?: unknown;\n submitted_at: string;\n}\n\n/** Runtime v0.5.0 paginated list of worklog summaries. */\nexport interface WorklogPage {\n items: WorklogSummary[];\n total: number;\n limit: number;\n offset: number;\n}\n\n/** Runtime v0.5.0 paginated list of worklog events for a single task. */\nexport interface WorklogEventPage {\n task_id: string;\n items: WorklogEventDetail[];\n total: number;\n}\n\n/** Runtime v0.5.0 hash-chain verification result returned by `GET /worklog/{task_id}/verify`. */\nexport interface WorklogVerificationResult {\n valid: boolean;\n task_id: string;\n event_count: number;\n first_broken_event_id?: number | null;\n first_broken_index?: number | null;\n expected_hash?: string | null;\n actual_hash?: string | null;\n message: string;\n}\n\n/** Semantic bucket a node belongs to. */\nexport type NodeKind =\n | \"safeguard\"\n | \"reasoning\"\n | \"tool\"\n | \"a2a\"\n | \"memory\"\n | \"knowledge\"\n | \"speech\"\n | \"answer\"\n | \"unknown\";\n\n/** Lifecycle state of a single node. */\nexport type NodeStatus = \"pending\" | \"running\" | \"completed\" | \"failed\" | \"skipped\";\n\n/** Overall run status. */\nexport type RunStatus = \"idle\" | \"running\" | \"success\" | \"error\";\n\n/** A single step in the execution chain (command + its response merged by control_id). */\nexport interface WorklogNode {\n id: string;\n kind: NodeKind;\n eventClass: string;\n status: NodeStatus;\n title: string;\n startedAt?: string;\n endedAt?: string;\n depth: number;\n parentId?: string;\n children: WorklogNode[];\n command?: unknown;\n response?: unknown;\n error?: string;\n raw: WorklogRecord[];\n}\n\n/** Normalized execution model produced by the reducer. */\nexport interface WorklogState {\n taskId: string | null;\n status: RunStatus;\n answer: string | null;\n nodes: WorklogNode[];\n index: Record<string, number>;\n raw: WorklogRecord[];\n}\n\n/** How a record acts on the model. */\nexport type EventRole = \"open\" | \"close\" | \"run-open\" | \"run-close\" | \"ignore\";\n\n/** Registry descriptor for one event_class. */\nexport interface EventInterpreter {\n kind: NodeKind;\n role: EventRole;\n title: (_record: WorklogRecord) => string;\n /** If true, an opened node starts in \"pending\" (awaiting external input) rather than \"running\". */\n pending?: boolean;\n}\n\nexport function initialWorklogState(taskId: string | null = null): WorklogState {\n return { taskId, status: \"idle\", answer: null, nodes: [], index: {}, raw: [] };\n}\n","import type { EventInterpreter, WorklogRecord } from \"./types\";\n\nconst asRecord = (data: unknown): Record<string, unknown> =>\n data && typeof data === \"object\" ? (data as Record<string, unknown>) : {};\n\nconst toolTitle = (r: WorklogRecord): string => {\n const name = asRecord(r.data).name;\n return typeof name === \"string\" && name.length > 0 ? `Tool: ${name}` : \"Tool\";\n};\n\nconst agentTitle = (r: WorklogRecord): string => {\n const name = asRecord(r.data).name;\n return typeof name === \"string\" && name.length > 0 ? `Agent: ${name}` : \"Agent-to-agent\";\n};\n\nconst constTitle = (label: string) => () => label;\n\n// The approval gate wraps the parked tool execution in `parameters`.\nconst approvalTitle = (r: WorklogRecord): string => {\n const name = asRecord(asRecord(r.data).parameters).name;\n return typeof name === \"string\" && name.length > 0\n ? `Approval required: ${name}`\n : \"Human approval required\";\n};\n\nconst shieldBlockTitle = (r: WorklogRecord): string => {\n const id = asRecord(r.data).shield_id;\n return typeof id === \"string\" && id.length > 0 ? `Blocked by ${id}` : \"Blocked by safeguard\";\n};\n\nconst knowledgeTitle = (r: WorklogRecord): string => {\n const query = asRecord(r.data).query;\n return typeof query === \"string\" && query.length > 0\n ? `Knowledge: ${query}`\n : \"Knowledge retrieval\";\n};\n\nexport const EVENT_REGISTRY: Record<string, EventInterpreter> = {\n // Run envelope\n AssistantInference: { kind: \"answer\", role: \"run-open\", title: constTitle(\"Inference started\") },\n AssistantInferenceResponse: { kind: \"answer\", role: \"run-close\", title: constTitle(\"Answer\") },\n\n // Safeguard\n ShieldInference: { kind: \"safeguard\", role: \"open\", title: constTitle(\"Safeguard\") },\n ShieldInferenceResponse: { kind: \"safeguard\", role: \"close\", title: constTitle(\"Safeguard\") },\n // Emitted when a shield enforcement decision blocks the request (core 0.5.x).\n // Response-only: the reducer opens it already closed when no command matched.\n ShieldBlockedResponse: { kind: \"safeguard\", role: \"close\", title: shieldBlockTitle },\n\n // Reasoning\n ResponseInference: { kind: \"reasoning\", role: \"open\", title: constTitle(\"Reasoning\") },\n ResponseInferenceResponse: { kind: \"reasoning\", role: \"close\", title: constTitle(\"Reasoning\") },\n\n // Tools (server + subclasses) and their responses\n ServerToolExecution: { kind: \"tool\", role: \"open\", title: toolTitle },\n BuiltinToolExecution: { kind: \"tool\", role: \"open\", title: toolTitle },\n UnknownToolExecution: { kind: \"tool\", role: \"open\", title: toolTitle },\n ClientToolExecution: { kind: \"tool\", role: \"open\", title: toolTitle, pending: true },\n ToolExecutionResponse: { kind: \"tool\", role: \"close\", title: toolTitle },\n BuiltinToolExecutionResponse: { kind: \"tool\", role: \"close\", title: toolTitle },\n\n // Tool schema discovery\n ToolSchema: { kind: \"tool\", role: \"open\", title: constTitle(\"Tool schema\") },\n ToolSchemaResponse: { kind: \"tool\", role: \"close\", title: constTitle(\"Tool schema\") },\n\n // Agent-to-agent\n A2AInference: { kind: \"a2a\", role: \"open\", title: agentTitle },\n AgentDiscovery: { kind: \"a2a\", role: \"open\", title: constTitle(\"Agent discovery\") },\n AgentDiscoveryResponse: { kind: \"a2a\", role: \"close\", title: constTitle(\"Agent discovery\") },\n\n // Knowledge retrieval (RAG) — core 0.5.x\n KnowledgeRetrieval: { kind: \"knowledge\", role: \"open\", title: knowledgeTitle },\n KnowledgeRetrievalResponse: { kind: \"knowledge\", role: \"close\", title: knowledgeTitle },\n\n // Speech pipeline — core 0.5.x\n SpeechTranscription: { kind: \"speech\", role: \"open\", title: constTitle(\"Speech-to-text\") },\n SpeechTranscriptionResponse: { kind: \"speech\", role: \"close\", title: constTitle(\"Speech-to-text\") },\n SpeechSynthesis: { kind: \"speech\", role: \"open\", title: constTitle(\"Text-to-speech\") },\n SpeechSynthesisResponse: { kind: \"speech\", role: \"close\", title: constTitle(\"Text-to-speech\") },\n\n // Memory / persistence\n ContextPersistence: { kind: \"memory\", role: \"open\", title: constTitle(\"Memory persistence\") },\n ContextFlush: { kind: \"memory\", role: \"open\", title: constTitle(\"Memory flush\") },\n ContextFlushResponse: { kind: \"memory\", role: \"close\", title: constTitle(\"Memory flush\") },\n\n // Human approval\n HumanApprovalRequired: {\n kind: \"tool\",\n role: \"open\",\n title: approvalTitle,\n pending: true,\n },\n HumanApprovalRequiredResponse: { kind: \"tool\", role: \"close\", title: constTitle(\"Human approval\") },\n};\n\nexport function resolveInterpreter(eventClass: string): EventInterpreter {\n if (Object.prototype.hasOwnProperty.call(EVENT_REGISTRY, eventClass)) {\n return EVENT_REGISTRY[eventClass];\n }\n return {\n kind: \"unknown\",\n role: \"open\",\n title: (r: WorklogRecord) => r.event_class,\n };\n}\n","import { resolveInterpreter } from \"./registry\";\nimport type { EventInterpreter, WorklogNode, WorklogRecord, WorklogState } from \"./types\";\nimport { initialWorklogState } from \"./types\";\n\nconst asString = (v: unknown): string =>\n typeof v === \"string\" ? v : v == null ? \"\" : JSON.stringify(v);\n\nconst nodeDepth = (record: WorklogRecord): number => {\n const d = record.data && typeof record.data === \"object\"\n ? (record.data as Record<string, unknown>).depth\n : undefined;\n return typeof d === \"number\" ? d : 0;\n};\n\nconst makeOpenNode = (record: WorklogRecord, interp: EventInterpreter, id: string): WorklogNode => ({\n id,\n kind: interp.kind,\n eventClass: record.event_class,\n status: interp.pending ? \"pending\" : \"running\",\n title: interp.title(record),\n startedAt: record.date_submitted,\n depth: nodeDepth(record),\n children: [],\n command: record.data,\n raw: [record],\n});\n\nconst makeClosedNode = (record: WorklogRecord, interp: EventInterpreter, id: string): WorklogNode => ({\n id,\n kind: interp.kind,\n eventClass: record.event_class,\n status: record.status === \"error\" ? \"failed\" : \"completed\",\n title: interp.title(record),\n startedAt: record.date_submitted,\n endedAt: record.date_submitted,\n depth: nodeDepth(record),\n children: [],\n response: record.data,\n error: record.status === \"error\" ? asString(record.data) : undefined,\n raw: [record],\n});\n\nexport function reduceWorklog(state: WorklogState, record: WorklogRecord): WorklogState {\n const interp = resolveInterpreter(record.event_class);\n const next: WorklogState = {\n ...state,\n nodes: state.nodes.slice(),\n index: { ...state.index },\n raw: [...state.raw, record],\n };\n\n if (interp.role === \"ignore\") return next;\n\n if (interp.role === \"run-open\") {\n next.status = \"running\";\n return next;\n }\n\n if (interp.role === \"run-close\") {\n next.answer = asString(record.data) || null;\n next.status = record.status === \"error\" ? \"error\" : \"success\";\n return next;\n }\n\n const key = record.control_id ?? `${record.event_class}-${next.raw.length}`;\n\n if (interp.role === \"close\") {\n const pos = Object.prototype.hasOwnProperty.call(next.index, key) ? next.index[key] : undefined;\n if (pos != null) {\n const existing = next.nodes[pos];\n next.nodes[pos] = {\n ...existing,\n status: record.status === \"error\" ? \"failed\" : \"completed\",\n endedAt: record.date_submitted,\n response: record.data,\n error: record.status === \"error\" ? asString(record.data) : existing.error,\n raw: [...existing.raw, record],\n };\n } else {\n // response arrived without a seen command — create it already closed\n next.index[key] = next.nodes.length;\n next.nodes.push(makeClosedNode(record, interp, key));\n }\n if (record.status === \"error\") next.status = \"error\";\n return next;\n }\n\n // role === \"open\"\n const pos = Object.prototype.hasOwnProperty.call(next.index, key) ? next.index[key] : undefined;\n if (pos != null) {\n const existing = next.nodes[pos];\n // The command can arrive after its response (the node was opened closed);\n // keep the status, but fill in what the command says it was.\n next.nodes[pos] = {\n ...existing,\n command: existing.command ?? record.data,\n title: existing.command === undefined ? interp.title(record) : existing.title,\n raw: [...existing.raw, record],\n };\n } else {\n next.index[key] = next.nodes.length;\n next.nodes.push(makeOpenNode(record, interp, key));\n }\n return next;\n}\n\nexport function foldWorklog(records: WorklogRecord[], taskId: string | null = null): WorklogState {\n return records.reduce(reduceWorklog, initialWorklogState(taskId));\n}\n","import { useCallback, useReducer } from \"react\";\nimport { reduceWorklog } from \"./reducer\";\nimport { initialWorklogState, type WorklogRecord, type WorklogState } from \"./types\";\n\ntype Action =\n | { type: \"ingest\"; record: WorklogRecord }\n | { type: \"ingestMany\"; records: WorklogRecord[] }\n | { type: \"reset\"; taskId: string | null };\n\nfunction hookReducer(state: WorklogState, action: Action): WorklogState {\n switch (action.type) {\n case \"ingest\":\n return reduceWorklog(state, action.record);\n case \"ingestMany\":\n return action.records.reduce(reduceWorklog, state);\n case \"reset\":\n return initialWorklogState(action.taskId);\n }\n}\n\n/** Live worklog accumulator. Feed it `bus_mode` records via `ingest`; use `foldWorklog` for history. */\nexport function useWorklog(taskId: string | null = null) {\n const [worklog, dispatch] = useReducer(hookReducer, taskId, initialWorklogState);\n\n const ingest = useCallback((record: WorklogRecord) => dispatch({ type: \"ingest\", record }), []);\n const ingestMany = useCallback(\n (records: WorklogRecord[]) => dispatch({ type: \"ingestMany\", records }),\n [],\n );\n const reset = useCallback(\n (id: string | null = null) => dispatch({ type: \"reset\", taskId: id }),\n [],\n );\n\n return { worklog, ingest, ingestMany, reset };\n}\n","import type { WorklogRecord } from \"./types\";\n\n/** Loosely-typed shape of a parsed SSE `data:` frame from the granular Runtime stream. */\nexport interface RawFrame {\n event_class?: string;\n control_id?: string | null;\n data?: unknown;\n status?: string | null;\n date_submitted?: string;\n /** Runtime v0.5.0+ tamper-evident hash chain fields. */\n entry_hash?: string | null;\n previous_hash?: string | null;\n}\n\n/** Normalize a parsed SSE frame into a WorklogRecord (defaults missing fields; never throws). */\nexport function frameToRecord(frame: RawFrame): WorklogRecord {\n const status = frame.status === \"success\" || frame.status === \"error\" ? frame.status : null;\n return {\n event_class: typeof frame.event_class === \"string\" && frame.event_class.length > 0\n ? frame.event_class\n : \"Unknown\",\n control_id: frame.control_id ?? null,\n data: frame.data,\n status,\n date_submitted: typeof frame.date_submitted === \"string\" ? frame.date_submitted : \"\",\n entry_hash: frame.entry_hash ?? null,\n previous_hash: frame.previous_hash ?? null,\n };\n}\n","import type { WorklogRecord } from \"./types\";\n\n/**\n * Human-approval gates, derived from the worklog.\n *\n * When the runtime's authz policy resolves a tool call to `REQUIRE_APPROVAL`,\n * core parks the call and records a `HumanApprovalRequired` whose `data` is the\n * command minus its conversation: `{ parameters: <the tool execution> }`. The\n * gate closes with a `HumanApprovalRequiredResponse` under the same\n * `control_id`, whichever channel the decision came through — so the stream,\n * not the local submit, is the source of truth for \"settled\".\n */\n\n/** A decision as the worklog records it. */\nexport interface ApprovalDecision {\n approved: boolean;\n /**\n * Rejection reason. Core records `result or message` as the response data,\n * so an approval never carries one and a rejection carries the reason when\n * the approver gave it.\n */\n reason: string | null;\n decidedAt: string;\n}\n\n/** One approval gate, pending or settled. */\nexport interface ApprovalRequest {\n /** The `HumanApprovalRequired` control id — the one `/event/tool-approval` expects. */\n controlId: string;\n /** Name of the parked tool call; `null` until the request record is seen. */\n toolName: string | null;\n /** Control id of the parked tool execution itself (distinct from `controlId`). */\n toolCallId: string | null;\n /** Arguments the tool would be called with. What is actually being approved. */\n arguments: unknown;\n /**\n * The gate belongs to an MCP server that runs its own approval over the\n * task's originating channel (the `mcp_approval` runtime extension). The\n * runtime refuses an HTTP decision for it with a 409, so offering buttons\n * would be a lie.\n */\n channelOwned: boolean;\n requestedAt: string | null;\n /** `null` while pending. */\n decision: ApprovalDecision | null;\n}\n\nexport interface ApprovalsState {\n /** Gates in the order they were first seen. */\n order: string[];\n byId: Record<string, ApprovalRequest>;\n}\n\nexport function initialApprovalsState(): ApprovalsState {\n return { order: [], byId: {} };\n}\n\nconst asObject = (v: unknown): Record<string, unknown> | null =>\n v && typeof v === \"object\" && !Array.isArray(v) ? (v as Record<string, unknown>) : null;\n\nconst MCP_APPROVAL_EXTENSION = \"mcp_approval\";\n\nfunction describeRequest(record: WorklogRecord) {\n const execution = asObject(asObject(record.data)?.parameters) ?? {};\n const name = execution.name;\n const callId = execution.control_id;\n // Server tools keep their config in `parameters` and the LLM's arguments in\n // `tool_call_parameters`; client and builtin tools put the arguments in\n // `parameters` directly.\n const args =\n execution.tool_call_parameters !== undefined && execution.tool_call_parameters !== null\n ? execution.tool_call_parameters\n : execution.parameters;\n const extensions = asObject(execution.parameters)?.runtime_extensions;\n return {\n toolName: typeof name === \"string\" && name.length > 0 ? name : null,\n toolCallId: typeof callId === \"string\" ? callId : null,\n arguments: args ?? null,\n channelOwned: Array.isArray(extensions) && extensions.includes(MCP_APPROVAL_EXTENSION),\n };\n}\n\nfunction describeDecision(record: WorklogRecord): ApprovalDecision {\n const approved = record.data === true;\n return {\n approved,\n reason: !approved && typeof record.data === \"string\" && record.data.length > 0 ? record.data : null,\n decidedAt: record.date_submitted,\n };\n}\n\nconst blank = (controlId: string): ApprovalRequest => ({\n controlId,\n toolName: null,\n toolCallId: null,\n arguments: null,\n channelOwned: false,\n requestedAt: null,\n decision: null,\n});\n\n/** Fold one worklog record into the approvals state. Records of other classes are a no-op. */\nexport function reduceApprovals(state: ApprovalsState, record: WorklogRecord): ApprovalsState {\n const isRequest = record.event_class === \"HumanApprovalRequired\";\n const isResponse = record.event_class === \"HumanApprovalRequiredResponse\";\n if ((!isRequest && !isResponse) || !record.control_id) return state;\n\n const id = record.control_id;\n const known = state.byId[id];\n const current = known ?? blank(id);\n\n // A response can overtake its request (bus redelivery, a replayed history).\n // Either order lands on the same settled entry: the request only fills in\n // what is being approved and never reopens a decision.\n const next: ApprovalRequest = isRequest\n ? { ...current, ...describeRequest(record), requestedAt: record.date_submitted }\n : { ...current, decision: current.decision ?? describeDecision(record) };\n\n return {\n order: known ? state.order : [...state.order, id],\n byId: { ...state.byId, [id]: next },\n };\n}\n\nexport function foldApprovals(records: WorklogRecord[]): ApprovalsState {\n return records.reduce(reduceApprovals, initialApprovalsState());\n}\n\n/** All gates, in first-seen order. */\nexport function listApprovals(state: ApprovalsState): ApprovalRequest[] {\n return state.order.map((id) => state.byId[id]);\n}\n\n/** Gates with no recorded decision yet. */\nexport function pendingApprovals(state: ApprovalsState): ApprovalRequest[] {\n return listApprovals(state).filter((a) => a.decision === null);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACmIO,SAAS,oBAAoB,SAAwB,MAAoB;AAC9E,SAAO,EAAE,QAAQ,QAAQ,QAAQ,QAAQ,MAAM,OAAO,CAAC,GAAG,OAAO,CAAC,GAAG,KAAK,CAAC,EAAE;AAC/E;;;ACnIA,IAAM,WAAW,CAAC,SAChB,QAAQ,OAAO,SAAS,WAAY,OAAmC,CAAC;AAE1E,IAAM,YAAY,CAAC,MAA6B;AAC9C,QAAM,OAAO,SAAS,EAAE,IAAI,EAAE;AAC9B,SAAO,OAAO,SAAS,YAAY,KAAK,SAAS,IAAI,SAAS,IAAI,KAAK;AACzE;AAEA,IAAM,aAAa,CAAC,MAA6B;AAC/C,QAAM,OAAO,SAAS,EAAE,IAAI,EAAE;AAC9B,SAAO,OAAO,SAAS,YAAY,KAAK,SAAS,IAAI,UAAU,IAAI,KAAK;AAC1E;AAEA,IAAM,aAAa,CAAC,UAAkB,MAAM;AAG5C,IAAM,gBAAgB,CAA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AGO,SAAS,iBAAiB,OAA0C;AACzE,SAAO,cAAc,KAAK,EAAE,OAAO,CAAC,MAAM,EAAE,aAAa,IAAI;AAC/D;","names":["pos"]}
|
package/dist/worklog/index.mjs
CHANGED
|
@@ -14,6 +14,18 @@ var agentTitle = (r) => {
|
|
|
14
14
|
return typeof name === "string" && name.length > 0 ? `Agent: ${name}` : "Agent-to-agent";
|
|
15
15
|
};
|
|
16
16
|
var constTitle = (label) => () => label;
|
|
17
|
+
var approvalTitle = (r) => {
|
|
18
|
+
const name = asRecord(asRecord(r.data).parameters).name;
|
|
19
|
+
return typeof name === "string" && name.length > 0 ? `Approval required: ${name}` : "Human approval required";
|
|
20
|
+
};
|
|
21
|
+
var shieldBlockTitle = (r) => {
|
|
22
|
+
const id = asRecord(r.data).shield_id;
|
|
23
|
+
return typeof id === "string" && id.length > 0 ? `Blocked by ${id}` : "Blocked by safeguard";
|
|
24
|
+
};
|
|
25
|
+
var knowledgeTitle = (r) => {
|
|
26
|
+
const query = asRecord(r.data).query;
|
|
27
|
+
return typeof query === "string" && query.length > 0 ? `Knowledge: ${query}` : "Knowledge retrieval";
|
|
28
|
+
};
|
|
17
29
|
var EVENT_REGISTRY = {
|
|
18
30
|
// Run envelope
|
|
19
31
|
AssistantInference: { kind: "answer", role: "run-open", title: constTitle("Inference started") },
|
|
@@ -21,6 +33,9 @@ var EVENT_REGISTRY = {
|
|
|
21
33
|
// Safeguard
|
|
22
34
|
ShieldInference: { kind: "safeguard", role: "open", title: constTitle("Safeguard") },
|
|
23
35
|
ShieldInferenceResponse: { kind: "safeguard", role: "close", title: constTitle("Safeguard") },
|
|
36
|
+
// Emitted when a shield enforcement decision blocks the request (core 0.5.x).
|
|
37
|
+
// Response-only: the reducer opens it already closed when no command matched.
|
|
38
|
+
ShieldBlockedResponse: { kind: "safeguard", role: "close", title: shieldBlockTitle },
|
|
24
39
|
// Reasoning
|
|
25
40
|
ResponseInference: { kind: "reasoning", role: "open", title: constTitle("Reasoning") },
|
|
26
41
|
ResponseInferenceResponse: { kind: "reasoning", role: "close", title: constTitle("Reasoning") },
|
|
@@ -38,6 +53,14 @@ var EVENT_REGISTRY = {
|
|
|
38
53
|
A2AInference: { kind: "a2a", role: "open", title: agentTitle },
|
|
39
54
|
AgentDiscovery: { kind: "a2a", role: "open", title: constTitle("Agent discovery") },
|
|
40
55
|
AgentDiscoveryResponse: { kind: "a2a", role: "close", title: constTitle("Agent discovery") },
|
|
56
|
+
// Knowledge retrieval (RAG) — core 0.5.x
|
|
57
|
+
KnowledgeRetrieval: { kind: "knowledge", role: "open", title: knowledgeTitle },
|
|
58
|
+
KnowledgeRetrievalResponse: { kind: "knowledge", role: "close", title: knowledgeTitle },
|
|
59
|
+
// Speech pipeline — core 0.5.x
|
|
60
|
+
SpeechTranscription: { kind: "speech", role: "open", title: constTitle("Speech-to-text") },
|
|
61
|
+
SpeechTranscriptionResponse: { kind: "speech", role: "close", title: constTitle("Speech-to-text") },
|
|
62
|
+
SpeechSynthesis: { kind: "speech", role: "open", title: constTitle("Text-to-speech") },
|
|
63
|
+
SpeechSynthesisResponse: { kind: "speech", role: "close", title: constTitle("Text-to-speech") },
|
|
41
64
|
// Memory / persistence
|
|
42
65
|
ContextPersistence: { kind: "memory", role: "open", title: constTitle("Memory persistence") },
|
|
43
66
|
ContextFlush: { kind: "memory", role: "open", title: constTitle("Memory flush") },
|
|
@@ -46,7 +69,7 @@ var EVENT_REGISTRY = {
|
|
|
46
69
|
HumanApprovalRequired: {
|
|
47
70
|
kind: "tool",
|
|
48
71
|
role: "open",
|
|
49
|
-
title:
|
|
72
|
+
title: approvalTitle,
|
|
50
73
|
pending: true
|
|
51
74
|
},
|
|
52
75
|
HumanApprovalRequiredResponse: { kind: "tool", role: "close", title: constTitle("Human approval") }
|
|
@@ -135,7 +158,12 @@ function reduceWorklog(state, record) {
|
|
|
135
158
|
const pos = Object.prototype.hasOwnProperty.call(next.index, key) ? next.index[key] : void 0;
|
|
136
159
|
if (pos != null) {
|
|
137
160
|
const existing = next.nodes[pos];
|
|
138
|
-
next.nodes[pos] = {
|
|
161
|
+
next.nodes[pos] = {
|
|
162
|
+
...existing,
|
|
163
|
+
command: existing.command ?? record.data,
|
|
164
|
+
title: existing.command === void 0 ? interp.title(record) : existing.title,
|
|
165
|
+
raw: [...existing.raw, record]
|
|
166
|
+
};
|
|
139
167
|
} else {
|
|
140
168
|
next.index[key] = next.nodes.length;
|
|
141
169
|
next.nodes.push(makeOpenNode(record, interp, key));
|
|
@@ -185,11 +213,75 @@ function frameToRecord(frame) {
|
|
|
185
213
|
previous_hash: frame.previous_hash ?? null
|
|
186
214
|
};
|
|
187
215
|
}
|
|
216
|
+
|
|
217
|
+
// src/worklog/approvals.ts
|
|
218
|
+
function initialApprovalsState() {
|
|
219
|
+
return { order: [], byId: {} };
|
|
220
|
+
}
|
|
221
|
+
var asObject = (v) => v && typeof v === "object" && !Array.isArray(v) ? v : null;
|
|
222
|
+
var MCP_APPROVAL_EXTENSION = "mcp_approval";
|
|
223
|
+
function describeRequest(record) {
|
|
224
|
+
const execution = asObject(asObject(record.data)?.parameters) ?? {};
|
|
225
|
+
const name = execution.name;
|
|
226
|
+
const callId = execution.control_id;
|
|
227
|
+
const args = execution.tool_call_parameters !== void 0 && execution.tool_call_parameters !== null ? execution.tool_call_parameters : execution.parameters;
|
|
228
|
+
const extensions = asObject(execution.parameters)?.runtime_extensions;
|
|
229
|
+
return {
|
|
230
|
+
toolName: typeof name === "string" && name.length > 0 ? name : null,
|
|
231
|
+
toolCallId: typeof callId === "string" ? callId : null,
|
|
232
|
+
arguments: args ?? null,
|
|
233
|
+
channelOwned: Array.isArray(extensions) && extensions.includes(MCP_APPROVAL_EXTENSION)
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
function describeDecision(record) {
|
|
237
|
+
const approved = record.data === true;
|
|
238
|
+
return {
|
|
239
|
+
approved,
|
|
240
|
+
reason: !approved && typeof record.data === "string" && record.data.length > 0 ? record.data : null,
|
|
241
|
+
decidedAt: record.date_submitted
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
var blank = (controlId) => ({
|
|
245
|
+
controlId,
|
|
246
|
+
toolName: null,
|
|
247
|
+
toolCallId: null,
|
|
248
|
+
arguments: null,
|
|
249
|
+
channelOwned: false,
|
|
250
|
+
requestedAt: null,
|
|
251
|
+
decision: null
|
|
252
|
+
});
|
|
253
|
+
function reduceApprovals(state, record) {
|
|
254
|
+
const isRequest = record.event_class === "HumanApprovalRequired";
|
|
255
|
+
const isResponse = record.event_class === "HumanApprovalRequiredResponse";
|
|
256
|
+
if (!isRequest && !isResponse || !record.control_id) return state;
|
|
257
|
+
const id = record.control_id;
|
|
258
|
+
const known = state.byId[id];
|
|
259
|
+
const current = known ?? blank(id);
|
|
260
|
+
const next = isRequest ? { ...current, ...describeRequest(record), requestedAt: record.date_submitted } : { ...current, decision: current.decision ?? describeDecision(record) };
|
|
261
|
+
return {
|
|
262
|
+
order: known ? state.order : [...state.order, id],
|
|
263
|
+
byId: { ...state.byId, [id]: next }
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
function foldApprovals(records) {
|
|
267
|
+
return records.reduce(reduceApprovals, initialApprovalsState());
|
|
268
|
+
}
|
|
269
|
+
function listApprovals(state) {
|
|
270
|
+
return state.order.map((id) => state.byId[id]);
|
|
271
|
+
}
|
|
272
|
+
function pendingApprovals(state) {
|
|
273
|
+
return listApprovals(state).filter((a) => a.decision === null);
|
|
274
|
+
}
|
|
188
275
|
export {
|
|
189
276
|
EVENT_REGISTRY,
|
|
277
|
+
foldApprovals,
|
|
190
278
|
foldWorklog,
|
|
191
279
|
frameToRecord,
|
|
280
|
+
initialApprovalsState,
|
|
192
281
|
initialWorklogState,
|
|
282
|
+
listApprovals,
|
|
283
|
+
pendingApprovals,
|
|
284
|
+
reduceApprovals,
|
|
193
285
|
reduceWorklog,
|
|
194
286
|
resolveInterpreter,
|
|
195
287
|
useWorklog
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/worklog/types.ts","../../src/worklog/registry.ts","../../src/worklog/reducer.ts","../../src/worklog/use-worklog.ts","../../src/worklog/from-frame.ts"],"sourcesContent":["/** One granular Runtime worklog record (a `bus_mode` SSE frame or a `/worklog/{task_id}/events` item). */\nexport interface WorklogRecord {\n /** Runtime v0.5.0+ tamper-evident hash chain fields (optional on SSE frames). */\n entry_hash?: string | null;\n previous_hash?: string | null;\n event_class: string;\n control_id: string | null;\n data: unknown;\n status: \"success\" | \"error\" | null;\n date_submitted: string;\n}\n\n/** Runtime v0.5.0 worklog audit summary returned by `GET /worklog/`. */\nexport interface WorklogSummary {\n task_id: string;\n parent_task_id?: string | null;\n session_id?: string | null;\n user_id?: string | null;\n assistant_id?: string | null;\n agentspace_id?: string | null;\n channel_id?: string | null;\n depth?: number;\n final_status?: string | null;\n started_at: string;\n finished_at?: string | null;\n}\n\n/** Runtime v0.5.0 full worklog detail returned by `GET /worklog/{task_id}`. */\nexport interface WorklogDetail extends WorklogSummary {\n final_result?: string | null;\n error_message?: string | null;\n}\n\n/** Runtime v0.5.0 single worklog event returned by `GET /worklog/{task_id}/events`. */\nexport interface WorklogEventDetail {\n id: number;\n task_id: string;\n previous_hash?: string | null;\n entry_hash?: string | null;\n event_class: string;\n control_id?: string | null;\n status?: string | null;\n data?: unknown;\n submitted_at: string;\n}\n\n/** Runtime v0.5.0 paginated list of worklog summaries. */\nexport interface WorklogPage {\n items: WorklogSummary[];\n total: number;\n limit: number;\n offset: number;\n}\n\n/** Runtime v0.5.0 paginated list of worklog events for a single task. */\nexport interface WorklogEventPage {\n task_id: string;\n items: WorklogEventDetail[];\n total: number;\n}\n\n/** Runtime v0.5.0 hash-chain verification result returned by `GET /worklog/{task_id}/verify`. */\nexport interface WorklogVerificationResult {\n valid: boolean;\n task_id: string;\n event_count: number;\n first_broken_event_id?: number | null;\n first_broken_index?: number | null;\n expected_hash?: string | null;\n actual_hash?: string | null;\n message: string;\n}\n\n/** Semantic bucket a node belongs to. */\nexport type NodeKind =\n | \"safeguard\"\n | \"reasoning\"\n | \"tool\"\n | \"a2a\"\n | \"memory\"\n | \"answer\"\n | \"unknown\";\n\n/** Lifecycle state of a single node. */\nexport type NodeStatus = \"pending\" | \"running\" | \"completed\" | \"failed\" | \"skipped\";\n\n/** Overall run status. */\nexport type RunStatus = \"idle\" | \"running\" | \"success\" | \"error\";\n\n/** A single step in the execution chain (command + its response merged by control_id). */\nexport interface WorklogNode {\n id: string;\n kind: NodeKind;\n eventClass: string;\n status: NodeStatus;\n title: string;\n startedAt?: string;\n endedAt?: string;\n depth: number;\n parentId?: string;\n children: WorklogNode[];\n command?: unknown;\n response?: unknown;\n error?: string;\n raw: WorklogRecord[];\n}\n\n/** Normalized execution model produced by the reducer. */\nexport interface WorklogState {\n taskId: string | null;\n status: RunStatus;\n answer: string | null;\n nodes: WorklogNode[];\n index: Record<string, number>;\n raw: WorklogRecord[];\n}\n\n/** How a record acts on the model. */\nexport type EventRole = \"open\" | \"close\" | \"run-open\" | \"run-close\" | \"ignore\";\n\n/** Registry descriptor for one event_class. */\nexport interface EventInterpreter {\n kind: NodeKind;\n role: EventRole;\n title: (_record: WorklogRecord) => string;\n /** If true, an opened node starts in \"pending\" (awaiting external input) rather than \"running\". */\n pending?: boolean;\n}\n\nexport function initialWorklogState(taskId: string | null = null): WorklogState {\n return { taskId, status: \"idle\", answer: null, nodes: [], index: {}, raw: [] };\n}\n","import type { EventInterpreter, WorklogRecord } from \"./types\";\n\nconst asRecord = (data: unknown): Record<string, unknown> =>\n data && typeof data === \"object\" ? (data as Record<string, unknown>) : {};\n\nconst toolTitle = (r: WorklogRecord): string => {\n const name = asRecord(r.data).name;\n return typeof name === \"string\" && name.length > 0 ? `Tool: ${name}` : \"Tool\";\n};\n\nconst agentTitle = (r: WorklogRecord): string => {\n const name = asRecord(r.data).name;\n return typeof name === \"string\" && name.length > 0 ? `Agent: ${name}` : \"Agent-to-agent\";\n};\n\nconst constTitle = (label: string) => () => label;\n\nexport const EVENT_REGISTRY: Record<string, EventInterpreter> = {\n // Run envelope\n AssistantInference: { kind: \"answer\", role: \"run-open\", title: constTitle(\"Inference started\") },\n AssistantInferenceResponse: { kind: \"answer\", role: \"run-close\", title: constTitle(\"Answer\") },\n\n // Safeguard\n ShieldInference: { kind: \"safeguard\", role: \"open\", title: constTitle(\"Safeguard\") },\n ShieldInferenceResponse: { kind: \"safeguard\", role: \"close\", title: constTitle(\"Safeguard\") },\n\n // Reasoning\n ResponseInference: { kind: \"reasoning\", role: \"open\", title: constTitle(\"Reasoning\") },\n ResponseInferenceResponse: { kind: \"reasoning\", role: \"close\", title: constTitle(\"Reasoning\") },\n\n // Tools (server + subclasses) and their responses\n ServerToolExecution: { kind: \"tool\", role: \"open\", title: toolTitle },\n BuiltinToolExecution: { kind: \"tool\", role: \"open\", title: toolTitle },\n UnknownToolExecution: { kind: \"tool\", role: \"open\", title: toolTitle },\n ClientToolExecution: { kind: \"tool\", role: \"open\", title: toolTitle, pending: true },\n ToolExecutionResponse: { kind: \"tool\", role: \"close\", title: toolTitle },\n BuiltinToolExecutionResponse: { kind: \"tool\", role: \"close\", title: toolTitle },\n\n // Tool schema discovery\n ToolSchema: { kind: \"tool\", role: \"open\", title: constTitle(\"Tool schema\") },\n ToolSchemaResponse: { kind: \"tool\", role: \"close\", title: constTitle(\"Tool schema\") },\n\n // Agent-to-agent\n A2AInference: { kind: \"a2a\", role: \"open\", title: agentTitle },\n AgentDiscovery: { kind: \"a2a\", role: \"open\", title: constTitle(\"Agent discovery\") },\n AgentDiscoveryResponse: { kind: \"a2a\", role: \"close\", title: constTitle(\"Agent discovery\") },\n\n // Memory / persistence\n ContextPersistence: { kind: \"memory\", role: \"open\", title: constTitle(\"Memory persistence\") },\n ContextFlush: { kind: \"memory\", role: \"open\", title: constTitle(\"Memory flush\") },\n ContextFlushResponse: { kind: \"memory\", role: \"close\", title: constTitle(\"Memory flush\") },\n\n // Human approval\n HumanApprovalRequired: {\n kind: \"tool\",\n role: \"open\",\n title: constTitle(\"Human approval required\"),\n pending: true,\n },\n HumanApprovalRequiredResponse: { kind: \"tool\", role: \"close\", title: constTitle(\"Human approval\") },\n};\n\nexport function resolveInterpreter(eventClass: string): EventInterpreter {\n if (Object.prototype.hasOwnProperty.call(EVENT_REGISTRY, eventClass)) {\n return EVENT_REGISTRY[eventClass];\n }\n return {\n kind: \"unknown\",\n role: \"open\",\n title: (r: WorklogRecord) => r.event_class,\n };\n}\n","import { resolveInterpreter } from \"./registry\";\nimport type { EventInterpreter, WorklogNode, WorklogRecord, WorklogState } from \"./types\";\nimport { initialWorklogState } from \"./types\";\n\nconst asString = (v: unknown): string =>\n typeof v === \"string\" ? v : v == null ? \"\" : JSON.stringify(v);\n\nconst nodeDepth = (record: WorklogRecord): number => {\n const d = record.data && typeof record.data === \"object\"\n ? (record.data as Record<string, unknown>).depth\n : undefined;\n return typeof d === \"number\" ? d : 0;\n};\n\nconst makeOpenNode = (record: WorklogRecord, interp: EventInterpreter, id: string): WorklogNode => ({\n id,\n kind: interp.kind,\n eventClass: record.event_class,\n status: interp.pending ? \"pending\" : \"running\",\n title: interp.title(record),\n startedAt: record.date_submitted,\n depth: nodeDepth(record),\n children: [],\n command: record.data,\n raw: [record],\n});\n\nconst makeClosedNode = (record: WorklogRecord, interp: EventInterpreter, id: string): WorklogNode => ({\n id,\n kind: interp.kind,\n eventClass: record.event_class,\n status: record.status === \"error\" ? \"failed\" : \"completed\",\n title: interp.title(record),\n startedAt: record.date_submitted,\n endedAt: record.date_submitted,\n depth: nodeDepth(record),\n children: [],\n response: record.data,\n error: record.status === \"error\" ? asString(record.data) : undefined,\n raw: [record],\n});\n\nexport function reduceWorklog(state: WorklogState, record: WorklogRecord): WorklogState {\n const interp = resolveInterpreter(record.event_class);\n const next: WorklogState = {\n ...state,\n nodes: state.nodes.slice(),\n index: { ...state.index },\n raw: [...state.raw, record],\n };\n\n if (interp.role === \"ignore\") return next;\n\n if (interp.role === \"run-open\") {\n next.status = \"running\";\n return next;\n }\n\n if (interp.role === \"run-close\") {\n next.answer = asString(record.data) || null;\n next.status = record.status === \"error\" ? \"error\" : \"success\";\n return next;\n }\n\n const key = record.control_id ?? `${record.event_class}-${next.raw.length}`;\n\n if (interp.role === \"close\") {\n const pos = Object.prototype.hasOwnProperty.call(next.index, key) ? next.index[key] : undefined;\n if (pos != null) {\n const existing = next.nodes[pos];\n next.nodes[pos] = {\n ...existing,\n status: record.status === \"error\" ? \"failed\" : \"completed\",\n endedAt: record.date_submitted,\n response: record.data,\n error: record.status === \"error\" ? asString(record.data) : existing.error,\n raw: [...existing.raw, record],\n };\n } else {\n // response arrived without a seen command — create it already closed\n next.index[key] = next.nodes.length;\n next.nodes.push(makeClosedNode(record, interp, key));\n }\n if (record.status === \"error\") next.status = \"error\";\n return next;\n }\n\n // role === \"open\"\n const pos = Object.prototype.hasOwnProperty.call(next.index, key) ? next.index[key] : undefined;\n if (pos != null) {\n const existing = next.nodes[pos];\n next.nodes[pos] = { ...existing, raw: [...existing.raw, record] };\n } else {\n next.index[key] = next.nodes.length;\n next.nodes.push(makeOpenNode(record, interp, key));\n }\n return next;\n}\n\nexport function foldWorklog(records: WorklogRecord[], taskId: string | null = null): WorklogState {\n return records.reduce(reduceWorklog, initialWorklogState(taskId));\n}\n","import { useCallback, useReducer } from \"react\";\nimport { reduceWorklog } from \"./reducer\";\nimport { initialWorklogState, type WorklogRecord, type WorklogState } from \"./types\";\n\ntype Action =\n | { type: \"ingest\"; record: WorklogRecord }\n | { type: \"ingestMany\"; records: WorklogRecord[] }\n | { type: \"reset\"; taskId: string | null };\n\nfunction hookReducer(state: WorklogState, action: Action): WorklogState {\n switch (action.type) {\n case \"ingest\":\n return reduceWorklog(state, action.record);\n case \"ingestMany\":\n return action.records.reduce(reduceWorklog, state);\n case \"reset\":\n return initialWorklogState(action.taskId);\n }\n}\n\n/** Live worklog accumulator. Feed it `bus_mode` records via `ingest`; use `foldWorklog` for history. */\nexport function useWorklog(taskId: string | null = null) {\n const [worklog, dispatch] = useReducer(hookReducer, taskId, initialWorklogState);\n\n const ingest = useCallback((record: WorklogRecord) => dispatch({ type: \"ingest\", record }), []);\n const ingestMany = useCallback(\n (records: WorklogRecord[]) => dispatch({ type: \"ingestMany\", records }),\n [],\n );\n const reset = useCallback(\n (id: string | null = null) => dispatch({ type: \"reset\", taskId: id }),\n [],\n );\n\n return { worklog, ingest, ingestMany, reset };\n}\n","import type { WorklogRecord } from \"./types\";\n\n/** Loosely-typed shape of a parsed SSE `data:` frame from the granular Runtime stream. */\nexport interface RawFrame {\n event_class?: string;\n control_id?: string | null;\n data?: unknown;\n status?: string | null;\n date_submitted?: string;\n /** Runtime v0.5.0+ tamper-evident hash chain fields. */\n entry_hash?: string | null;\n previous_hash?: string | null;\n}\n\n/** Normalize a parsed SSE frame into a WorklogRecord (defaults missing fields; never throws). */\nexport function frameToRecord(frame: RawFrame): WorklogRecord {\n const status = frame.status === \"success\" || frame.status === \"error\" ? frame.status : null;\n return {\n event_class: typeof frame.event_class === \"string\" && frame.event_class.length > 0\n ? frame.event_class\n : \"Unknown\",\n control_id: frame.control_id ?? null,\n data: frame.data,\n status,\n date_submitted: typeof frame.date_submitted === \"string\" ? frame.date_submitted : \"\",\n entry_hash: frame.entry_hash ?? null,\n previous_hash: frame.previous_hash ?? null,\n };\n}\n"],"mappings":";AAiIO,SAAS,oBAAoB,SAAwB,MAAoB;AAC9E,SAAO,EAAE,QAAQ,QAAQ,QAAQ,QAAQ,MAAM,OAAO,CAAC,GAAG,OAAO,CAAC,GAAG,KAAK,CAAC,EAAE;AAC/E;;;ACjIA,IAAM,WAAW,CAAC,SAChB,QAAQ,OAAO,SAAS,WAAY,OAAmC,CAAC;AAE1E,IAAM,YAAY,CAAC,MAA6B;AAC9C,QAAM,OAAO,SAAS,EAAE,IAAI,EAAE;AAC9B,SAAO,OAAO,SAAS,YAAY,KAAK,SAAS,IAAI,SAAS,IAAI,KAAK;AACzE;AAEA,IAAM,aAAa,CAAC,MAA6B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H,aAAO,OAAO,QAAQ,OAAO,eAAe,KAAK;AAAA,IACnD,KAAK;AACH,aAAO,oBAAoB,OAAO,MAAM;AAAA,EAC5C;AACF;AAGO,SAAS,WAAW,SAAwB,MAAM;AACvD,QAAM,CAAC,SAAS,QAAQ,IAAI,WAAW,aAAa,QAAQ,mBAAmB;AAE/E,QAAM,SAAS,YAAY,CAAC,WAA0B,SAAS,EAAE,MAAM,UAAU,OAAO,CAAC,GAAG,CAAC,CAAC;AAC9F,QAAM,aAAa;AAAA,IACjB,CAAC,YAA6B,SAAS,EAAE,MAAM,cAAc,QAAQ,CAAC;AAAA,IACtE,CAAC;AAAA,EACH;AACA,QAAM,QAAQ;AAAA,IACZ,CAAC,KAAoB,SAAS,SAAS,EAAE,MAAM,SAAS,QAAQ,GAAG,CAAC;AAAA,IACpE,CAAC;AAAA,EACH;AAEA,SAAO,EAAE,SAAS,QAAQ,YAAY,MAAM;AAC9C;;;ACpBO,SAAS,cAAc,OAAgC;AAC5D,QAAM,SAAS,MAAM,WAAW,aAAa,MAAM,WAAW,UAAU,MAAM,SAAS;AACvF,SAAO;AAAA,IACL,aAAa,OAAO,MAAM,gBAAgB,YAAY,MAAM,YAAY,SAAS,IAC7E,MAAM,cACN;AAAA,IACJ,YAAY,MAAM,cAAc;AAAA,IAChC,MAAM,MAAM;AAAA,IACZ;AAAA,IACA,gBAAgB,OAAO,MAAM,mBAAmB,WAAW,MAAM,iBAAiB;AAAA,IAClF,YAAY,MAAM,cAAc;AAAA,IAChC,eAAe,MAAM,iBAAiB;AAAA,EACxC;AACF;","names":["pos"]}
|
|
1
|
+
{"version":3,"sources":["../../src/worklog/types.ts","../../src/worklog/registry.ts","../../src/worklog/reducer.ts","../../src/worklog/use-worklog.ts","../../src/worklog/from-frame.ts","../../src/worklog/approvals.ts"],"sourcesContent":["/** One granular Runtime worklog record (a `bus_mode` SSE frame or a `/worklog/{task_id}/events` item). */\nexport interface WorklogRecord {\n /** Runtime v0.5.0+ tamper-evident hash chain fields (optional on SSE frames). */\n entry_hash?: string | null;\n previous_hash?: string | null;\n event_class: string;\n control_id: string | null;\n data: unknown;\n status: \"success\" | \"error\" | null;\n date_submitted: string;\n}\n\n/** Runtime v0.5.0 worklog audit summary returned by `GET /worklog/`. */\nexport interface WorklogSummary {\n task_id: string;\n parent_task_id?: string | null;\n session_id?: string | null;\n user_id?: string | null;\n assistant_id?: string | null;\n agentspace_id?: string | null;\n channel_id?: string | null;\n depth?: number;\n final_status?: string | null;\n started_at: string;\n finished_at?: string | null;\n}\n\n/** Runtime v0.5.0 full worklog detail returned by `GET /worklog/{task_id}`. */\nexport interface WorklogDetail extends WorklogSummary {\n final_result?: string | null;\n error_message?: string | null;\n}\n\n/** Runtime v0.5.0 single worklog event returned by `GET /worklog/{task_id}/events`. */\nexport interface WorklogEventDetail {\n id: number;\n task_id: string;\n previous_hash?: string | null;\n entry_hash?: string | null;\n event_class: string;\n control_id?: string | null;\n status?: string | null;\n data?: unknown;\n submitted_at: string;\n}\n\n/** Runtime v0.5.0 paginated list of worklog summaries. */\nexport interface WorklogPage {\n items: WorklogSummary[];\n total: number;\n limit: number;\n offset: number;\n}\n\n/** Runtime v0.5.0 paginated list of worklog events for a single task. */\nexport interface WorklogEventPage {\n task_id: string;\n items: WorklogEventDetail[];\n total: number;\n}\n\n/** Runtime v0.5.0 hash-chain verification result returned by `GET /worklog/{task_id}/verify`. */\nexport interface WorklogVerificationResult {\n valid: boolean;\n task_id: string;\n event_count: number;\n first_broken_event_id?: number | null;\n first_broken_index?: number | null;\n expected_hash?: string | null;\n actual_hash?: string | null;\n message: string;\n}\n\n/** Semantic bucket a node belongs to. */\nexport type NodeKind =\n | \"safeguard\"\n | \"reasoning\"\n | \"tool\"\n | \"a2a\"\n | \"memory\"\n | \"knowledge\"\n | \"speech\"\n | \"answer\"\n | \"unknown\";\n\n/** Lifecycle state of a single node. */\nexport type NodeStatus = \"pending\" | \"running\" | \"completed\" | \"failed\" | \"skipped\";\n\n/** Overall run status. */\nexport type RunStatus = \"idle\" | \"running\" | \"success\" | \"error\";\n\n/** A single step in the execution chain (command + its response merged by control_id). */\nexport interface WorklogNode {\n id: string;\n kind: NodeKind;\n eventClass: string;\n status: NodeStatus;\n title: string;\n startedAt?: string;\n endedAt?: string;\n depth: number;\n parentId?: string;\n children: WorklogNode[];\n command?: unknown;\n response?: unknown;\n error?: string;\n raw: WorklogRecord[];\n}\n\n/** Normalized execution model produced by the reducer. */\nexport interface WorklogState {\n taskId: string | null;\n status: RunStatus;\n answer: string | null;\n nodes: WorklogNode[];\n index: Record<string, number>;\n raw: WorklogRecord[];\n}\n\n/** How a record acts on the model. */\nexport type EventRole = \"open\" | \"close\" | \"run-open\" | \"run-close\" | \"ignore\";\n\n/** Registry descriptor for one event_class. */\nexport interface EventInterpreter {\n kind: NodeKind;\n role: EventRole;\n title: (_record: WorklogRecord) => string;\n /** If true, an opened node starts in \"pending\" (awaiting external input) rather than \"running\". */\n pending?: boolean;\n}\n\nexport function initialWorklogState(taskId: string | null = null): WorklogState {\n return { taskId, status: \"idle\", answer: null, nodes: [], index: {}, raw: [] };\n}\n","import type { EventInterpreter, WorklogRecord } from \"./types\";\n\nconst asRecord = (data: unknown): Record<string, unknown> =>\n data && typeof data === \"object\" ? (data as Record<string, unknown>) : {};\n\nconst toolTitle = (r: WorklogRecord): string => {\n const name = asRecord(r.data).name;\n return typeof name === \"string\" && name.length > 0 ? `Tool: ${name}` : \"Tool\";\n};\n\nconst agentTitle = (r: WorklogRecord): string => {\n const name = asRecord(r.data).name;\n return typeof name === \"string\" && name.length > 0 ? `Agent: ${name}` : \"Agent-to-agent\";\n};\n\nconst constTitle = (label: string) => () => label;\n\n// The approval gate wraps the parked tool execution in `parameters`.\nconst approvalTitle = (r: WorklogRecord): string => {\n const name = asRecord(asRecord(r.data).parameters).name;\n return typeof name === \"string\" && name.length > 0\n ? `Approval required: ${name}`\n : \"Human approval required\";\n};\n\nconst shieldBlockTitle = (r: WorklogRecord): string => {\n const id = asRecord(r.data).shield_id;\n return typeof id === \"string\" && id.length > 0 ? `Blocked by ${id}` : \"Blocked by safeguard\";\n};\n\nconst knowledgeTitle = (r: WorklogRecord): string => {\n const query = asRecord(r.data).query;\n return typeof query === \"string\" && query.length > 0\n ? `Knowledge: ${query}`\n : \"Knowledge retrieval\";\n};\n\nexport const EVENT_REGISTRY: Record<string, EventInterpreter> = {\n // Run envelope\n AssistantInference: { kind: \"answer\", role: \"run-open\", title: constTitle(\"Inference started\") },\n AssistantInferenceResponse: { kind: \"answer\", role: \"run-close\", title: constTitle(\"Answer\") },\n\n // Safeguard\n ShieldInference: { kind: \"safeguard\", role: \"open\", title: constTitle(\"Safeguard\") },\n ShieldInferenceResponse: { kind: \"safeguard\", role: \"close\", title: constTitle(\"Safeguard\") },\n // Emitted when a shield enforcement decision blocks the request (core 0.5.x).\n // Response-only: the reducer opens it already closed when no command matched.\n ShieldBlockedResponse: { kind: \"safeguard\", role: \"close\", title: shieldBlockTitle },\n\n // Reasoning\n ResponseInference: { kind: \"reasoning\", role: \"open\", title: constTitle(\"Reasoning\") },\n ResponseInferenceResponse: { kind: \"reasoning\", role: \"close\", title: constTitle(\"Reasoning\") },\n\n // Tools (server + subclasses) and their responses\n ServerToolExecution: { kind: \"tool\", role: \"open\", title: toolTitle },\n BuiltinToolExecution: { kind: \"tool\", role: \"open\", title: toolTitle },\n UnknownToolExecution: { kind: \"tool\", role: \"open\", title: toolTitle },\n ClientToolExecution: { kind: \"tool\", role: \"open\", title: toolTitle, pending: true },\n ToolExecutionResponse: { kind: \"tool\", role: \"close\", title: toolTitle },\n BuiltinToolExecutionResponse: { kind: \"tool\", role: \"close\", title: toolTitle },\n\n // Tool schema discovery\n ToolSchema: { kind: \"tool\", role: \"open\", title: constTitle(\"Tool schema\") },\n ToolSchemaResponse: { kind: \"tool\", role: \"close\", title: constTitle(\"Tool schema\") },\n\n // Agent-to-agent\n A2AInference: { kind: \"a2a\", role: \"open\", title: agentTitle },\n AgentDiscovery: { kind: \"a2a\", role: \"open\", title: constTitle(\"Agent discovery\") },\n AgentDiscoveryResponse: { kind: \"a2a\", role: \"close\", title: constTitle(\"Agent discovery\") },\n\n // Knowledge retrieval (RAG) — core 0.5.x\n KnowledgeRetrieval: { kind: \"knowledge\", role: \"open\", title: knowledgeTitle },\n KnowledgeRetrievalResponse: { kind: \"knowledge\", role: \"close\", title: knowledgeTitle },\n\n // Speech pipeline — core 0.5.x\n SpeechTranscription: { kind: \"speech\", role: \"open\", title: constTitle(\"Speech-to-text\") },\n SpeechTranscriptionResponse: { kind: \"speech\", role: \"close\", title: constTitle(\"Speech-to-text\") },\n SpeechSynthesis: { kind: \"speech\", role: \"open\", title: constTitle(\"Text-to-speech\") },\n SpeechSynthesisResponse: { kind: \"speech\", role: \"close\", title: constTitle(\"Text-to-speech\") },\n\n // Memory / persistence\n ContextPersistence: { kind: \"memory\", role: \"open\", title: constTitle(\"Memory persistence\") },\n ContextFlush: { kind: \"memory\", role: \"open\", title: constTitle(\"Memory flush\") },\n ContextFlushResponse: { kind: \"memory\", role: \"close\", title: constTitle(\"Memory flush\") },\n\n // Human approval\n HumanApprovalRequired: {\n kind: \"tool\",\n role: \"open\",\n title: approvalTitle,\n pending: true,\n },\n HumanApprovalRequiredResponse: { kind: \"tool\", role: \"close\", title: constTitle(\"Human approval\") },\n};\n\nexport function resolveInterpreter(eventClass: string): EventInterpreter {\n if (Object.prototype.hasOwnProperty.call(EVENT_REGISTRY, eventClass)) {\n return EVENT_REGISTRY[eventClass];\n }\n return {\n kind: \"unknown\",\n role: \"open\",\n title: (r: WorklogRecord) => r.event_class,\n };\n}\n","import { resolveInterpreter } from \"./registry\";\nimport type { EventInterpreter, WorklogNode, WorklogRecord, WorklogState } from \"./types\";\nimport { initialWorklogState } from \"./types\";\n\nconst asString = (v: unknown): string =>\n typeof v === \"string\" ? v : v == null ? \"\" : JSON.stringify(v);\n\nconst nodeDepth = (record: WorklogRecord): number => {\n const d = record.data && typeof record.data === \"object\"\n ? (record.data as Record<string, unknown>).depth\n : undefined;\n return typeof d === \"number\" ? d : 0;\n};\n\nconst makeOpenNode = (record: WorklogRecord, interp: EventInterpreter, id: string): WorklogNode => ({\n id,\n kind: interp.kind,\n eventClass: record.event_class,\n status: interp.pending ? \"pending\" : \"running\",\n title: interp.title(record),\n startedAt: record.date_submitted,\n depth: nodeDepth(record),\n children: [],\n command: record.data,\n raw: [record],\n});\n\nconst makeClosedNode = (record: WorklogRecord, interp: EventInterpreter, id: string): WorklogNode => ({\n id,\n kind: interp.kind,\n eventClass: record.event_class,\n status: record.status === \"error\" ? \"failed\" : \"completed\",\n title: interp.title(record),\n startedAt: record.date_submitted,\n endedAt: record.date_submitted,\n depth: nodeDepth(record),\n children: [],\n response: record.data,\n error: record.status === \"error\" ? asString(record.data) : undefined,\n raw: [record],\n});\n\nexport function reduceWorklog(state: WorklogState, record: WorklogRecord): WorklogState {\n const interp = resolveInterpreter(record.event_class);\n const next: WorklogState = {\n ...state,\n nodes: state.nodes.slice(),\n index: { ...state.index },\n raw: [...state.raw, record],\n };\n\n if (interp.role === \"ignore\") return next;\n\n if (interp.role === \"run-open\") {\n next.status = \"running\";\n return next;\n }\n\n if (interp.role === \"run-close\") {\n next.answer = asString(record.data) || null;\n next.status = record.status === \"error\" ? \"error\" : \"success\";\n return next;\n }\n\n const key = record.control_id ?? `${record.event_class}-${next.raw.length}`;\n\n if (interp.role === \"close\") {\n const pos = Object.prototype.hasOwnProperty.call(next.index, key) ? next.index[key] : undefined;\n if (pos != null) {\n const existing = next.nodes[pos];\n next.nodes[pos] = {\n ...existing,\n status: record.status === \"error\" ? \"failed\" : \"completed\",\n endedAt: record.date_submitted,\n response: record.data,\n error: record.status === \"error\" ? asString(record.data) : existing.error,\n raw: [...existing.raw, record],\n };\n } else {\n // response arrived without a seen command — create it already closed\n next.index[key] = next.nodes.length;\n next.nodes.push(makeClosedNode(record, interp, key));\n }\n if (record.status === \"error\") next.status = \"error\";\n return next;\n }\n\n // role === \"open\"\n const pos = Object.prototype.hasOwnProperty.call(next.index, key) ? next.index[key] : undefined;\n if (pos != null) {\n const existing = next.nodes[pos];\n // The command can arrive after its response (the node was opened closed);\n // keep the status, but fill in what the command says it was.\n next.nodes[pos] = {\n ...existing,\n command: existing.command ?? record.data,\n title: existing.command === undefined ? interp.title(record) : existing.title,\n raw: [...existing.raw, record],\n };\n } else {\n next.index[key] = next.nodes.length;\n next.nodes.push(makeOpenNode(record, interp, key));\n }\n return next;\n}\n\nexport function foldWorklog(records: WorklogRecord[], taskId: string | null = null): WorklogState {\n return records.reduce(reduceWorklog, initialWorklogState(taskId));\n}\n","import { useCallback, useReducer } from \"react\";\nimport { reduceWorklog } from \"./reducer\";\nimport { initialWorklogState, type WorklogRecord, type WorklogState } from \"./types\";\n\ntype Action =\n | { type: \"ingest\"; record: WorklogRecord }\n | { type: \"ingestMany\"; records: WorklogRecord[] }\n | { type: \"reset\"; taskId: string | null };\n\nfunction hookReducer(state: WorklogState, action: Action): WorklogState {\n switch (action.type) {\n case \"ingest\":\n return reduceWorklog(state, action.record);\n case \"ingestMany\":\n return action.records.reduce(reduceWorklog, state);\n case \"reset\":\n return initialWorklogState(action.taskId);\n }\n}\n\n/** Live worklog accumulator. Feed it `bus_mode` records via `ingest`; use `foldWorklog` for history. */\nexport function useWorklog(taskId: string | null = null) {\n const [worklog, dispatch] = useReducer(hookReducer, taskId, initialWorklogState);\n\n const ingest = useCallback((record: WorklogRecord) => dispatch({ type: \"ingest\", record }), []);\n const ingestMany = useCallback(\n (records: WorklogRecord[]) => dispatch({ type: \"ingestMany\", records }),\n [],\n );\n const reset = useCallback(\n (id: string | null = null) => dispatch({ type: \"reset\", taskId: id }),\n [],\n );\n\n return { worklog, ingest, ingestMany, reset };\n}\n","import type { WorklogRecord } from \"./types\";\n\n/** Loosely-typed shape of a parsed SSE `data:` frame from the granular Runtime stream. */\nexport interface RawFrame {\n event_class?: string;\n control_id?: string | null;\n data?: unknown;\n status?: string | null;\n date_submitted?: string;\n /** Runtime v0.5.0+ tamper-evident hash chain fields. */\n entry_hash?: string | null;\n previous_hash?: string | null;\n}\n\n/** Normalize a parsed SSE frame into a WorklogRecord (defaults missing fields; never throws). */\nexport function frameToRecord(frame: RawFrame): WorklogRecord {\n const status = frame.status === \"success\" || frame.status === \"error\" ? frame.status : null;\n return {\n event_class: typeof frame.event_class === \"string\" && frame.event_class.length > 0\n ? frame.event_class\n : \"Unknown\",\n control_id: frame.control_id ?? null,\n data: frame.data,\n status,\n date_submitted: typeof frame.date_submitted === \"string\" ? frame.date_submitted : \"\",\n entry_hash: frame.entry_hash ?? null,\n previous_hash: frame.previous_hash ?? null,\n };\n}\n","import type { WorklogRecord } from \"./types\";\n\n/**\n * Human-approval gates, derived from the worklog.\n *\n * When the runtime's authz policy resolves a tool call to `REQUIRE_APPROVAL`,\n * core parks the call and records a `HumanApprovalRequired` whose `data` is the\n * command minus its conversation: `{ parameters: <the tool execution> }`. The\n * gate closes with a `HumanApprovalRequiredResponse` under the same\n * `control_id`, whichever channel the decision came through — so the stream,\n * not the local submit, is the source of truth for \"settled\".\n */\n\n/** A decision as the worklog records it. */\nexport interface ApprovalDecision {\n approved: boolean;\n /**\n * Rejection reason. Core records `result or message` as the response data,\n * so an approval never carries one and a rejection carries the reason when\n * the approver gave it.\n */\n reason: string | null;\n decidedAt: string;\n}\n\n/** One approval gate, pending or settled. */\nexport interface ApprovalRequest {\n /** The `HumanApprovalRequired` control id — the one `/event/tool-approval` expects. */\n controlId: string;\n /** Name of the parked tool call; `null` until the request record is seen. */\n toolName: string | null;\n /** Control id of the parked tool execution itself (distinct from `controlId`). */\n toolCallId: string | null;\n /** Arguments the tool would be called with. What is actually being approved. */\n arguments: unknown;\n /**\n * The gate belongs to an MCP server that runs its own approval over the\n * task's originating channel (the `mcp_approval` runtime extension). The\n * runtime refuses an HTTP decision for it with a 409, so offering buttons\n * would be a lie.\n */\n channelOwned: boolean;\n requestedAt: string | null;\n /** `null` while pending. */\n decision: ApprovalDecision | null;\n}\n\nexport interface ApprovalsState {\n /** Gates in the order they were first seen. */\n order: string[];\n byId: Record<string, ApprovalRequest>;\n}\n\nexport function initialApprovalsState(): ApprovalsState {\n return { order: [], byId: {} };\n}\n\nconst asObject = (v: unknown): Record<string, unknown> | null =>\n v && typeof v === \"object\" && !Array.isArray(v) ? (v as Record<string, unknown>) : null;\n\nconst MCP_APPROVAL_EXTENSION = \"mcp_approval\";\n\nfunction describeRequest(record: WorklogRecord) {\n const execution = asObject(asObject(record.data)?.parameters) ?? {};\n const name = execution.name;\n const callId = execution.control_id;\n // Server tools keep their config in `parameters` and the LLM's arguments in\n // `tool_call_parameters`; client and builtin tools put the arguments in\n // `parameters` directly.\n const args =\n execution.tool_call_parameters !== undefined && execution.tool_call_parameters !== null\n ? execution.tool_call_parameters\n : execution.parameters;\n const extensions = asObject(execution.parameters)?.runtime_extensions;\n return {\n toolName: typeof name === \"string\" && name.length > 0 ? name : null,\n toolCallId: typeof callId === \"string\" ? callId : null,\n arguments: args ?? null,\n channelOwned: Array.isArray(extensions) && extensions.includes(MCP_APPROVAL_EXTENSION),\n };\n}\n\nfunction describeDecision(record: WorklogRecord): ApprovalDecision {\n const approved = record.data === true;\n return {\n approved,\n reason: !approved && typeof record.data === \"string\" && record.data.length > 0 ? record.data : null,\n decidedAt: record.date_submitted,\n };\n}\n\nconst blank = (controlId: string): ApprovalRequest => ({\n controlId,\n toolName: null,\n toolCallId: null,\n arguments: null,\n channelOwned: false,\n requestedAt: null,\n decision: null,\n});\n\n/** Fold one worklog record into the approvals state. Records of other classes are a no-op. */\nexport function reduceApprovals(state: ApprovalsState, record: WorklogRecord): ApprovalsState {\n const isRequest = record.event_class === \"HumanApprovalRequired\";\n const isResponse = record.event_class === \"HumanApprovalRequiredResponse\";\n if ((!isRequest && !isResponse) || !record.control_id) return state;\n\n const id = record.control_id;\n const known = state.byId[id];\n const current = known ?? blank(id);\n\n // A response can overtake its request (bus redelivery, a replayed history).\n // Either order lands on the same settled entry: the request only fills in\n // what is being approved and never reopens a decision.\n const next: ApprovalRequest = isRequest\n ? { ...current, ...describeRequest(record), requestedAt: record.date_submitted }\n : { ...current, decision: current.decision ?? describeDecision(record) };\n\n return {\n order: known ? state.order : [...state.order, id],\n byId: { ...state.byId, [id]: next },\n };\n}\n\nexport function foldApprovals(records: WorklogRecord[]): ApprovalsState {\n return records.reduce(reduceApprovals, initialApprovalsState());\n}\n\n/** All gates, in first-seen order. */\nexport function listApprovals(state: ApprovalsState): ApprovalRequest[] {\n return state.order.map((id) => state.byId[id]);\n}\n\n/** Gates with no recorded decision yet. */\nexport function pendingApprovals(state: ApprovalsState): ApprovalRequest[] {\n return listApprovals(state).filter((a) => a.decision === null);\n}\n"],"mappings":";AAmIO,SAAS,oBAAoB,SAAwB,MAAoB;AAC9E,SAAO,EAAE,QAAQ,QAAQ,QAAQ,QAAQ,MAAM,OAAO,CAAC,GAAG,OAAO,CAAC,GAAG,KAAK,CAAC,EAAE;AAC/E;;;ACnIA,IAAM,WAAW,CAAC,SAChB,QAAQ,OAAO,SAAS,WAAY,OAAmC,CAAC;AAE1E,IAAM,YAAY,CAAC,MAA6B;AAC9C,QAAM,OAAO,SAAS,EAAE,IAAI,EAAE;AAC9B,SAAO,OAAO,SAAS,YAAY,KAAK,SAAS,IAAI,SAAS,IAAI,KAAK;AACzE;AAEA,IAAM,aAAa,CAAC,MAA6B;AAC/C,QAAM,OAAO,SAAS,EAAE,IAAI,EAAE;AAC9B,SAAO,OAAO,SAAS,YAAY,KAAK,SAAS,IAAI,UAAU,IAAI,KAAK;AAC1E;AAEA,IAAM,aAAa,CAAC,UAAkB,MAAM;AAG5C,IAAM,gBAAgB,CAAC,MAA6B;AAClD,QAAM,OAAO,SAAS,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE;AACnD,SAAO,OAAO,SAAS,YAAY,KAAK,SAAS,IAC7C,sBAAsB,IAAI,KAC1B;AACN;AAEA,IAAM,mBAAmB,CAAC,MAA6B;AACrD,QAAM,KAAK,SAAS,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