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anEventAttributes,\n\tTelemetrySchemaSpanEventName,\n\tTelemetrySchemaSpanName,\n\tTelemetrySchemaSpanStartAttributes,\n\tTelemetrySchemaSpanUnion,\n\tTelemetrySpan,\n} from \"@earendil-works/pi-telemetry\";\nimport { type Context, getTelemetryContext, withTelemetryContext } from \"./context.ts\";\n\nexport type {\n\tAttributeValue,\n\tExactTelemetryAttributes,\n\tSchemaTelemetrySpan,\n\tSpanAttributes,\n\tSpanOptions,\n\tSpanStatus,\n\tTelemetryAttributeDefinition,\n\tTelemetryAttributeMetadata,\n\tTelemetryAttributeType,\n\tTelemetryContext,\n\tTelemetryEventAttributeDefinition,\n\tTelemetryEventDefinition,\n\tTelemetryParentDefinition,\n\tTelemetrySchemaDefinition,\n\tTelemetrySchemaSpanEndAttributes,\n\tTelemetrySchemaSpanEventAttributes,\n\tTelemetrySchemaSpanEventName,\n\tTelemetrySchemaSpanName,\n\tTelemetrySchemaSpanStartAttributes,\n\tTelemetrySchemaSpanUnion,\n\tTelemetrySpan,\n\tTelemetrySpanDefinition,\n\tTelemetryStartAttributeDefinition,\n\tTypedSpanStarter,\n} from \"@earendil-works/pi-telemetry\";\n\nexport const AI_TELEMETRY_SCHEMA = {\n\tversion: 1,\n\tspans: {\n\t\t\"pi.ai.request\": {\n\t\t\tdescription: \"One logical request to an AI provider\",\n\t\t\tparents: { kind: \"any\" },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.ai.operation\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"stream\", \"fetch_deferred\", \"cancel_deferred\", \"generate_images\"],\n\t\t\t\t\tdescription: \"Logical provider operation\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.provider\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Selected provider id\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.model\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Requested model id\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.api\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Provider API id\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.streaming\": {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Whether this operation returns a stream\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.deferred\": {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tdescription: \"Whether the operation requests or participates in deferred execution\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.ai.response.model\": { type: \"string\", description: \"Concrete response model\" },\n\t\t\t\t\"pi.ai.response.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Provider response id\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.response.stop_reason\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"stop\", \"length\", \"tool_use\", \"error\", \"aborted\", \"deferred\"],\n\t\t\t\t\tdescription: \"Normalized terminal response reason\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.http.status_code\": { type: \"number\", description: \"Final HTTP status\" },\n\t\t\t\t\"pi.ai.usage.input_tokens\": { type: \"number\", description: \"Reported input tokens\" },\n\t\t\t\t\"pi.ai.usage.output_tokens\": { type: \"number\", description: \"Reported output tokens\" },\n\t\t\t\t\"pi.ai.usage.cache_read_tokens\": { type: \"number\", description: \"Reported cache-read tokens\" },\n\t\t\t\t\"pi.ai.usage.cache_write_tokens\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\tdescription: \"Reported cache-write tokens\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.usage.reasoning_tokens\": { type: \"number\", description: \"Reported reasoning tokens\" },\n\t\t\t\t\"pi.ai.usage.total_tokens\": { type: \"number\", description: \"Reported total tokens\" },\n\t\t\t\t\"pi.ai.usage.cost\": { type: \"number\", description: \"Reported total cost\" },\n\t\t\t\t\"pi.ai.stream.chunk_count\": { type: \"number\", description: \"Streamed update chunk count\" },\n\t\t\t\t\"pi.ai.stream.time_to_first_chunk_ms\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\tdescription: \"Elapsed milliseconds to first update chunk\",\n\t\t\t\t},\n\t\t\t\t\"pi.ai.error.type\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tcardinality: \"low\",\n\t\t\t\t\tdescription: \"Provider or transport error class\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The operation throws or returns an error result\" },\n\t\t},\n\t},\n} as const satisfies TelemetrySchemaDefinition;\n\nexport type AiSpanName = TelemetrySchemaSpanName<typeof AI_TELEMETRY_SCHEMA>;\nexport type AiSpanStartAttributes<Name extends AiSpanName> = TelemetrySchemaSpanStartAttributes<\n\ttypeof AI_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type AiSpanEndAttributes<Name extends AiSpanName> = TelemetrySchemaSpanEndAttributes<\n\ttypeof AI_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type AiSpanAttributes<Name extends AiSpanName> = AiSpanStartAttributes<Name> & AiSpanEndAttributes<Name>;\nexport type AiSpanEventName<Name extends AiSpanName> = TelemetrySchemaSpanEventName<typeof AI_TELEMETRY_SCHEMA, Name>;\nexport type AiSpanEventAttributes<\n\tName extends AiSpanName,\n\tEventName extends AiSpanEventName<Name>,\n> = TelemetrySchemaSpanEventAttributes<typeof AI_TELEMETRY_SCHEMA, Name, EventName>;\nexport type AiTelemetrySpan<Name extends AiSpanName> = SchemaTelemetrySpan<typeof AI_TELEMETRY_SCHEMA, Name>;\nexport type AiSpan = TelemetrySchemaSpanUnion<typeof AI_TELEMETRY_SCHEMA>;\n\nexport function startAiSpan<Name extends AiSpanName, const Attributes extends AiSpanStartAttributes<Name>, Result>(\n\tname: Name,\n\tattributes: ExactTelemetryAttributes<AiSpanStartAttributes<Name>, Attributes>,\n\tcallback: (span: AiTelemetrySpan<Name>, context: Context) => Result | Promise<Result>,\n\tcontext: Context,\n): Promise<Result> {\n\treturn getTelemetryContext(context).startSpan({ name, attributes }, (span) =>\n\t\tcallback(span as AiTelemetrySpan<Name>, withTelemetryContext(span, context)),\n\t);\n}\n\nconst HOOK_NAMES = [\n\t\"before_run\",\n\t\"before_drive\",\n\t\"before_run_end\",\n\t\"transform_context\",\n\t\"before_request\",\n\t\"before_payload\",\n\t\"after_response\",\n\t\"before_tool\",\n\t\"after_tool\",\n\t\"before_compaction\",\n\t\"before_navigation\",\n] as const;\n\nconst EVENT_TYPES = [\n\t\"run_start\",\n\t\"run_resume\",\n\t\"run_suspend\",\n\t\"operation_abort\",\n\t\"run_end\",\n\t\"fault\",\n\t\"handler_error\",\n\t\"turn_start\",\n\t\"turn_end\",\n\t\"retry_scheduled\",\n\t\"retry_start\",\n\t\"retry_end\",\n\t\"message_start\",\n\t\"message_update\",\n\t\"message_end\",\n\t\"tool_start\",\n\t\"tool_update\",\n\t\"tool_end\",\n\t\"entry_added\",\n\t\"queue_update\",\n\t\"value_update\",\n\t\"config_update\",\n\t\"compaction_start\",\n\t\"compaction_end\",\n\t\"navigation_start\",\n\t\"navigation_end\",\n\t\"lane_created\",\n\t\"usage\",\n] as const;\n\nconst operationStartAttributes = {\n\t\"pi.session.id\": {\n\t\ttype: \"string\",\n\t\trequired: true,\n\t\tcardinality: \"high\",\n\t\tdescription: \"Session id\",\n\t},\n\t\"pi.lane.name\": {\n\t\ttype: \"string\",\n\t\trequired: true,\n\t\tcardinality: \"high\",\n\t\tdescription: \"Lane name\",\n\t},\n\t\"pi.operation.id\": {\n\t\ttype: \"string\",\n\t\trequired: true,\n\t\tcardinality: \"high\",\n\t\tdescription: \"Durable operation id\",\n\t},\n\t\"pi.operation.recovery\": {\n\t\ttype: \"boolean\",\n\t\trequired: true,\n\t\tdescription: \"Whether this invocation resumes durable work\",\n\t},\n} as const;\n\nconst operationErrorAttributes = {\n\t\"pi.error.code\": {\n\t\ttype: \"string\",\n\t\tcardinality: \"low\",\n\t\tdescription: \"Stable operation error code\",\n\t},\n\t\"pi.error.type\": {\n\t\ttype: \"string\",\n\t\tcardinality: \"low\",\n\t\tdescription: \"Low-cardinality operation error class\",\n\t},\n} as const;\n\nexport const HARNESS_TELEMETRY_SCHEMA = {\n\tversion: 1,\n\tspans: {\n\t\t\"pi.harness.run\": {\n\t\t\tdescription: \"One admitted in-process run invocation\",\n\t\t\tparents: { kind: \"root_or_external\" },\n\t\t\tstartAttributes: {\n\t\t\t\t...operationStartAttributes,\n\t\t\t\t\"pi.operation.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"run\"],\n\t\t\t\t\tdescription: \"Run operation kind\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.operation.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"completed\", \"aborted\", \"failed\", \"suspended\"],\n\t\t\t\t\tdescription: \"Run invocation outcome\",\n\t\t\t\t},\n\t\t\t\t...operationErrorAttributes,\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The run fails or throws\" },\n\t\t},\n\t\t\"pi.harness.compaction\": {\n\t\t\tdescription: \"One admitted in-process manual compaction invocation\",\n\t\t\tparents: { kind: \"root_or_external\" },\n\t\t\tstartAttributes: {\n\t\t\t\t...operationStartAttributes,\n\t\t\t\t\"pi.operation.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"compaction\"],\n\t\t\t\t\tdescription: \"Compaction operation kind\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.operation.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"completed\", \"declined\", \"aborted\", \"failed\"],\n\t\t\t\t\tdescription: \"Compaction invocation outcome\",\n\t\t\t\t},\n\t\t\t\t...operationErrorAttributes,\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The compaction fails or throws\" },\n\t\t},\n\t\t\"pi.harness.navigation\": {\n\t\t\tdescription: \"One admitted in-process navigation invocation\",\n\t\t\tparents: { kind: \"root_or_external\" },\n\t\t\tstartAttributes: {\n\t\t\t\t...operationStartAttributes,\n\t\t\t\t\"pi.operation.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"navigation\"],\n\t\t\t\t\tdescription: \"Navigation operation kind\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.operation.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"completed\", \"declined\", \"aborted\", \"failed\"],\n\t\t\t\t\tdescription: \"Navigation invocation outcome\",\n\t\t\t\t},\n\t\t\t\t...operationErrorAttributes,\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The navigation fails or throws\" },\n\t\t},\n\t\t\"pi.harness.checkpoint\": {\n\t\t\tdescription: \"One run checkpoint\",\n\t\t\tparents: { kind: \"spans\", spans: [\"pi.harness.run\"] },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.checkpoint.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"normal\", \"abort_reconcile\"],\n\t\t\t\t\tdescription: \"Checkpoint purpose\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Checkpoint work throws\" },\n\t\t},\n\t\t\"pi.harness.turn\": {\n\t\t\tdescription: \"One assistant response and its tool batch\",\n\t\t\tparents: { kind: \"spans\", spans: [\"pi.harness.run\"] },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.turn.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Invocation-local turn id\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Turn work throws\" },\n\t\t},\n\t\t\"pi.harness.step\": {\n\t\t\tdescription: \"One durable retry attempt\",\n\t\t\tparents: {\n\t\t\t\tkind: \"spans\",\n\t\t\t\tspans: [\"pi.harness.turn\", \"pi.harness.checkpoint\", \"pi.harness.compaction\", \"pi.harness.navigation\"],\n\t\t\t},\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.step.kind\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"assistant\", \"compaction\", \"branch_summary\"],\n\t\t\t\t\tdescription: \"Retryable step kind\",\n\t\t\t\t},\n\t\t\t\t\"pi.step.attempt\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"One-based durable attempt number\",\n\t\t\t\t},\n\t\t\t\t\"pi.compaction.reason\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tvalues: [\"manual\", \"threshold\", \"overflow\"],\n\t\t\t\t\tdescription: \"Compaction trigger\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.step.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"succeeded\", \"retry\", \"failed\", \"aborted\", \"deferred\", \"overflow\"],\n\t\t\t\t\tdescription: \"Attempt outcome\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The attempt retries, fails, or throws\" },\n\t\t},\n\t\t\"pi.harness.tool\": {\n\t\t\tdescription: \"One raw phase-2 tool execution\",\n\t\t\tparents: { kind: \"spans\", spans: [\"pi.harness.turn\", \"pi.harness.run\"] },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.turn.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Invocation-local live turn id\",\n\t\t\t\t},\n\t\t\t\t\"pi.tool.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Tool name\",\n\t\t\t\t},\n\t\t\t\t\"pi.tool.call_id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Tool call id\",\n\t\t\t\t},\n\t\t\t\t\"pi.tool.replay\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: [\"never\", \"safe\"],\n\t\t\t\t\tdescription: \"Declared replay policy\",\n\t\t\t\t},\n\t\t\t\t\"pi.tool.recovery\": {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Whether this is recovery execution\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.tool.is_error\": {\n\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\tdescription: \"Whether raw phase-2 execution returned an error\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Raw phase-2 execution returns an error\" },\n\t\t},\n\t\t\"pi.harness.hook\": {\n\t\t\tdescription: \"One registered hook handler invocation\",\n\t\t\tparents: { kind: \"any\" },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id when accepted\",\n\t\t\t\t},\n\t\t\t\t\"pi.hook.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tvalues: HOOK_NAMES,\n\t\t\t\t\tdescription: \"Hook name\",\n\t\t\t\t},\n\t\t\t\t\"pi.hook.registration_id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tdescription: \"Optional hook registration metadata\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.hook.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"completed\", \"skipped\", \"blocked\", \"failed\"],\n\t\t\t\t\tdescription: \"Handler outcome\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The handler throws\" },\n\t\t},\n\t\t\"pi.harness.sleep\": {\n\t\t\tdescription: \"One retry delay\",\n\t\t\tparents: {\n\t\t\t\tkind: \"spans\",\n\t\t\t\tspans: [\n\t\t\t\t\t\"pi.harness.run\",\n\t\t\t\t\t\"pi.harness.compaction\",\n\t\t\t\t\t\"pi.harness.navigation\",\n\t\t\t\t\t\"pi.harness.turn\",\n\t\t\t\t\t\"pi.harness.checkpoint\",\n\t\t\t\t],\n\t\t\t},\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id\",\n\t\t\t\t},\n\t\t\t\t\"pi.sleep.delay_ms\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Requested delay in milliseconds\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.sleep.outcome\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\tvalues: [\"elapsed\", \"aborted\"],\n\t\t\t\t\tdescription: \"Delay outcome\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Sleep work throws\" },\n\t\t},\n\t\t\"pi.harness.event_handler\": {\n\t\t\tdescription: \"One passive event listener invocation\",\n\t\t\tparents: { kind: \"any\" },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.event.type\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"low\",\n\t\t\t\t\tvalues: EVENT_TYPES,\n\t\t\t\t\tdescription: \"Delivered harness event type\",\n\t\t\t\t},\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name for lane-scoped events\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"The listener throws\" },\n\t\t},\n\t\t\"pi.session.write\": {\n\t\t\tdescription: \"One committed session transaction\",\n\t\t\tparents: { kind: \"any\" },\n\t\t\tstartAttributes: {\n\t\t\t\t\"pi.session.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Session id\",\n\t\t\t\t},\n\t\t\t\t\"pi.lane.name\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Lane name when supplied by the caller\",\n\t\t\t\t},\n\t\t\t\t\"pi.operation.id\": {\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: false,\n\t\t\t\t\tcardinality: \"high\",\n\t\t\t\t\tdescription: \"Durable operation id when supplied by the caller\",\n\t\t\t\t},\n\t\t\t\t\"pi.session.item_count\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: \"Number of writes in the transaction\",\n\t\t\t\t},\n\t\t\t\t\"pi.session.item_kinds\": {\n\t\t\t\t\ttype: \"string[]\",\n\t\t\t\t\trequired: true,\n\t\t\t\t\telementValues: [\"entry\", \"usage\", \"value\", \"list\"],\n\t\t\t\t\tdescription: \"Distinct write kinds in the transaction\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tendAttributes: {\n\t\t\t\t\"pi.session.first_seq\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\tdescription: \"First committed sequence in the transaction\",\n\t\t\t\t},\n\t\t\t\t\"pi.session.last_seq\": {\n\t\t\t\t\ttype: \"number\",\n\t\t\t\t\tdescription: \"Last committed sequence in the transaction\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tstatus: { default: \"ok\", errorWhen: \"Storage rejects the transaction\" },\n\t\t},\n\t},\n} as const satisfies TelemetrySchemaDefinition;\n\n/** Combined typed span vocabulary for agent-owned AI-request and harness telemetry. */\nexport const AGENT_TELEMETRY_SCHEMAS = [AI_TELEMETRY_SCHEMA, HARNESS_TELEMETRY_SCHEMA] as const;\n\nexport type HarnessSpanName = TelemetrySchemaSpanName<typeof HARNESS_TELEMETRY_SCHEMA>;\nexport type HarnessSpanStartAttributes<Name extends HarnessSpanName> = TelemetrySchemaSpanStartAttributes<\n\ttypeof HARNESS_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type HarnessSpanEndAttributes<Name extends HarnessSpanName> = TelemetrySchemaSpanEndAttributes<\n\ttypeof HARNESS_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type HarnessSpanAttributes<Name extends HarnessSpanName> = HarnessSpanStartAttributes<Name> &\n\tHarnessSpanEndAttributes<Name>;\nexport type HarnessSpanEventName<Name extends HarnessSpanName> = TelemetrySchemaSpanEventName<\n\ttypeof HARNESS_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type HarnessSpanEventAttributes<\n\tName extends HarnessSpanName,\n\tEventName extends HarnessSpanEventName<Name>,\n> = TelemetrySchemaSpanEventAttributes<typeof HARNESS_TELEMETRY_SCHEMA, Name, EventName>;\nexport type HarnessTelemetrySpan<Name extends HarnessSpanName> = SchemaTelemetrySpan<\n\ttypeof HARNESS_TELEMETRY_SCHEMA,\n\tName\n>;\nexport type HarnessSpan = TelemetrySchemaSpanUnion<typeof HARNESS_TELEMETRY_SCHEMA>;\n\nexport function startHarnessSpan<\n\tName extends HarnessSpanName,\n\tconst Attributes extends HarnessSpanStartAttributes<Name>,\n\tResult,\n>(\n\tname: Name,\n\tattributes: ExactTelemetryAttributes<HarnessSpanStartAttributes<Name>, Attributes>,\n\tcallback: (span: HarnessTelemetrySpan<Name>, context: Context) => Result | Promise<Result>,\n\tcontext: Context,\n): Promise<Result> {\n\treturn getTelemetryContext(context).startSpan({ name, attributes }, (span: TelemetrySpan) =>\n\t\tcallback(span as HarnessTelemetrySpan<Name>, withTelemetryContext(span, context)),\n\t);\n}\n"]}