{"version":3,"file":"lifecycle.cjs","names":["hasPrefix","StreamChannel","nsKey"],"sources":["../../../src/stream/transformers/lifecycle.ts"],"sourcesContent":["/**\n * LifecycleTransformer - synthesizes `lifecycle` channel events that\n * track the status of the root run and every subgraph it spawns.\n *\n * The transformer is registered first in `createGraphRunStream` so that\n * every other transformer / consumer sees a coherent, authoritative\n * lifecycle stream. It is product-agnostic: deeper semantics (e.g.\n * DeepAgents' `SubagentTransformer` tool-call causation) reach the wire\n * by way of the re-entrant {@link StreamEmitter} - the transformer\n * stashes any `cause` attached upstream and re-emits its own\n * authoritative `lifecycle.started` with the correlation in place.\n *\n * Events are also pushed to a local {@link StreamChannel} so in-process\n * consumers can iterate `run.lifecycle` without filtering the main\n * event stream.\n */\n\nimport type {\n  AgentStatus,\n  LifecycleCause,\n  LifecycleData,\n} from \"@langchain/protocol\";\n\nimport { hasPrefix, nsKey } from \"../mux.js\";\nimport { StreamChannel } from \"../stream-channel.js\";\nimport type {\n  NativeStreamTransformer,\n  Namespace,\n  ProtocolEvent,\n  StreamEmitter,\n} from \"../types.js\";\nimport type { LifecycleEntry, LifecycleTransformerOptions } from \"./types.js\";\n\n/**\n * Projection returned from the lifecycle transformer's `init()`.\n *\n * The local `StreamChannel` is closed automatically when the transformer\n * finalizes or fails. `_lifecycleLog` is intentionally underscore-prefixed to\n * signal that it is consumed by the run stream wiring\n * (see `run-stream.ts`) and not meant for direct user access -\n * consumers should read `run.lifecycle` instead.\n *\n * The `lifecycle` iterable is the root-scoped projection (prefix\n * `[]`, starting at offset `0`) mirroring the pattern used by the\n * subgraph discovery transformer.  Root stream wiring consumes it\n * via `SET_LIFECYCLE_ITERABLE`; child streams are wired with their\n * own path-scoped iterable produced by `filterLifecycleEntries`.\n */\nexport interface LifecycleProjection {\n  _lifecycleLog: StreamChannel<LifecycleEntry>;\n  lifecycle: AsyncIterable<LifecycleEntry>;\n}\n\n/**\n * Filter a lifecycle {@link StreamChannel} to only the entries whose\n * namespace lies within the subtree rooted at {@link path}.\n *\n * Returns an `AsyncIterable` whose iterator yields every entry whose\n * namespace either equals {@link path} or is a descendant of it.\n * Iteration begins at {@link startAt}, so callers can capture the\n * log's current size at construction time to skip entries emitted\n * before the caller existed (e.g. a subgraph stream discovered\n * mid-run shouldn't replay the root's `started`).\n *\n * @param log - The shared lifecycle log owned by the transformer.\n * @param path - Namespace prefix to scope entries by (use `[]` for\n *   the root subtree, i.e. everything).\n * @param startAt - Zero-based index into the log to begin from.\n * @returns An async iterable of matching lifecycle entries.\n */\nexport function filterLifecycleEntries(\n  log: StreamChannel<LifecycleEntry>,\n  path: Namespace,\n  startAt = 0\n): AsyncIterable<LifecycleEntry> {\n  return {\n    [Symbol.asyncIterator](): AsyncIterator<LifecycleEntry> {\n      const base = log.iterate(startAt);\n      return {\n        async next(): Promise<IteratorResult<LifecycleEntry>> {\n          // eslint-disable-next-line no-constant-condition\n          while (true) {\n            const result = await base.next();\n            if (result.done) {\n              return {\n                value: undefined as unknown as LifecycleEntry,\n                done: true,\n              };\n            }\n            if (hasPrefix(result.value.namespace, path)) {\n              return { value: result.value, done: false };\n            }\n          }\n        },\n      };\n    },\n  };\n}\n\nconst DEFAULT_ROOT_GRAPH_NAME = \"root\";\n\nfunction defaultGuessGraphName(ns: Namespace): string {\n  if (ns.length === 0) return DEFAULT_ROOT_GRAPH_NAME;\n  const last = ns[ns.length - 1];\n  const colon = last.indexOf(\":\");\n  return colon === -1 ? last : last.slice(0, colon);\n}\n\nfunction defaultSerializeError(err: unknown): string {\n  // oxlint-disable-next-line no-instanceof/no-instanceof\n  if (err instanceof Error) return err.message;\n  if (typeof err === \"string\") return err;\n  try {\n    return JSON.stringify(err);\n  } catch {\n    return String(err);\n  }\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n  return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/**\n * Extract an upstream `cause` from a `lifecycle.started` payload, if\n * the shape matches one of the known variants. Shape validation is\n * intentionally loose: any object with a string `type` is accepted, so\n * future protocol variants flow through unchanged.\n */\nfunction extractCause(data: unknown): LifecycleCause | undefined {\n  if (!isRecord(data)) return undefined;\n  if (data.event !== \"started\") return undefined;\n  const cause = data.cause;\n  if (!isRecord(cause)) return undefined;\n  if (typeof cause.type !== \"string\") return undefined;\n  return cause as unknown as LifecycleCause;\n}\n\nfunction extractTaskResultCompletion(\n  data: unknown\n): TaskResultCompletion | undefined {\n  if (!isRecord(data)) return undefined;\n  if (!(\"result\" in data)) return undefined;\n  if (typeof data.name !== \"string\") return undefined;\n  if (typeof data.id !== \"string\") return undefined;\n  if (data.name.startsWith(\"__\")) return undefined;\n  return { name: data.name, id: data.id };\n}\n\ninterface NamespaceRecord {\n  readonly namespace: Namespace;\n  readonly graphName: string;\n  /** Last emitted status; `undefined` until `emit` fires for this namespace. */\n  status: AgentStatus | undefined;\n}\n\ninterface TaskResultCompletion {\n  readonly name: string;\n  readonly id: string;\n}\n\ninterface PendingCompletion {\n  readonly namespace: Namespace;\n  readonly source:\n    | { readonly type: \"task\" }\n    | {\n        readonly type: \"node\";\n        readonly parent: Namespace;\n        readonly node: string;\n      };\n}\n\n/**\n * Create the built-in lifecycle transformer.\n *\n * Marked as a {@link NativeStreamTransformer} so the run stream\n * factory can expose `_lifecycleLog` via a dedicated getter\n * (`run.lifecycle`) rather than through `run.extensions`.\n */\nexport function createLifecycleTransformer(\n  options: LifecycleTransformerOptions = {}\n): NativeStreamTransformer<LifecycleProjection> {\n  const rootGraphName = options.rootGraphName ?? DEFAULT_ROOT_GRAPH_NAME;\n  const initialStatus: AgentStatus = options.initialStatus ?? \"running\";\n  const emitRootOnRegister = options.emitRootOnRegister ?? true;\n  const getGraphName = options.getGraphName ?? defaultGuessGraphName;\n  const serializeError = options.serializeError ?? defaultSerializeError;\n  const getTerminalStatusOverride = options.getTerminalStatusOverride;\n\n  const log = StreamChannel.local<LifecycleEntry>();\n  const namespaces = new Map<string, NamespaceRecord>();\n  const namespaceCause = new Map<string, LifecycleCause>();\n  const pendingInterruptIds = new Set<string>();\n  /**\n   * Child namespaces whose parent just saw an `updates` event with a\n   * `node` attribution. We defer the `lifecycle.completed` emission\n   * until the *next* inbound event (or `finalize`) so the parent's\n   * `updates` lands on the wire before its child is marked complete -\n   * matching the previous session behavior.\n   */\n  const pendingCompletions: PendingCompletion[] = [];\n\n  let emitter: StreamEmitter | undefined;\n  let inSelfEmit = 0;\n  let finalized = false;\n\n  const resolveGraphName = (ns: Namespace): string =>\n    ns.length === 0 ? rootGraphName : getGraphName(ns);\n\n  const emit = (\n    ns: Namespace,\n    status: AgentStatus,\n    extras?: { cause?: LifecycleCause; error?: string }\n  ): void => {\n    const key = nsKey(ns);\n    let current = namespaces.get(key);\n    const graphName = current?.graphName ?? resolveGraphName(ns);\n\n    // Dedup: identical status + graph name + no error override => skip.\n    if (\n      current != null &&\n      current.status === status &&\n      current.graphName === graphName &&\n      extras?.error == null\n    ) {\n      return;\n    }\n\n    if (current == null) {\n      current = { namespace: ns, graphName, status };\n      namespaces.set(key, current);\n    } else {\n      current.status = status;\n    }\n\n    const data: LifecycleData = {\n      event: status,\n      graph_name: graphName,\n      ...(extras?.cause != null ? { cause: extras.cause } : {}),\n      ...(extras?.error != null ? { error: extras.error } : {}),\n    };\n\n    const timestamp = Date.now();\n\n    log.push({ namespace: ns, timestamp, ...data });\n\n    if (ns.length === 0 && !emitRootOnRegister) return;\n\n    if (emitter == null) return;\n\n    inSelfEmit += 1;\n    try {\n      emitter.push(ns, {\n        type: \"event\",\n        seq: 0,\n        method: \"lifecycle\",\n        params: { namespace: ns, timestamp, data },\n      });\n    } finally {\n      inSelfEmit -= 1;\n    }\n  };\n\n  /**\n   * Ensures a record exists for `ns` without mutating its status. Used\n   * by hooks that need a canonical `graphName` for lookups before emit\n   * writes the first status. Status remains `undefined` until `emit`\n   * fires.\n   */\n  const trackNamespace = (ns: Namespace): NamespaceRecord => {\n    const key = nsKey(ns);\n    let rec = namespaces.get(key);\n    if (rec == null) {\n      rec = {\n        namespace: ns,\n        graphName: resolveGraphName(ns),\n        status: undefined,\n      };\n      namespaces.set(key, rec);\n    }\n    return rec;\n  };\n\n  const flushPendingCompletions = (): void => {\n    if (pendingCompletions.length === 0) return;\n    const toFlush = pendingCompletions.splice(0, pendingCompletions.length);\n    for (const completion of toFlush) {\n      const key = nsKey(completion.namespace);\n      const rec = namespaces.get(key);\n      if (rec == null || rec.status !== \"started\") continue;\n      emit(completion.namespace, \"completed\");\n    }\n  };\n\n  const enqueueCompletion = (completion: PendingCompletion): void => {\n    const key = nsKey(completion.namespace);\n    const rec = namespaces.get(key);\n    if (rec == null || rec.status !== \"started\") return;\n    if (\n      pendingCompletions.some((pending) => nsKey(pending.namespace) === key)\n    ) {\n      return;\n    }\n    pendingCompletions.push(completion);\n  };\n\n  const removePendingNodeCompletions = (\n    parent: Namespace,\n    node: string\n  ): void => {\n    for (let index = pendingCompletions.length - 1; index >= 0; index -= 1) {\n      const pending = pendingCompletions[index];\n      if (pending.source.type !== \"node\") continue;\n      if (pending.source.node !== node) continue;\n      if (nsKey(pending.source.parent) !== nsKey(parent)) continue;\n      pendingCompletions.splice(index, 1);\n    }\n  };\n\n  const ensureStarted = (ns: Namespace): void => {\n    // Synthesize `lifecycle.started` for each unseen prefix of `ns`,\n    // outermost first. Deepest-first would force consumers to see a\n    // child's started before its parent, which is wrong.\n    for (let length = 1; length <= ns.length; length += 1) {\n      const prefix = ns.slice(0, length);\n      const key = nsKey(prefix);\n      if (namespaces.has(key)) continue;\n      trackNamespace(prefix);\n      const cause = namespaceCause.get(key);\n      emit(prefix, \"started\", cause != null ? { cause } : undefined);\n    }\n  };\n\n  const defaultTerminalStatus = (): AgentStatus =>\n    pendingInterruptIds.size > 0 ? \"interrupted\" : \"completed\";\n\n  const cascadeTerminalStatus = (status: AgentStatus): void => {\n    for (const rec of namespaces.values()) {\n      if (rec.namespace.length === 0) continue;\n      if (rec.status !== \"started\") continue;\n      emit(rec.namespace, status);\n    }\n    emit([], status);\n    log.close();\n  };\n\n  const resolveTerminalStatusOverride = async (): Promise<AgentStatus> => {\n    if (getTerminalStatusOverride == null) return defaultTerminalStatus();\n    try {\n      return (await getTerminalStatusOverride()) ?? defaultTerminalStatus();\n    } catch {\n      return defaultTerminalStatus();\n    }\n  };\n\n  const findStartedChildForNode = (\n    parentNamespace: Namespace,\n    node: string\n  ): Namespace | undefined => {\n    const prefix = `${node}:`;\n    for (const rec of namespaces.values()) {\n      if (rec.namespace.length !== parentNamespace.length + 1) continue;\n      if (rec.status !== \"started\") continue;\n      if (!hasPrefix(rec.namespace, parentNamespace)) continue;\n      const last = rec.namespace[rec.namespace.length - 1];\n      if (last === node || last.startsWith(prefix)) return rec.namespace;\n    }\n    return undefined;\n  };\n\n  const findStartedChildForTask = (\n    parentNamespace: Namespace,\n    task: TaskResultCompletion\n  ): Namespace | undefined => {\n    const namespace = [...parentNamespace, `${task.name}:${task.id}`];\n    const rec = namespaces.get(nsKey(namespace));\n    return rec?.status === \"started\" ? namespace : undefined;\n  };\n\n  const transformer: NativeStreamTransformer<LifecycleProjection> = {\n    __native: true,\n\n    init() {\n      return {\n        _lifecycleLog: log,\n        lifecycle: filterLifecycleEntries(log, [], 0),\n      };\n    },\n\n    onRegister(handle: StreamEmitter) {\n      emitter = handle;\n      // Seed root record so cascade logic can see it, even when the\n      // outer authority owns root emission.\n      trackNamespace([]);\n      if (emitRootOnRegister) {\n        emit([], initialStatus);\n      }\n    },\n\n    process(event: ProtocolEvent): boolean {\n      const ns = event.params.namespace;\n\n      // Re-entrant loopback: an event we emitted via `emitter.push`\n      // is being routed back through this transformer by the mux.\n      // Allow it through the wire unchanged.\n      if (inSelfEmit > 0) return true;\n\n      const taskCompletion =\n        event.method === \"tasks\"\n          ? extractTaskResultCompletion(event.params.data)\n          : undefined;\n      if (taskCompletion != null) {\n        // Prefer exact task-result attribution over any ambiguous\n        // `updates.node` completion deferred from the previous event.\n        removePendingNodeCompletions(ns, taskCompletion.name);\n      }\n\n      // Flush any completions deferred by the previous event so the\n      // wire order is [triggering event] -> [deferred completed].\n      flushPendingCompletions();\n\n      // Upstream `lifecycle` events: stash any `cause` attached by a\n      // product-specific transformer (e.g. deepagents' SubagentTransformer),\n      // synthesize our authoritative started/... for the namespace, and\n      // suppress the original so we are the single source of truth.\n      if (event.method === \"lifecycle\") {\n        const cause = extractCause(event.params.data);\n        if (cause != null) {\n          namespaceCause.set(nsKey(ns), cause);\n        }\n        ensureStarted(ns);\n        return false;\n      }\n\n      // Lifecycle for parent + any unseen prefix => synthesize started.\n      ensureStarted(ns);\n\n      // Track interrupt ids so `finalize` can decide between\n      // `completed` and `interrupted`.\n      if (\n        event.method === \"input\" &&\n        isRecord(event.params.data) &&\n        event.params.data.event === \"requested\"\n      ) {\n        const id = (event.params.data as { id?: unknown }).id;\n        if (typeof id === \"string\") {\n          pendingInterruptIds.add(id);\n        }\n      }\n\n      if (taskCompletion != null) {\n        const childNamespace = findStartedChildForTask(ns, taskCompletion);\n        if (childNamespace != null) {\n          enqueueCompletion({\n            namespace: childNamespace,\n            source: { type: \"task\" },\n          });\n        }\n      }\n\n      // Defer child-node completion: the `updates` event carries the\n      // node attribution; the corresponding child namespace is\n      // `[...ns, \"<node>:<uuid>\"]`. We pick the oldest still-started\n      // matching child (LangGraph emits one updates per completed task\n      // so repeated calls drain parallel fan-outs in order).\n      if (event.method === \"updates\") {\n        const node = event.params.node;\n        if (typeof node === \"string\" && !node.startsWith(\"__\")) {\n          const childNamespace = findStartedChildForNode(ns, node);\n          if (childNamespace != null) {\n            enqueueCompletion({\n              namespace: childNamespace,\n              source: { type: \"node\", parent: ns, node },\n            });\n          }\n        }\n      }\n\n      return true;\n    },\n\n    finalize(): void | PromiseLike<void> {\n      if (finalized) return;\n      finalized = true;\n      flushPendingCompletions();\n\n      if (getTerminalStatusOverride == null) {\n        cascadeTerminalStatus(defaultTerminalStatus());\n        return;\n      }\n\n      return resolveTerminalStatusOverride()\n        .then(cascadeTerminalStatus)\n        .catch((err) => {\n          log.fail(err);\n        });\n    },\n\n    fail(err: unknown) {\n      if (finalized) return;\n      finalized = true;\n      const errorMessage = serializeError(err);\n\n      // Cascade `failed` to every still-started namespace. Children\n      // that had already entered a terminal state are left untouched\n      // by the dedup guard in `emit`.\n      for (const rec of namespaces.values()) {\n        if (rec.namespace.length === 0) continue;\n        if (rec.status !== \"started\") continue;\n        emit(rec.namespace, \"failed\");\n      }\n\n      emit([], \"failed\", { error: errorMessage });\n      log.fail(err);\n    },\n  };\n\n  return transformer;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAsEA,SAAgB,uBACd,KACA,MACA,UAAU,GACqB;AAC/B,QAAO,EACL,CAAC,OAAO,iBAAgD;EACtD,MAAM,OAAO,IAAI,QAAQ,QAAQ;AACjC,SAAO,EACL,MAAM,OAAgD;AAEpD,UAAO,MAAM;IACX,MAAM,SAAS,MAAM,KAAK,MAAM;AAChC,QAAI,OAAO,KACT,QAAO;KACL,OAAO,KAAA;KACP,MAAM;KACP;AAEH,QAAIA,YAAAA,UAAU,OAAO,MAAM,WAAW,KAAK,CACzC,QAAO;KAAE,OAAO,OAAO;KAAO,MAAM;KAAO;;KAIlD;IAEJ;;AAGH,MAAM,0BAA0B;AAEhC,SAAS,sBAAsB,IAAuB;AACpD,KAAI,GAAG,WAAW,EAAG,QAAO;CAC5B,MAAM,OAAO,GAAG,GAAG,SAAS;CAC5B,MAAM,QAAQ,KAAK,QAAQ,IAAI;AAC/B,QAAO,UAAU,KAAK,OAAO,KAAK,MAAM,GAAG,MAAM;;AAGnD,SAAS,sBAAsB,KAAsB;AAEnD,KAAI,eAAe,MAAO,QAAO,IAAI;AACrC,KAAI,OAAO,QAAQ,SAAU,QAAO;AACpC,KAAI;AACF,SAAO,KAAK,UAAU,IAAI;SACpB;AACN,SAAO,OAAO,IAAI;;;AAItB,SAAS,SAAS,OAAkD;AAClE,QAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,MAAM;;;;;;;;AAS7E,SAAS,aAAa,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