@conciv/protocol 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"ui-types.d.ts","names":[],"sources":["../src/ui-types.ts"],"mappings":";;;;cASa,iBAAA,EAAiB,CAAA,CAAA,SAAA;;;;;;;;;cAOjB,eAAA,EAAe,CAAA,CAAA,SAAA;;;;;;cAMf,eAAA,EAAe,CAAA,CAAA,SAAA;;;;;;cAMf,YAAA,EAAY,CAAA,CAAA,SAAA;;;;;;;cAOZ,YAAA,EAAY,CAAA,CAAA,SAAA;;;;;;;;;;;;;;cAOZ,cAAA,EAAc,CAAA,CAAA,SAAA;;;;cAEd,YAAA,EAAY,CAAA,CAAA,qBAAA,EAAA,CAAA,CAAA,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAQb,WAAA,GAAc,CAAA,CAAE,KAAK,QAAQ,iBAAA;AAAA,KAC7B,WAAA,GAAc,WAAW;AAAA,KACzB,MAAA,GAAS,CAAA,CAAE,KAAK,QAAQ,YAAA;AAAA,KACxB,SAAA,GAAY,CAAA,CAAE,KAAK,QAAQ,eAAA;AAAA,KAC3B,SAAA,GAAY,CAAA,CAAE,KAAK,QAAQ,eAAA;AAAA,KAC3B,MAAA,GAAS,CAAA,CAAE,KAAK,QAAQ,YAAA;AAAA,KACxB,MAAA,GAAS,CAAA,CAAE,KAAK,QAAQ,YAAA;AAAA,KACxB,QAAA,GAAW,CAAA,CAAE,KAAK,QAAQ,cAAA;AAAA,cAGzB,eAAA;AAAA,iBAGG,aAAA,CAAc,IAAA,EAAM,MAAA,GAAS,WAAW;AAAA,cAU3C,wBAAA;AAAA,KAID,eAAA;EAAmB,UAAA;EAAoB,QAAA;EAAkB,KAAA;EAAgB,UAAA;AAAA;AAAA,iBAErE,wBAAA,CAAyB,GAAA,EAAK,eAAA,GAAkB,WAAW;AAAA,iBAS3D,WAAA,CAAY,K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AAmB,UAAA;EAAoB,QAAA;EAAkB,KAAA;EAAgB,UAAA;AAAA;AAAA,iBAErE,wBAAA,CAAyB,GAAA,EAAK,eAAA,GAAkB,WAAW;AAAA,iBAQ3D,WAAA,CAAY,KAAA,YAAiB,MAAM;AAAA,iBAKnC,UAAA,CAAW,GAAA,WAAc,WAAW;AAAA,KAYxC,YAAA;EACV,IAAA;EACA,QAAA;EACA,MAAA;EACA,OAAA;EACA,IAAA;EACA,MAAA;EACA,KAAA;EACA,KAAA;EACA,MAAA,GAAS,WAAW;AAAA;AAAA,iBAGN,WAAA,CAAY,KAAA,EAAO,YAAA,EAAc,EAAA,WAAa,MAAM"}
@@ -1 +1 @@
1
- {"version":3,"file":"ui-types.js","names":[],"sources":["../src/ui-types.ts"],"sourcesContent":["import {z} from 'zod'\nimport {EventType, type StreamChunk} from '@tanstack/ai'\n\n// Generative-UI specs the chat agent emits via `conciv ui …`, rendered as components in the\n// chat thread and carried to the widget as an AG-UI CUSTOM event. The schemas are the contract;\n// types are inferred from them.\n\nconst renderId = z.string().min(1)\n\nexport const UiFormFieldSchema = z.object({\n name: z.string(),\n label: z.string(),\n type: z.enum(['text', 'select']),\n options: z.array(z.string()).optional(),\n})\n\nexport const UiChoicesSchema = z.object({\n kind: z.literal('choices'),\n renderId,\n question: z.string(),\n options: z.array(z.string()).min(1),\n})\nexport const UiConfirmSchema = z.object({\n kind: z.literal('confirm'),\n renderId,\n question: z.string(),\n detail: z.string().optional(),\n})\nexport const UiDiffSchema = z.object({\n kind: z.literal('diff'),\n renderId,\n file: z.string(),\n before: z.string(),\n after: z.string(),\n})\nexport const UiFormSchema = z.object({\n kind: z.literal('form'),\n renderId,\n title: z.string().optional(),\n fields: z.array(UiFormFieldSchema).min(1),\n})\n// Test-results card injected by the test route. (Kind stays 'vitest' until Plan 3.)\nexport const UiVitestSchema = z.object({kind: z.literal('vitest'), renderId})\n\nexport const UiSpecSchema = z.discriminatedUnion('kind', [\n UiChoicesSchema,\n UiConfirmSchema,\n UiDiffSchema,\n UiFormSchema,\n UiVitestSchema,\n])\n\nexport type UiFormField = z.infer<typeof UiFormFieldSchema>\nexport type UiFieldType = UiFormField['type']\nexport type UiSpec = z.infer<typeof UiSpecSchema>\nexport type UiChoices = z.infer<typeof UiChoicesSchema>\nexport type UiConfirm = z.infer<typeof UiConfirmSchema>\nexport type UiDiff = z.infer<typeof UiDiffSchema>\nexport type UiForm = z.infer<typeof UiFormSchema>\nexport type UiVitest = z.infer<typeof UiVitestSchema>\n\n// The CUSTOM event name the widget listens for via useChat({onCustomEvent}).\nexport const CONCIV_UI_EVENT = 'conciv-ui'\n\n// Wrap a spec as the AG-UI CUSTOM StreamChunk injected into the live chat stream.\nexport function aguiCustomFor(spec: UiSpec): StreamChunk {\n return {type: EventType.CUSTOM, name: CONCIV_UI_EVENT, value: spec}\n}\n\n// tanstack's StreamProcessor consumes this reserved CUSTOM event name to drive a tool-call part into\n// its NATIVE approval-requested state — it sets part.state='approval-requested' and part.approval\n// (see @tanstack/ai processor handleCustomEvent). The risky-Bash gate emits it so approval renders on\n// the tool card itself (no separate GenUi card). The decision returns out-of-band via\n// /api/chat/permission-decision: claude owns the loop and blocks on its PreToolUse hook, so the\n// decision cannot ride the one-way stream back (it would deadlock the live turn).\nexport const APPROVAL_REQUESTED_EVENT = 'approval-requested'\n\n// The value shape the StreamProcessor reads off the approval-requested CUSTOM event. toolCallId MUST\n// equal the streamed tool-call part id (= claude's tool_use_id) so the right part is targeted.\nexport type ApprovalRequest = {toolCallId: string; toolName: string; input: unknown; approvalId: string}\n\nexport function aguiApprovalRequestedFor(req: ApprovalRequest): StreamChunk {\n return {\n type: EventType.CUSTOM,\n name: APPROVAL_REQUESTED_EVENT,\n value: {toolCallId: req.toolCallId, toolName: req.toolName, input: req.input, approval: {id: req.approvalId}},\n }\n}\n\n// For non-h3 callers; route handlers use readValidatedBody(event, UiSpecSchema) directly.\nexport function parseUiSpec(input: unknown): UiSpec | null {\n const result = UiSpecSchema.safeParse(input)\n return result.success ? result.data : null\n}\n\n// Parse a CLI form-field spec `name:label:type[:opt1,opt2]` into a typed field. null if malformed.\nexport function parseField(raw: string): UiFormField | null {\n const [name, label, type, opts] = raw.split(':')\n if (!name || !label) return null\n if (type !== 'text' && type !== 'select') return null\n if (type === 'select') {\n const options = (opts ?? '').split(',').filter(Boolean)\n if (options.length === 0) return null\n return {name, label, type, options}\n }\n return {name, label, type}\n}\n\n// Normalized builder input — shared by the CLI (`conciv ui`) and the conciv_ui MCP tool. Both\n// normalize their own raw args to this shape, then call buildUiSpec.\nexport type UiBuildInput = {\n kind: string\n question?: string\n detail?: string\n options?: string[]\n file?: string\n before?: string\n after?: string\n title?: string\n fields?: UiFormField[]\n}\n\n// Pure: normalized input + a caller-supplied renderId → a typed UiSpec. Throws on invalid input.\nexport function buildUiSpec(input: UiBuildInput, id: string): UiSpec {\n if (input.kind === 'choices') {\n if (!input.question) throw new Error('choices needs a question')\n if (!input.options?.length) throw new Error('choices needs at least one option')\n return {kind: 'choices', renderId: id, question: input.question, options: input.options}\n }\n if (input.kind === 'confirm') {\n if (!input.question) throw new Error('confirm needs a question')\n return {kind: 'confirm', renderId: id, question: input.question, detail: input.detail}\n }\n if (input.kind === 'diff') {\n if (input.file === undefined || input.before === undefined || input.after === undefined) {\n throw new Error('diff needs file, before, and after')\n }\n return {kind: 'diff', renderId: id, file: input.file, before: input.before, after: input.after}\n }\n if (input.kind === 'form') {\n if (!input.fields?.length) throw new Error('form needs at least one field')\n return {kind: 'form', renderId: id, title: input.title, fields: input.fields}\n }\n throw new Error(`unknown ui kind: ${input.kind}`)\n}\n"],"mappings":";;;AAOA,MAAM,WAAW,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;AAEjC,MAAa,oBAAoB,EAAE,OAAO;CACxC,MAAM,EAAE,OAAO;CACf,OAAO,EAAE,OAAO;CAChB,MAAM,EAAE,KAAK,CAAC,QAAQ,QAAQ,CAAC;CAC/B,SAAS,EAAE,MAAM,EAAE,OAAO,C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+B;EAC1E,OAAO;GAAC,MAAM;GAAQ,UAAU;GAAI,OAAO,MAAM;GAAO,QAAQ,MAAM;EAAM;CAC9E;CACA,MAAM,IAAI,MAAM,oBAAoB,MAAM,MAAM;AAClD"}
1
+ {"version":3,"file":"ui-types.js","names":[],"sources":["../src/ui-types.ts"],"sourcesContent":["import {z} from 'zod'\nimport {EventType, type StreamChunk} from '@tanstack/ai'\n\nconst renderId = z.string().min(1)\n\nexport const UiFormFieldSchema = z.object({\n name: z.string(),\n label: z.string(),\n type: z.enum(['text', 'select']),\n options: z.array(z.string()).optional(),\n})\n\nexport const UiChoicesSchema = z.object({\n kind: z.literal('choices'),\n renderId,\n question: z.string(),\n options: z.array(z.string()).min(1),\n})\nexport const UiConfirmSchema = z.object({\n kind: z.literal('confirm'),\n renderId,\n question: z.string(),\n detail: z.string().optional(),\n})\nexport const UiDiffSchema = z.object({\n kind: z.literal('diff'),\n renderId,\n file: z.string(),\n before: z.string(),\n after: z.string(),\n})\nexport const UiFormSchema = z.object({\n kind: z.literal('form'),\n renderId,\n title: z.string().optional(),\n fields: z.array(UiFormFieldSchema).min(1),\n})\n\nexport const UiVitestSchema = z.object({kind: z.literal('vitest'), renderId})\n\nexport const UiSpecSchema = z.discriminatedUnion('kind', [\n UiChoicesSchema,\n UiConfirmSchema,\n UiDiffSchema,\n UiFormSchema,\n UiVitestSchema,\n])\n\nexport type UiFormField = z.infer<typeof UiFormFieldSchema>\nexport type UiFieldType = UiFormField['type']\nexport type UiSpec = z.infer<typeof UiSpecSchema>\nexport type UiChoices = z.infer<typeof UiChoicesSchema>\nexport type UiConfirm = z.infer<typeof UiConfirmSchema>\nexport type UiDiff = z.infer<typeof UiDiffSchema>\nexport type UiForm = z.infer<typeof UiFormSchema>\nexport type UiVitest = z.infer<typeof UiVitestSchema>\n\nexport const CONCIV_UI_EVENT = 'conciv-ui'\n\nexport function aguiCustomFor(spec: UiSpec): StreamChunk {\n return {type: EventType.CUSTOM, name: CONCIV_UI_EVENT, value: spec}\n}\n\n// /api/chat/permission-decision: claude owns the loop and blocks on its PreToolUse hook, so the\n\nexport const APPROVAL_REQUESTED_EVENT = 'approval-requested'\n\nexport type ApprovalRequest = {toolCallId: string; toolName: string; input: unknown; approvalId: string}\n\nexport function aguiApprovalRequestedFor(req: ApprovalRequest): StreamChunk {\n return {\n type: EventType.CUSTOM,\n name: APPROVAL_REQUESTED_EVENT,\n value: {toolCallId: req.toolCallId, toolName: req.toolName, input: req.input, approval: {id: req.approvalId}},\n }\n}\n\nexport function parseUiSpec(input: unknown): UiSpec | null {\n const result = UiSpecSchema.safeParse(input)\n return result.success ? result.data : null\n}\n\nexport function parseField(raw: string): UiFormField | null {\n const [name, label, type, opts] = raw.split(':')\n if (!name || !label) return null\n if (type !== 'text' && type !== 'select') return null\n if (type === 'select') {\n const options = (opts ?? '').split(',').filter(Boolean)\n if (options.length === 0) return null\n return {name, label, type, options}\n }\n return {name, label, type}\n}\n\nexport type UiBuildInput = {\n kind: string\n question?: string\n detail?: string\n options?: string[]\n file?: string\n before?: string\n after?: string\n title?: string\n fields?: UiFormField[]\n}\n\nexport function buildUiSpec(input: UiBuildInput, id: string): UiSpec {\n if (input.kind === 'choices') {\n if (!input.question) throw new Error('choices needs a question')\n if (!input.options?.length) throw new Error('choices needs at least one option')\n return {kind: 'choices', renderId: id, question: input.question, options: input.options}\n }\n if (input.kind === 'confirm') {\n if (!input.question) throw new Error('confirm needs a question')\n return {kind: 'confirm', renderId: id, question: input.question, detail: input.detail}\n }\n if (input.kind === 'diff') {\n if (input.file === undefined || input.before === undefined || input.after === undefined) {\n throw new Error('diff needs file, before, and after')\n }\n return {kind: 'diff', renderId: id, file: input.file, before: input.before, after: input.after}\n }\n if (input.kind === 'form') {\n if (!input.fields?.length) throw new Error('form needs at least one field')\n return {kind: 'form', renderId: id, title: input.title, fields: input.fields}\n }\n throw new Error(`unknown ui kind: ${input.kind}`)\n}\n"],"mappings":";;;AAGA,MAAM,WAAW,EAAE,OAAO,CAA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AO;GAAC,MAAM;GAAQ,UAAU;GAAI,MAAM,MAAM;GAAM,QAAQ,MAAM;GAAQ,OAAO,MAAM;EAAK;CAChG;CACA,IAAI,MAAM,SAAS,QAAQ;EACzB,IAAI,CAAC,MAAM,QAAQ,QAAQ,MAAM,IAAI,MAAM,+BAA+B;EAC1E,OAAO;GAAC,MAAM;GAAQ,UAAU;GAAI,OAAO,MAAM;GAAO,QAAQ,MAAM;EAAM;CAC9E;CACA,MAAM,IAAI,MAAM,oBAAoB,MAAM,MAAM;AAClD"}
@@ -1 +1 @@
1
- {"version":3,"file":"usage-types.d.ts","names":[],"sources":["../src/usage-types.ts"],"mappings":";;;;cAIa,mBAAA,EAAmB,CAAA,CAAA,SAAA;;;;;;;;;;;KAWpB,aAAA,GAAgB,CAAA,CAAE,KAAK,QAAQ,mBAAA;AAAA,iBAW3B,oBAAA,CAAqB,CAAA,EAAG,aAAA,GAAgB,UAAU;AAAA,iBAkBlD,oBAAA,CAAqB,CAAA,EAAG,UAAA,GAAa,aAAa;AAAA,cAiBrD,kBAAA;AAAA,iBACG,YAAA,CAAa,QAAA,EAAU,aAAA,GAAgB,WAAW;AAAA,iBAKlD,iBAAA,CAAkB,CAAgB,EAAb,aAAa"}
1
+ {"version":3,"file":"usage-types.d.ts","names":[],"sources":["../src/usage-types.ts"],"mappings":";;;;cAGa,mBAAA,EAAmB,CAAA,CAAA,SAAA;;;;;;;;;;;KAWpB,aAAA,GAAgB,CAAA,CAAE,KAAK,QAAQ,mBAAA;AAAA,iBAS3B,oBAAA,CAAqB,CAAA,EAAG,aAAA,GAAgB,UAAU;AAAA,iBAiBlD,oBAAA,CAAqB,CAAA,EAAG,UAAA,GAAa,aAAa;AAAA,cAerD,kBAAA;AAAA,iBACG,YAAA,CAAa,QAAA,EAAU,aAAA,GAAgB,WAAW;AAAA,iBAIlD,iBAAA,CAAkB,CAAgB,EAAb,aAAa"}
@@ -1 +1 @@
1
- {"version":3,"file":"usage-types.js","names":[],"sources":["../src/usage-types.ts"],"sourcesContent":["import {z} from 'zod'\nimport {EventType, type StreamChunk, type TokenUsage} from '@tanstack/ai'\n\n// Normalized per-session model usage; every field optional so a harness reports only what it has.\nexport const UsageSnapshotSchema = z.object({\n modelId: z.string().optional(),\n contextWindow: z.number().int().nonnegative().optional(),\n inputTokens: z.number().int().nonnegative().optional(),\n outputTokens: z.number().int().nonnegative().optional(),\n cacheReadTokens: z.number().int().nonnegative().optional(),\n cacheWriteTokens: z.number().int().nonnegative().optional(),\n reasoningTokens: z.number().int().nonnegative().optional(),\n totalCostUsd: z.number().nonnegative().optional(),\n numTurns: z.number().int().nonnegative().optional(),\n})\nexport type UsageSnapshot = z.infer<typeof UsageSnapshotSchema>\n\n// Fields with no standard TokenUsage slot ride providerUsageDetails (one type keeps the mappers in sync).\ntype ConcivProviderUsage = {\n modelId?: string\n contextWindow?: number\n totalCostUsd?: number\n numTurns?: number\n}\n\n// Snapshot → native TokenUsage on RUN_FINISHED (survives chat(); CUSTOM chunks do not).\nexport function snapshotToTokenUsage(s: UsageSnapshot): TokenUsage {\n const provider: ConcivProviderUsage = {\n modelId: s.modelId,\n contextWindow: s.contextWindow,\n totalCostUsd: s.totalCostUsd,\n numTurns: s.numTurns,\n }\n return {\n promptTokens: s.inputTokens ?? 0,\n completionTokens: s.outputTokens ?? 0,\n totalTokens: (s.inputTokens ?? 0) + (s.outputTokens ?? 0),\n promptTokensDetails: {cachedTokens: s.cacheReadTokens, cacheWriteTokens: s.cacheWriteTokens},\n completionTokensDetails: {reasoningTokens: s.reasoningTokens},\n providerUsageDetails: provider,\n }\n}\n\n// Inverse of snapshotToTokenUsage: read a RUN_FINISHED usage back into our display shape.\nexport function tokenUsageToSnapshot(u: TokenUsage): UsageSnapshot {\n const p = (u.providerUsageDetails ?? {}) as ConcivProviderUsage\n return {\n modelId: p.modelId,\n contextWindow: p.contextWindow,\n inputTokens: u.promptTokens,\n outputTokens: u.completionTokens,\n cacheReadTokens: u.promptTokensDetails?.cachedTokens,\n cacheWriteTokens: u.promptTokensDetails?.cacheWriteTokens,\n reasoningTokens: u.completionTokensDetails?.reasoningTokens,\n totalCostUsd: p.totalCostUsd,\n numTurns: p.numTurns,\n }\n}\n\n// Live usage carried to the widget mid-turn as an AG-UI CUSTOM event, injected by core post-chat()\n// (the same seam conciv-ui uses). RUN_FINISHED.usage stays the canonical end-of-turn/persist value.\nexport const CONCIV_USAGE_EVENT = 'conciv-usage'\nexport function aguiUsageFor(snapshot: UsageSnapshot): StreamChunk {\n return {type: EventType.CUSTOM, name: CONCIV_USAGE_EVENT, value: snapshot}\n}\n\n// Context occupancy = prompt resident in the window (input + cache), excluding output; undefined when no tokens.\nexport function contextUsedTokens(s: UsageSnapshot): number | undefined {\n const parts = [s.inputTokens, s.cacheReadTokens, s.cacheWriteTokens]\n if (parts.every((p) => p === undefined)) return undefined\n return parts.reduce<number>((sum, p) => sum + (p ?? 0), 0)\n}\n"],"mappings":";;;AAIA,MAAa,sBAAsB,EAAE,OAAO;CAC1C,SAAS,EAAE,OAAO,CAAC,CAAC,SAAS;CAC7B,eAAe,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC,CAAC,SAAS;CACvD,aAAa,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC,CAAC,SAAS;CACrD,cAAc,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC,CAAC,SAAS;CACtD,iBAAiB,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC,CAAC,SAAS;CACzD,kBAAkB,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC,CAAC,SAAS;CAC1D,iBAAiB,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC,CAAC,SAAS;CACzD,cAAc,EAAE,OAAO,CAAC,CAAC,YAAY,CAAC,CAAC,SAAS;CAChD,UAAU,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC,CAAC,SAAS;AACpD,CAAC;AAYD,SAAgB,qBAAqB,GAA8B;CACjE,MAAM,WAAgC;EACpC,SAAS,EAAE;EACX,eAAe,EAAE;EACjB,cAAc,EAAE;EAChB,UAAU,EAAE;CACd;CACA,OAAO;EACL,cAAc,EAAE,eAAe;EAC/B,kBAAkB,EAAE,gBAAgB;EACpC,cAAc,EAAE,eAAe,MAAM,EAAE,gBAAgB;EACvD,qBAAqB;GAAC,cAAc,EAAE;GAAiB,kBAAkB,EAAE;EAAgB;EAC3F,yBAAyB,EAAC,iBAAiB,EAAE,gBAAe;EAC5D,sBAAsB;CACxB;AACF;AAGA,SAAgB,qBAAqB,GAA8B;CACjE,MAAM,IAAK,EAAE,wBAAwB,CAAC;CACtC,OAAO;EACL,SAAS,EAAE;EACX,eAAe,EAAE;EACjB,aAAa,EAAE;EACf,cAAc,EAAE;EAChB,iBAAiB,EAAE,qBAAqB;EACxC,kBAAkB,EAAE,qBAAqB;EACzC,iBAAiB,EAAE,yBAAyB;EAC5C,cAAc,EAAE;EAChB,UAAU,EAAE;CACd;AACF;AAIA,MAAa,qBAAqB;AAClC,SAAgB,aAAa,UAAsC;CACjE,OAAO;EAAC,MAAM,UAAU;EAAQ,MAAM;EAAoB,OAAO;CAAQ;AAC3E;AAGA,SAAgB,kBAAkB,GAAsC;CACtE,MAAM,QAAQ;EAAC,EAAE;EAAa,EAAE;EAAiB,EAAE;CAAgB;CACnE,IAAI,MAAM,OAAO,MAAM,MAAM,KAAA,CAAS,GAAG,OAAO,KAAA;CAChD,OAAO,MAAM,QAAgB,KAAK,MAAM,OAAO,KAAK,IAAI,CAAC;AAC3D"}
1
+ {"version":3,"file":"usage-types.js","names":[],"sources":["../src/usage-types.ts"],"sourcesContent":["import {z} from 'zod'\nimport {EventType, type StreamChunk, type TokenUsage} from '@tanstack/ai'\n\nexport const UsageSnapshotSchema = z.object({\n modelId: z.string().optional(),\n contextWindow: z.number().int().nonnegative().optional(),\n inputTokens: z.number().int().nonnegative().optional(),\n outputTokens: z.number().int().nonnegative().optional(),\n cacheReadTokens: z.number().int().nonnegative().optional(),\n cacheWriteTokens: z.number().int().nonnegative().optional(),\n reasoningTokens: z.number().int().nonnegative().optional(),\n totalCostUsd: z.number().nonnegative().optional(),\n numTurns: z.number().int().nonnegative().optional(),\n})\nexport type UsageSnapshot = z.infer<typeof UsageSnapshotSchema>\n\ntype ConcivProviderUsage = {\n modelId?: string\n contextWindow?: number\n totalCostUsd?: number\n numTurns?: number\n}\n\nexport function snapshotToTokenUsage(s: UsageSnapshot): TokenUsage {\n const provider: ConcivProviderUsage = {\n modelId: s.modelId,\n contextWindow: s.contextWindow,\n totalCostUsd: s.totalCostUsd,\n numTurns: s.numTurns,\n }\n return {\n promptTokens: s.inputTokens ?? 0,\n completionTokens: s.outputTokens ?? 0,\n totalTokens: (s.inputTokens ?? 0) + (s.outputTokens ?? 0),\n promptTokensDetails: {cachedTokens: s.cacheReadTokens, cacheWriteTokens: s.cacheWriteTokens},\n completionTokensDetails: {reasoningTokens: s.reasoningTokens},\n providerUsageDetails: provider,\n }\n}\n\nexport function tokenUsageToSnapshot(u: TokenUsage): UsageSnapshot {\n const p = (u.providerUsageDetails ?? {}) as ConcivProviderUsage\n return {\n modelId: p.modelId,\n contextWindow: p.contextWindow,\n inputTokens: u.promptTokens,\n outputTokens: u.completionTokens,\n cacheReadTokens: u.promptTokensDetails?.cachedTokens,\n cacheWriteTokens: u.promptTokensDetails?.cacheWriteTokens,\n reasoningTokens: u.completionTokensDetails?.reasoningTokens,\n totalCostUsd: p.totalCostUsd,\n numTurns: p.numTurns,\n }\n}\n\nexport const CONCIV_USAGE_EVENT = 'conciv-usage'\nexport function aguiUsageFor(snapshot: UsageSnapshot): StreamChunk {\n return {type: EventType.CUSTOM, name: CONCIV_USAGE_EVENT, value: snapshot}\n}\n\nexport function contextUsedTokens(s: UsageSnapshot): number | undefined {\n const parts = [s.inputTokens, s.cacheReadTokens, s.c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CACtC,OAAO;EACL,SAAS,EAAE;EACX,eAAe,EAAE;EACjB,aAAa,EAAE;EACf,cAAc,EAAE;EAChB,iBAAiB,EAAE,qBAAqB;EACxC,kBAAkB,EAAE,qBAAqB;EACzC,iBAAiB,EAAE,yBAAyB;EAC5C,cAAc,EAAE;EAChB,UAAU,EAAE;CACd;AACF;AAEA,MAAa,qBAAqB;AAClC,SAAgB,aAAa,UAAsC;CACjE,OAAO;EAAC,MAAM,UAAU;EAAQ,MAAM;EAAoB,OAAO;CAAQ;AAC3E;AAEA,SAAgB,kBAAkB,GAAsC;CACtE,MAAM,QAAQ;EAAC,EAAE;EAAa,EAAE;EAAiB,EAAE;CAAgB;CACnE,IAAI,MAAM,OAAO,MAAM,MAAM,KAAA,CAAS,GAAG,OAAO,KAAA;CAChD,OAAO,MAAM,QAAgB,KAAK,MAAM,OAAO,KAAK,IAAI,CAAC;AAC3D"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@conciv/protocol",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Wire types shared by the conciv vite-plugin and widget.",
5
5
  "keywords": [
6
6
  "ag-ui",
@@ -8,7 +8,7 @@
8
8
  "protocol",
9
9
  "types"
10
10
  ],
11
- "homepage": "https://github.com/conciv-dev/conciv/tree/main/packages/protocol#readme",
11
+ "homepage": "https://conciv.dev",
12
12
  "bugs": "https://github.com/conciv-dev/conciv/issues",
13
13
  "license": "MIT",
14
14
  "repository": {