@adecore/agent-contracts 0.65.2 → 0.66.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent.js +2 -1
- package/dist/chat.d.ts +29 -3
- package/dist/chat.js +24 -13
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/model.js +2 -1
- package/dist/task.js +5 -4
- package/dist/tolerance.d.ts +67 -0
- package/dist/tolerance.js +11 -0
- package/dist/usage.js +4 -1
- package/dist/wire-stamps.d.ts +52 -0
- package/dist/wire-stamps.js +308 -0
- package/package.json +8 -3
- package/src/agent.ts +2 -1
- package/src/chat.ts +87 -39
- package/src/index.ts +21 -0
- package/src/model.ts +2 -1
- package/src/task.ts +5 -4
- package/src/tolerance.ts +104 -0
- package/src/usage.ts +4 -1
- package/src/wire-stamps.ts +472 -0
package/dist/agent.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { SessionIdSchema } from './ids.js';
|
|
3
|
+
import { openValues } from './wire-stamps.js';
|
|
3
4
|
export const AGENT_KIND_MAX_LENGTH = 32;
|
|
4
5
|
/*
|
|
5
6
|
* Open, so a host can offer a CLI this version never heard of and an older client still reads a reply
|
|
@@ -13,7 +14,7 @@ export const AgentKindSchema = z
|
|
|
13
14
|
.regex(/^[a-z][a-z0-9-]*$/);
|
|
14
15
|
// `exited` is the daemon's own reading, not a hook's: the CLI went down with its shell without
|
|
15
16
|
// ever reporting an end, so the node offers a resume instead of a status that stays on running.
|
|
16
|
-
export const AgentStatusSchema = z.enum(['running', 'needs-you', 'idle', 'error', 'exited']);
|
|
17
|
+
export const AgentStatusSchema = openValues(z.enum(['running', 'needs-you', 'idle', 'error', 'exited']), 'AgentStatus', { words: 'strings' });
|
|
17
18
|
// Past this a model's name for a session is a summary, not a title.
|
|
18
19
|
export const SUGGESTED_TITLE_LIMIT = 80;
|
|
19
20
|
// Written by a model, so a node shows it as plain text and nothing reads it as an instruction.
|
package/dist/chat.d.ts
CHANGED
|
@@ -414,7 +414,17 @@ export declare const ChatInfoSchema: z.ZodObject<{
|
|
|
414
414
|
export type ChatInfo = z.infer<typeof ChatInfoSchema>;
|
|
415
415
|
export declare function holdsConversation(info: Pick<ChatInfo, 'agentSessionId' | 'activeTurnId'>): boolean;
|
|
416
416
|
export type ChatActivity = 'waiting' | 'working' | 'delegating' | 'background' | 'holding' | 'settled';
|
|
417
|
-
export declare function chatActivity(info:
|
|
417
|
+
export declare function chatActivity(info: {
|
|
418
|
+
readonly status: string;
|
|
419
|
+
readonly delegating?: boolean;
|
|
420
|
+
readonly background?: readonly unknown[];
|
|
421
|
+
readonly requests?: readonly unknown[];
|
|
422
|
+
readonly goal?: {
|
|
423
|
+
readonly status: string;
|
|
424
|
+
};
|
|
425
|
+
readonly queue?: readonly unknown[];
|
|
426
|
+
readonly activeTurnId?: string | null;
|
|
427
|
+
}): ChatActivity;
|
|
418
428
|
export declare const ChatSkillSourceSchema: z.ZodEnum<{
|
|
419
429
|
plugin: "plugin";
|
|
420
430
|
project: "project";
|
|
@@ -1559,6 +1569,13 @@ export declare const ChatItemSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
1559
1569
|
postTokens: z.ZodOptional<z.ZodNumber>;
|
|
1560
1570
|
}, z.core.$strip>], "kind">;
|
|
1561
1571
|
export type ChatItem = z.infer<typeof ChatItemSchema>;
|
|
1572
|
+
export interface ChatUnknownItem {
|
|
1573
|
+
readonly kind: 'unknown';
|
|
1574
|
+
readonly id: string;
|
|
1575
|
+
readonly createdAt: number;
|
|
1576
|
+
readonly turnId: string | null;
|
|
1577
|
+
readonly raw: Readonly<Record<string, unknown>>;
|
|
1578
|
+
}
|
|
1562
1579
|
export type ChatUserItem = z.infer<typeof ChatUserItemSchema>;
|
|
1563
1580
|
export type ChatAssistantItem = z.infer<typeof ChatAssistantItemSchema>;
|
|
1564
1581
|
export type ChatThinkingItem = z.infer<typeof ChatThinkingItemSchema>;
|
|
@@ -1570,9 +1587,13 @@ export type ChatTurnItem = z.infer<typeof ChatTurnItemSchema>;
|
|
|
1570
1587
|
export type ChatNoteItem = z.infer<typeof ChatNoteItemSchema>;
|
|
1571
1588
|
export type ChatNoteMessage = z.infer<typeof ChatNoteMessageSchema>;
|
|
1572
1589
|
export type ChatCompactionItem = z.infer<typeof ChatCompactionItemSchema>;
|
|
1573
|
-
|
|
1590
|
+
type ThreadItem = {
|
|
1591
|
+
readonly kind: string;
|
|
1592
|
+
readonly createdAt: number;
|
|
1593
|
+
};
|
|
1594
|
+
export declare function activeSubagents(items: readonly ThreadItem[]): ChatSubagentItem[];
|
|
1574
1595
|
export declare function workflowEndedAt(workflow: ChatWorkflow): number | null;
|
|
1575
|
-
export declare function activeWorkflows(items: readonly
|
|
1596
|
+
export declare function activeWorkflows(items: readonly ThreadItem[]): ChatToolItem[];
|
|
1576
1597
|
export declare const CHAT_OUTLINE_TEXT_CHARS = 280;
|
|
1577
1598
|
export declare function outlineItems(items: readonly ChatItem[], marked?: ReadonlySet<string>): ChatItem[];
|
|
1578
1599
|
export declare const ChatEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
@@ -2828,6 +2849,10 @@ export declare const ChatEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
2828
2849
|
}, z.core.$strip>], "kind">>;
|
|
2829
2850
|
}, z.core.$strip>], "type">;
|
|
2830
2851
|
export type ChatEvent = z.infer<typeof ChatEventSchema>;
|
|
2852
|
+
export interface ChatUnknownEvent {
|
|
2853
|
+
readonly type: 'unknown';
|
|
2854
|
+
readonly raw: Readonly<Record<string, unknown>>;
|
|
2855
|
+
}
|
|
2831
2856
|
export declare const ChatEventEnvelopeSchema: z.ZodObject<{
|
|
2832
2857
|
chatId: z.ZodString;
|
|
2833
2858
|
event: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
@@ -8893,3 +8918,4 @@ export declare const GeneratedImageInputSchema: z.ZodObject<{
|
|
|
8893
8918
|
}, z.core.$strip>;
|
|
8894
8919
|
export type GeneratedImageInput = z.infer<typeof GeneratedImageInputSchema>;
|
|
8895
8920
|
export declare function generatedImageAttachment(item: ChatItem): ChatAttachment | null;
|
|
8921
|
+
export {};
|
package/dist/chat.js
CHANGED
|
@@ -5,6 +5,7 @@ import { AgentKindSchema, AgentStatusSchema, SuggestedTitleSchema } from './agen
|
|
|
5
5
|
import { ModelSelectionSchema, RuntimeModeSchema } from './model.js';
|
|
6
6
|
import { ProviderAccountIdSchema } from './provider-accounts.js';
|
|
7
7
|
import { ChatVisualsSchema } from './visual.js';
|
|
8
|
+
import { lossyItems, openUnion, openValues } from './wire-stamps.js';
|
|
8
9
|
import { WorktreeSchema } from './worktree.js';
|
|
9
10
|
// The client picks the id (its node id), like a terminal session.
|
|
10
11
|
export const ChatIdSchema = z.string().min(1);
|
|
@@ -129,7 +130,7 @@ export const ChatQueuedMessageSchema = z.object({
|
|
|
129
130
|
export const ChatBackgroundTaskSchema = z.object({
|
|
130
131
|
// The CLI's own id for the task, which is what stopping it names.
|
|
131
132
|
id: z.string().min(1),
|
|
132
|
-
kind: z.enum(['shell', 'monitor']),
|
|
133
|
+
kind: openValues(z.enum(['shell', 'monitor']), 'ChatBackgroundTaskKind'),
|
|
133
134
|
description: z.string(),
|
|
134
135
|
command: z.string().nullable(),
|
|
135
136
|
startedAt: z.number()
|
|
@@ -139,7 +140,7 @@ export const ChatBackgroundTaskSchema = z.object({
|
|
|
139
140
|
* too busy to answer. Not a state of its own, since a client that validates `state` knows four.
|
|
140
141
|
*/
|
|
141
142
|
export const ChatTurnLimitSchema = z.object({
|
|
142
|
-
kind: z.enum(['usage', 'overload']),
|
|
143
|
+
kind: openValues(z.enum(['usage', 'overload']), 'ChatTurnLimitKind'),
|
|
143
144
|
// When the limit lifts, in milliseconds since the epoch; absent when the CLI named no time.
|
|
144
145
|
resetsAt: z.number().optional()
|
|
145
146
|
});
|
|
@@ -149,7 +150,7 @@ export const ChatTurnLimitSchema = z.object({
|
|
|
149
150
|
* a new value inside one it already knew. `usage-limited` and `budget-limited` are Codex's: the plan's limit,
|
|
150
151
|
* or the token budget the goal was given.
|
|
151
152
|
*/
|
|
152
|
-
export const ChatGoalStatusSchema = z.enum(['active', 'paused', 'blocked', 'usage-limited', 'budget-limited', 'complete']);
|
|
153
|
+
export const ChatGoalStatusSchema = openValues(z.enum(['active', 'paused', 'blocked', 'usage-limited', 'budget-limited', 'complete']), 'ChatGoalStatus');
|
|
153
154
|
export const ChatGoalSchema = z.object({
|
|
154
155
|
objective: z.string(),
|
|
155
156
|
status: ChatGoalStatusSchema,
|
|
@@ -168,7 +169,8 @@ export const ChatQuestionSchema = z.object({
|
|
|
168
169
|
choices: z.array(z.object({ label: z.string(), description: z.string() })),
|
|
169
170
|
multiSelect: z.boolean()
|
|
170
171
|
});
|
|
171
|
-
|
|
172
|
+
// A request of a kind this version does not know still says a chat waits on a person, and is never answered from here.
|
|
173
|
+
export const ChatRequestKindSchema = openValues(z.enum(['approval', 'question']), 'ChatRequestKind', { words: 'strings' });
|
|
172
174
|
/*
|
|
173
175
|
* Where a request summary stops, in UTF-16 code units and lines. The schema holds no `max` on purpose: one
|
|
174
176
|
* cut a daemon got wrong would refuse every `chat.list` that carried it. Choice labels and question ids stay
|
|
@@ -273,6 +275,7 @@ export const ChatInfoSchema = z.object({
|
|
|
273
275
|
export function holdsConversation(info) {
|
|
274
276
|
return info.agentSessionId !== null || info.activeTurnId !== null;
|
|
275
277
|
}
|
|
278
|
+
// Only compares, so a client's info with a newer machine's words in it reads here as well.
|
|
276
279
|
export function chatActivity(info) {
|
|
277
280
|
if (info.status === 'needs-you') {
|
|
278
281
|
return 'waiting';
|
|
@@ -656,7 +659,7 @@ export const ChatCompactionItemSchema = z.object({
|
|
|
656
659
|
* native client validates `chat.attach` and `chat.history` whole, so one item it does not know rejects
|
|
657
660
|
* the entire conversation. Add optional fields instead.
|
|
658
661
|
*/
|
|
659
|
-
export const ChatItemSchema = z.discriminatedUnion('kind', [
|
|
662
|
+
export const ChatItemSchema = openUnion(z.discriminatedUnion('kind', [
|
|
660
663
|
ChatUserItemSchema,
|
|
661
664
|
ChatAssistantItemSchema,
|
|
662
665
|
ChatThinkingItemSchema,
|
|
@@ -667,7 +670,13 @@ export const ChatItemSchema = z.discriminatedUnion('kind', [
|
|
|
667
670
|
ChatTurnItemSchema,
|
|
668
671
|
ChatNoteItemSchema,
|
|
669
672
|
ChatCompactionItemSchema
|
|
670
|
-
]);
|
|
673
|
+
]), 'ChatItem', { tag: 'kind', base: ['id', 'createdAt', 'turnId'] });
|
|
674
|
+
function isSubagentItem(item) {
|
|
675
|
+
return item.kind === 'subagent';
|
|
676
|
+
}
|
|
677
|
+
function isToolItem(item) {
|
|
678
|
+
return item.kind === 'tool';
|
|
679
|
+
}
|
|
671
680
|
/*
|
|
672
681
|
* The sub-agents a chat still speaks of beside its thread: every one at work, and the ones that settled
|
|
673
682
|
* since the last message, so a finished batch stays until the next message is sent. That includes an
|
|
@@ -679,14 +688,14 @@ export function activeSubagents(items) {
|
|
|
679
688
|
const lastMessageAt = lastMessage < 0 ? null : items[lastMessage].createdAt;
|
|
680
689
|
const turns = new Set();
|
|
681
690
|
for (const item of items) {
|
|
682
|
-
if (item
|
|
691
|
+
if (isSubagentItem(item) && item.status === 'running' && item.turnId !== null) {
|
|
683
692
|
turns.add(item.turnId);
|
|
684
693
|
}
|
|
685
694
|
}
|
|
686
695
|
const active = [];
|
|
687
696
|
for (let index = 0; index < items.length; index++) {
|
|
688
697
|
const item = items[index];
|
|
689
|
-
if (item
|
|
698
|
+
if (isSubagentItem(item) &&
|
|
690
699
|
(item.status === 'running' ||
|
|
691
700
|
index > lastMessage ||
|
|
692
701
|
(lastMessageAt !== null && item.finishedAt !== null && item.finishedAt > lastMessageAt) ||
|
|
@@ -716,7 +725,7 @@ export function activeWorkflows(items) {
|
|
|
716
725
|
const lastMessage = items.findLastIndex((item) => item.kind === 'user');
|
|
717
726
|
const lastMessageAt = lastMessage < 0 ? null : items[lastMessage].createdAt;
|
|
718
727
|
return items.filter((item, index) => {
|
|
719
|
-
if (item
|
|
728
|
+
if (!isToolItem(item) || item.name !== 'Workflow' || item.workflow === undefined) {
|
|
720
729
|
return false;
|
|
721
730
|
}
|
|
722
731
|
if (item.state === 'running' || index > lastMessage) {
|
|
@@ -754,7 +763,7 @@ export function outlineItems(items, marked = new Set()) {
|
|
|
754
763
|
return outline;
|
|
755
764
|
}
|
|
756
765
|
// Events apply after the `chat.attach` snapshot; item ids make upserts and streamed deltas replayable.
|
|
757
|
-
export const ChatEventSchema = z.discriminatedUnion('type', [
|
|
766
|
+
export const ChatEventSchema = openUnion(z.discriminatedUnion('type', [
|
|
758
767
|
z.object({ type: z.literal('item'), item: ChatItemSchema, historyIndex: z.number().int().nonnegative().optional() }),
|
|
759
768
|
z.object({
|
|
760
769
|
type: z.literal('delta'),
|
|
@@ -766,7 +775,7 @@ export const ChatEventSchema = z.discriminatedUnion('type', [
|
|
|
766
775
|
}),
|
|
767
776
|
z.object({ type: z.literal('info'), info: ChatInfoSchema }),
|
|
768
777
|
z.object({ type: z.literal('reset'), info: ChatInfoSchema, items: z.array(ChatItemSchema) })
|
|
769
|
-
]);
|
|
778
|
+
]), 'ChatEvent', { tag: 'type', base: [] });
|
|
770
779
|
export const ChatEventEnvelopeSchema = z.object({
|
|
771
780
|
chatId: ChatIdSchema,
|
|
772
781
|
event: ChatEventSchema,
|
|
@@ -852,7 +861,9 @@ export const ChatSubagentResultSchema = z.object({
|
|
|
852
861
|
items: z.array(ChatItemSchema),
|
|
853
862
|
history: ChatSubagentPageSchema,
|
|
854
863
|
// A request still waiting must remain answerable after it leaves the newest page.
|
|
855
|
-
pending: z
|
|
864
|
+
pending: z
|
|
865
|
+
.array(openUnion(z.union([ChatApprovalItemSchema, ChatQuestionItemSchema]), 'ChatPendingRequest', { tag: 'kind', base: ['id', 'createdAt', 'turnId'] }))
|
|
866
|
+
.optional(),
|
|
856
867
|
source: ChatSubagentSourceSchema,
|
|
857
868
|
context: z.object({ provider: AgentKindSchema, cwd: z.string(), chatId: ChatIdSchema.optional() }).optional(),
|
|
858
869
|
// Whether the subagent is still writing, so a client knows to keep reading.
|
|
@@ -1061,7 +1072,7 @@ export const ChatForkInfoResultSchema = z.object({
|
|
|
1061
1072
|
filesAfterTurn: z.boolean()
|
|
1062
1073
|
});
|
|
1063
1074
|
export const ChatListResultSchema = z.object({
|
|
1064
|
-
chats: z.array(ChatInfoSchema)
|
|
1075
|
+
chats: lossyItems(z.array(ChatInfoSchema))
|
|
1065
1076
|
});
|
|
1066
1077
|
export const GeneratedImageInputSchema = z.object({
|
|
1067
1078
|
attachment: ChatAttachmentSchema.optional(),
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { AGENT_KIND_MAX_LENGTH, AgentKindSchema, type AgentKind, AgentStatusSchema, type AgentStatus, SUGGESTED_TITLE_LIMIT, SuggestedTitleSchema, AgentRequestSchema, type AgentRequest, AgentInfoSchema, type AgentInfo, SessionStatusEventSchema, type SessionStatusEvent, AgentResumePayloadSchema, type AgentResumePayload, ApprovalChoiceSchema, type ApprovalChoice, ApprovalRequestSchema, type ApprovalRequest, SessionApprovalsEventSchema, type SessionApprovalsEvent, ApprovalAnswerPayloadSchema, type ApprovalAnswerPayload, ApprovalAnswerResultSchema, type ApprovalAnswerResult, ApprovalPreferencePayloadSchema, type ApprovalPreferencePayload } from './agent.ts';
|
|
2
|
-
export { ChatIdSchema, type ChatId, ChatContextBreakdownSchema, type ChatContextBreakdown, ChatUsageSchema, type ChatUsage, CHAT_ATTACHMENTS_MAX_BYTES, CHAT_ATTACHMENT_MAX_BYTES, CHAT_ATTACHMENTS_MAX_COUNT, attachmentBytes, attachmentImageMime, ChatAttachmentUploadSchema, type ChatAttachmentUpload, ChatAttachmentUploadsSchema, ChatAttachmentSchema, type ChatAttachment, ChatUiChoiceOriginSchema, type ChatUiChoiceOrigin, ChatUiAnswerSchema, type ChatUiAnswer, ChatQuoteSourceSchema, type ChatQuoteSource, ChatQueuedMessageSchema, type ChatQueuedMessage, ChatBackgroundTaskSchema, type ChatBackgroundTask, ChatTurnLimitSchema, type ChatTurnLimit, ChatGoalStatusSchema, type ChatGoalStatus, ChatGoalSchema, type ChatGoal, ChatQuestionSchema, type ChatQuestion, ChatRequestKindSchema, type ChatRequestKind, CHAT_REQUEST_LIMITS, ChatRequestApprovalSchema, type ChatRequestApproval, ChatRequestSummarySchema, type ChatRequestSummary, ChatInfoSchema, type ChatInfo, ChatSkillSourceSchema, type ChatSkillSource, ChatSkillSchema, type ChatSkill, SkillsListPayloadSchema, type SkillsListPayload, SkillsListResultSchema, type SkillsListResult, ChatUserItemSchema, ChatUiQueryReadingSchema, type ChatUiQueryReading, ChatUiLinkReadingSchema, type ChatUiLinkReading, ChatUiPlaceReadingSchema, type ChatUiPlaceReading, ChatUiQueryStateSchema, type ChatUiQueryState, ChatAssistantItemSchema, ChatThinkingItemSchema, ChatToolStateSchema, type ChatToolState, ChatToolProgressSchema, type ChatToolProgress, ChatFileChangeSchema, type ChatFileChange, ChatSubagentStatusSchema, type ChatSubagentStatus, ChatWorkflowPhaseSchema, type ChatWorkflowPhase, ChatWorkflowAgentSchema, type ChatWorkflowAgent, ChatWorkflowSchema, type ChatWorkflow, workflowAgentRef, workflowAgentIdOf, CHAT_PAYLOAD_INLINE_BYTES, ChatPayloadRefSchema, type ChatPayloadRef, ChatToolItemSchema, ChatSubagentUsageSchema, type ChatSubagentUsage, HOST_TASK_ORIGIN, taskRowId, taskIdOfRow, ChatSubagentItemSchema, ChatApprovalDecisionSchema, type ChatApprovalDecision, ChatApprovalItemSchema, ChatQuestionItemSchema, ChatCheckpointFileSchema, type ChatCheckpointFile, ChatCheckpointDiffSchema, type ChatCheckpointDiff, ChatTurnItemSchema, notResumedNote, abortedByMachine, ENDED_NOTE_PREFIX, abortedByEnd, activeSubagents, activeWorkflows, workflowEndedAt, CHAT_OUTLINE_TEXT_CHARS, outlineItems, WAITING_NOTE_PREFIX, ChatNoteItemSchema, ChatNoteMessageSchema, ChatCompactionItemSchema, ChatItemSchema, type ChatItem, type ChatUserItem, type ChatAssistantItem, type ChatThinkingItem, type ChatToolItem, type ChatSubagentItem, type ChatApprovalItem, type ChatQuestionItem, type ChatTurnItem, type ChatNoteItem, type ChatNoteMessage, type ChatCompactionItem, ChatEventSchema, type ChatEvent, ChatEventEnvelopeSchema, type ChatEventEnvelope, ChatCreatePayloadSchema, type ChatCreatePayload, ChatConfigurePayloadSchema, type ChatConfigurePayload, ChatPreferencesPayloadSchema, type ChatPreferencesPayload, ChatTargetPayloadSchema, type ChatTargetPayload, ChatClearPayloadSchema, type ChatClearPayload, ChatCancelPayloadSchema, type ChatCancelPayload, ChatAttachPayloadSchema, ChatHistoryPayloadSchema, ChatHistoryPageSchema, ChatHistoryResultSchema, type ChatHistoryResult, ChatSubagentPayloadSchema, type ChatSubagentPayload, ChatStopSubagentPayloadSchema, type ChatStopSubagentPayload, ChatGoalActionSchema, type ChatGoalAction, ChatGoalPayloadSchema, type ChatGoalPayload, ChatStopTaskPayloadSchema, type ChatStopTaskPayload, ChatSubagentPageSchema, ChatSubagentSourceSchema, type ChatSubagentSource, ChatSubagentResultSchema, type ChatSubagentResult, ChatStatusEventSchema, type ChatStatusEvent, ChatSubagentChangedEventSchema, type ChatSubagentChangedEvent, CHAT_BOOKMARK_LIMITS, ChatBookmarkSchema, type ChatBookmark, ChatBookmarksSchema, ChatAddBookmarkPayloadSchema, type ChatAddBookmarkPayload, ChatRenameBookmarkPayloadSchema, type ChatRenameBookmarkPayload, ChatRemoveBookmarkPayloadSchema, type ChatRemoveBookmarkPayload, ChatBookmarksResultSchema, type ChatBookmarksResult, ChatBookmarksEventSchema, type ChatBookmarksEvent, ChatRemoveVisualPayloadSchema, type ChatRemoveVisualPayload, ChatVisualsResultSchema, type ChatVisualsResult, ChatVisualsEventSchema, type ChatVisualsEvent, ChatAttachResultSchema, type ChatAttachResult, ChatDeliverySchema, type ChatDelivery, ChatSendPayloadSchema, type ChatSendPayload, ChatSendResultSchema, type ChatSendResult, ChatUiChoicePayloadSchema, type ChatUiChoicePayload, ChatUiQueryPayloadSchema, type ChatUiQueryPayload, ChatUiLinkPayloadSchema, type ChatUiLinkPayload, ChatQueuePayloadSchema, type ChatQueuePayload, ChatUnqueueResultSchema, type ChatUnqueueResult, ChatApprovePayloadSchema, type ChatApprovePayload, ChatDismissPayloadSchema, type ChatDismissPayload, ChatAnswerPayloadSchema, type ChatAnswerPayload, ChatTurnDiffPayloadSchema, type ChatTurnDiffPayload, ChatTurnDiffResultSchema, type ChatTurnDiffResult, ChatToolOutputPayloadSchema, type ChatToolOutputPayload, ChatToolOutputResultSchema, type ChatToolOutputResult, CHAT_FORK_TITLE_MAX, ChatForkPayloadSchema, type ChatForkPayload, ChatForkResultSchema, type ChatForkResult, ChatContinueOnPayloadSchema, type ChatContinueOnPayload, ChatContinueOnResultSchema, type ChatContinueOnResult, ChatSummarizePayloadSchema, type ChatSummarizePayload, ChatSummarizeResultSchema, type ChatSummarizeResult, ChatForkInfoPayloadSchema, type ChatForkInfoPayload, ChatForkInfoResultSchema, type ChatForkInfoResult, ChatListResultSchema, type ChatListResult, GeneratedImageInputSchema, type GeneratedImageInput, generatedImageAttachment, holdsConversation, chatActivity, type ChatActivity } from './chat.ts';
|
|
2
|
+
export { ChatIdSchema, type ChatId, ChatContextBreakdownSchema, type ChatContextBreakdown, ChatUsageSchema, type ChatUsage, CHAT_ATTACHMENTS_MAX_BYTES, CHAT_ATTACHMENT_MAX_BYTES, CHAT_ATTACHMENTS_MAX_COUNT, attachmentBytes, attachmentImageMime, ChatAttachmentUploadSchema, type ChatAttachmentUpload, ChatAttachmentUploadsSchema, ChatAttachmentSchema, type ChatAttachment, ChatUiChoiceOriginSchema, type ChatUiChoiceOrigin, ChatUiAnswerSchema, type ChatUiAnswer, ChatQuoteSourceSchema, type ChatQuoteSource, ChatQueuedMessageSchema, type ChatQueuedMessage, ChatBackgroundTaskSchema, type ChatBackgroundTask, ChatTurnLimitSchema, type ChatTurnLimit, ChatGoalStatusSchema, type ChatGoalStatus, ChatGoalSchema, type ChatGoal, ChatQuestionSchema, type ChatQuestion, ChatRequestKindSchema, type ChatRequestKind, CHAT_REQUEST_LIMITS, ChatRequestApprovalSchema, type ChatRequestApproval, ChatRequestSummarySchema, type ChatRequestSummary, ChatInfoSchema, type ChatInfo, ChatSkillSourceSchema, type ChatSkillSource, ChatSkillSchema, type ChatSkill, SkillsListPayloadSchema, type SkillsListPayload, SkillsListResultSchema, type SkillsListResult, ChatUserItemSchema, ChatUiQueryReadingSchema, type ChatUiQueryReading, ChatUiLinkReadingSchema, type ChatUiLinkReading, ChatUiPlaceReadingSchema, type ChatUiPlaceReading, ChatUiQueryStateSchema, type ChatUiQueryState, ChatAssistantItemSchema, ChatThinkingItemSchema, ChatToolStateSchema, type ChatToolState, ChatToolProgressSchema, type ChatToolProgress, ChatFileChangeSchema, type ChatFileChange, ChatSubagentStatusSchema, type ChatSubagentStatus, ChatWorkflowPhaseSchema, type ChatWorkflowPhase, ChatWorkflowAgentSchema, type ChatWorkflowAgent, ChatWorkflowSchema, type ChatWorkflow, workflowAgentRef, workflowAgentIdOf, CHAT_PAYLOAD_INLINE_BYTES, ChatPayloadRefSchema, type ChatPayloadRef, ChatToolItemSchema, ChatSubagentUsageSchema, type ChatSubagentUsage, HOST_TASK_ORIGIN, taskRowId, taskIdOfRow, ChatSubagentItemSchema, ChatApprovalDecisionSchema, type ChatApprovalDecision, ChatApprovalItemSchema, ChatQuestionItemSchema, ChatCheckpointFileSchema, type ChatCheckpointFile, ChatCheckpointDiffSchema, type ChatCheckpointDiff, ChatTurnItemSchema, notResumedNote, abortedByMachine, ENDED_NOTE_PREFIX, abortedByEnd, activeSubagents, activeWorkflows, workflowEndedAt, CHAT_OUTLINE_TEXT_CHARS, outlineItems, WAITING_NOTE_PREFIX, ChatNoteItemSchema, ChatNoteMessageSchema, ChatCompactionItemSchema, ChatItemSchema, type ChatItem, type ChatUserItem, type ChatAssistantItem, type ChatThinkingItem, type ChatToolItem, type ChatSubagentItem, type ChatApprovalItem, type ChatQuestionItem, type ChatTurnItem, type ChatNoteItem, type ChatNoteMessage, type ChatCompactionItem, type ChatUnknownItem, ChatEventSchema, type ChatEvent, type ChatUnknownEvent, ChatEventEnvelopeSchema, type ChatEventEnvelope, ChatCreatePayloadSchema, type ChatCreatePayload, ChatConfigurePayloadSchema, type ChatConfigurePayload, ChatPreferencesPayloadSchema, type ChatPreferencesPayload, ChatTargetPayloadSchema, type ChatTargetPayload, ChatClearPayloadSchema, type ChatClearPayload, ChatCancelPayloadSchema, type ChatCancelPayload, ChatAttachPayloadSchema, ChatHistoryPayloadSchema, ChatHistoryPageSchema, ChatHistoryResultSchema, type ChatHistoryResult, ChatSubagentPayloadSchema, type ChatSubagentPayload, ChatStopSubagentPayloadSchema, type ChatStopSubagentPayload, ChatGoalActionSchema, type ChatGoalAction, ChatGoalPayloadSchema, type ChatGoalPayload, ChatStopTaskPayloadSchema, type ChatStopTaskPayload, ChatSubagentPageSchema, ChatSubagentSourceSchema, type ChatSubagentSource, ChatSubagentResultSchema, type ChatSubagentResult, ChatStatusEventSchema, type ChatStatusEvent, ChatSubagentChangedEventSchema, type ChatSubagentChangedEvent, CHAT_BOOKMARK_LIMITS, ChatBookmarkSchema, type ChatBookmark, ChatBookmarksSchema, ChatAddBookmarkPayloadSchema, type ChatAddBookmarkPayload, ChatRenameBookmarkPayloadSchema, type ChatRenameBookmarkPayload, ChatRemoveBookmarkPayloadSchema, type ChatRemoveBookmarkPayload, ChatBookmarksResultSchema, type ChatBookmarksResult, ChatBookmarksEventSchema, type ChatBookmarksEvent, ChatRemoveVisualPayloadSchema, type ChatRemoveVisualPayload, ChatVisualsResultSchema, type ChatVisualsResult, ChatVisualsEventSchema, type ChatVisualsEvent, ChatAttachResultSchema, type ChatAttachResult, ChatDeliverySchema, type ChatDelivery, ChatSendPayloadSchema, type ChatSendPayload, ChatSendResultSchema, type ChatSendResult, ChatUiChoicePayloadSchema, type ChatUiChoicePayload, ChatUiQueryPayloadSchema, type ChatUiQueryPayload, ChatUiLinkPayloadSchema, type ChatUiLinkPayload, ChatQueuePayloadSchema, type ChatQueuePayload, ChatUnqueueResultSchema, type ChatUnqueueResult, ChatApprovePayloadSchema, type ChatApprovePayload, ChatDismissPayloadSchema, type ChatDismissPayload, ChatAnswerPayloadSchema, type ChatAnswerPayload, ChatTurnDiffPayloadSchema, type ChatTurnDiffPayload, ChatTurnDiffResultSchema, type ChatTurnDiffResult, ChatToolOutputPayloadSchema, type ChatToolOutputPayload, ChatToolOutputResultSchema, type ChatToolOutputResult, CHAT_FORK_TITLE_MAX, ChatForkPayloadSchema, type ChatForkPayload, ChatForkResultSchema, type ChatForkResult, ChatContinueOnPayloadSchema, type ChatContinueOnPayload, ChatContinueOnResultSchema, type ChatContinueOnResult, ChatSummarizePayloadSchema, type ChatSummarizePayload, ChatSummarizeResultSchema, type ChatSummarizeResult, ChatForkInfoPayloadSchema, type ChatForkInfoPayload, ChatForkInfoResultSchema, type ChatForkInfoResult, ChatListResultSchema, type ChatListResult, GeneratedImageInputSchema, type GeneratedImageInput, generatedImageAttachment, holdsConversation, chatActivity, type ChatActivity } from './chat.ts';
|
|
3
3
|
export { ErrorSchema, type WireError, RequestSchema, type Request, ReplyOkSchema, type ReplyOk, ReplyErrorSchema, type ReplyError, ReplySchema, type Reply, EventSchema, type Event, ServerFrameSchema, type ServerFrame, type ParseResult, parseRequest, parseServerFrame } from './envelope.ts';
|
|
4
4
|
export { SessionIdSchema, type SessionId } from './ids.ts';
|
|
5
5
|
export { ModelOptionChoiceSchema, type ModelOptionChoice, ModelOptionDescriptorSchema, type ModelOptionDescriptor, ModelInfoSchema, type ModelInfo, ModelSelectionSchema, type ModelSelection, ModelCatalogProfileSchema, type ModelCatalogProfile, ModelCatalogEntrySchema, type ModelCatalogEntry, ModelCatalogDataSchema, type ModelCatalogData, RuntimeModeSchema, type RuntimeMode, ProviderCapabilitiesSchema, type ProviderCapabilities, ProviderPlatformSchema, type ProviderPlatform, ProviderSignInSchema, type ProviderSignIn, ProviderInstallSchema, type ProviderInstall, ProviderInfoSchema, type ProviderInfo, FRONTIER_PROVIDER_KINDS, API_PROVIDER_KINDS, type ProviderPickerGroup, type ProviderPickerGroups, providerGroupOf, pickerGroupsOf, inPickerOrder, separatesGroups, ProviderListResultSchema, type ProviderListResult, resumeCommandFor } from './model.ts';
|
|
@@ -8,6 +8,7 @@ export { EmptySchema, AGENT_REQUEST_SCHEMAS, AGENT_EVENT_SCHEMAS, type AgentRequ
|
|
|
8
8
|
export { ProviderAccountIdSchema, type ProviderAccountId, ProviderAccountVariableSchema, type ProviderAccountVariable, ProviderAccountSchema, type ProviderAccount, ProviderAccountStateSchema, type ProviderAccountState, ProviderAccountStatusSchema, type ProviderAccountStatus, ProviderAccountMapSchema, type ProviderAccountMap, ProviderAccountsSchema, type ProviderAccounts, ProviderAccountsSavePayloadSchema, type ProviderAccountsSavePayload, ProviderAccountCreatePayloadSchema, type ProviderAccountCreatePayload, ProviderAccountCreateResultSchema, type ProviderAccountCreateResult, ProviderAccountWatchLoginPayloadSchema, type ProviderAccountWatchLoginPayload, ProviderAccountsReorderPayloadSchema, type ProviderAccountsReorderPayload, ProviderAccountsShareConfigPayloadSchema, type ProviderAccountsShareConfigPayload, orderedAccountIds, topAccountOf } from './provider-accounts.ts';
|
|
9
9
|
export { TaskStatusSchema, type TaskStatus, TaskResultSchema, type TaskResult, TaskSchema, type Task, TaskChangedEventSchema, type TaskChangedEvent } from './task.ts';
|
|
10
10
|
export { clipText, TOOL_OUTPUT_TAIL, appendToolOutput } from './text.ts';
|
|
11
|
+
export { openUnion, lossyItems, openValues, wireStampOf, wireStampsIn, type WireStamp, type WireStampAt, type WireDegradation, readTolerant, type ToleratedRead, type Tolerant, type TolerantWith, type OpenUnionTable, type OpenWordTable, type OpenUnions, type OpenWords, type UnknownWord } from './tolerance.ts';
|
|
11
12
|
export { type ToolFileEdit, type ToolFileEditPiece, toolFileEdit } from './tool-edits.ts';
|
|
12
13
|
export { UsageProviderSchema, type UsageProvider, USAGE_PROVIDERS, UsageResolutionSchema, type UsageResolution, UsageTotalsSchema, type UsageTotals, EMPTY_TOTALS, totalTokensOf, addTotals, UsageAccountSchema, type UsageAccount, UsageBucketSchema, type UsageBucket, UsagePriceBasisSchema, type UsagePriceBasis, UsageModelSchema, type UsageModel, UsageProjectSchema, type UsageProject, UsageSummaryPayloadSchema, type UsageSummaryPayload, UsageScanSchema, type UsageScan, UsagePricingSchema, type UsagePricing, UsageRootSchema, type UsageRoot, UsageRateSchema, type UsageRate, UsageSummaryResultSchema, type UsageSummaryResult, UsageChangedEventSchema, type UsageChangedEvent, UsageWindowSchema, type UsageWindow, type PaceStanding, type EvenPace, evenPace, UsageLimitsProviderSchema, type UsageLimitsProvider, UsageLimitsSnapshotSchema, type UsageLimitsSnapshot } from './usage.ts';
|
|
13
14
|
export { VISUAL_LIMITS, VISUAL_MEASURE_WIDTHS, REPLY_COLUMN_WIDTH, VisualHeightSchema, type VisualHeight, VisualLayoutSchema, type VisualLayout, ChatVisualSchema, type ChatVisual, ChatVisualsSchema, visualFrameHeight, VISUAL_BRIDGE_METHODS, type VisualAppearance, type VisualTheme, type VisualRequestId, type VisualViewport, type VisualScrollRequest, visualViewportMessage, visualScrollMessage, type VisualMessage, visualProxyReadyMessage, visualResourceReadyMessage, visualHostContextMessage, visualSizeChangedMessage, visualOpenLinkRequest, visualOpenLinkResult, parseVisualMessage, VISUAL_THEME_VARIABLES, type VisualThemeVariable, VISUAL_LIGHT_THEME, VISUAL_DARK_THEME, cleanVisualVariables, visualThemeFragment, VISUAL_PAGE_RULES, VISUAL_LAYOUT_GUIDE, VISUAL_THEME_GUIDE, injectVisualBootstrap, VISUAL_HOST_PAGE } from './visual.ts';
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export { EmptySchema, AGENT_REQUEST_SCHEMAS, AGENT_EVENT_SCHEMAS } from './proto
|
|
|
8
8
|
export { ProviderAccountIdSchema, ProviderAccountVariableSchema, ProviderAccountSchema, ProviderAccountStateSchema, ProviderAccountStatusSchema, ProviderAccountMapSchema, ProviderAccountsSchema, ProviderAccountsSavePayloadSchema, ProviderAccountCreatePayloadSchema, ProviderAccountCreateResultSchema, ProviderAccountWatchLoginPayloadSchema, ProviderAccountsReorderPayloadSchema, ProviderAccountsShareConfigPayloadSchema, orderedAccountIds, topAccountOf } from './provider-accounts.js';
|
|
9
9
|
export { TaskStatusSchema, TaskResultSchema, TaskSchema, TaskChangedEventSchema } from './task.js';
|
|
10
10
|
export { clipText, TOOL_OUTPUT_TAIL, appendToolOutput } from './text.js';
|
|
11
|
+
export { openUnion, lossyItems, openValues, wireStampOf, wireStampsIn, readTolerant } from './tolerance.js';
|
|
11
12
|
export { toolFileEdit } from './tool-edits.js';
|
|
12
13
|
export { UsageProviderSchema, USAGE_PROVIDERS, UsageResolutionSchema, UsageTotalsSchema, EMPTY_TOTALS, totalTokensOf, addTotals, UsageAccountSchema, UsageBucketSchema, UsagePriceBasisSchema, UsageModelSchema, UsageProjectSchema, UsageSummaryPayloadSchema, UsageScanSchema, UsagePricingSchema, UsageRootSchema, UsageRateSchema, UsageSummaryResultSchema, UsageChangedEventSchema, UsageWindowSchema, evenPace, UsageLimitsProviderSchema, UsageLimitsSnapshotSchema } from './usage.js';
|
|
13
14
|
export { VISUAL_LIMITS, VISUAL_MEASURE_WIDTHS, REPLY_COLUMN_WIDTH, VisualHeightSchema, VisualLayoutSchema, ChatVisualSchema, ChatVisualsSchema, visualFrameHeight, VISUAL_BRIDGE_METHODS, visualViewportMessage, visualScrollMessage, visualProxyReadyMessage, visualResourceReadyMessage, visualHostContextMessage, visualSizeChangedMessage, visualOpenLinkRequest, visualOpenLinkResult, parseVisualMessage, VISUAL_THEME_VARIABLES, VISUAL_LIGHT_THEME, VISUAL_DARK_THEME, cleanVisualVariables, visualThemeFragment, VISUAL_PAGE_RULES, VISUAL_LAYOUT_GUIDE, VISUAL_THEME_GUIDE, injectVisualBootstrap, VISUAL_HOST_PAGE } from './visual.js';
|
package/dist/model.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { AgentKindSchema } from './agent.js';
|
|
3
|
+
import { openValues } from './wire-stamps.js';
|
|
3
4
|
// Options a model exposes (effort, context window, thinking). Generic descriptors rather than
|
|
4
5
|
// per-provider enums, so a new model needs a catalog entry and no code change.
|
|
5
6
|
export const ModelOptionChoiceSchema = z.object({
|
|
@@ -77,7 +78,7 @@ export const ModelCatalogDataSchema = z
|
|
|
77
78
|
.refine((data) => data.models.every((model) => data.profiles[model.profile] !== undefined), 'Every model needs a profile the catalog has')
|
|
78
79
|
.refine((data) => data.models.some((model) => model.slug === data.defaultModel), 'The default model has to be one of the models');
|
|
79
80
|
// The thread's permission policy, one vocabulary for every provider; each adapter maps it.
|
|
80
|
-
export const RuntimeModeSchema = z.enum(['supervised', 'auto-accept-edits', 'auto', 'full-access']);
|
|
81
|
+
export const RuntimeModeSchema = openValues(z.enum(['supervised', 'auto-accept-edits', 'auto', 'full-access']), 'RuntimeMode', { words: 'strings' });
|
|
81
82
|
// What a provider's CLI can do, so a client never offers what it would drop and the daemon
|
|
82
83
|
// never asks for what the protocol has no room for.
|
|
83
84
|
export const ProviderCapabilitiesSchema = z.object({
|
package/dist/task.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
|
|
2
|
+
import { openValues } from './wire-stamps.js';
|
|
3
|
+
export const TaskStatusSchema = openValues(z.enum(['open', 'done', 'failed', 'cancelled']), 'TaskStatus');
|
|
3
4
|
export const TaskResultSchema = z.object({
|
|
4
5
|
text: z.string(),
|
|
5
6
|
// How the result came about: the child called `done`, its first turn ended, or its process left.
|
|
6
|
-
source: z.enum(['done', 'turn', 'exit']),
|
|
7
|
+
source: openValues(z.enum(['done', 'turn', 'exit']), 'TaskResultSource'),
|
|
7
8
|
at: z.number()
|
|
8
9
|
});
|
|
9
10
|
/*
|
|
@@ -26,9 +27,9 @@ export const TaskSchema = z.object({
|
|
|
26
27
|
createdAt: z.number(),
|
|
27
28
|
settledAt: z.number().nullable(),
|
|
28
29
|
// Whether the parent has been woken about this task yet; `none` for a task that never wakes anybody.
|
|
29
|
-
wake: z.enum(['pending', 'sent', 'none']),
|
|
30
|
+
wake: openValues(z.enum(['pending', 'sent', 'none']), 'TaskWake'),
|
|
30
31
|
// Set while the child's last turn stopped on a limit: the task stays open and wakes nobody, `until` the limit lifts when known.
|
|
31
|
-
paused: z.object({ kind: z.enum(['usage', 'overload']), until: z.number().optional() }).optional(),
|
|
32
|
+
paused: z.object({ kind: openValues(z.enum(['usage', 'overload']), 'TaskPauseKind'), until: z.number().optional() }).optional(),
|
|
32
33
|
// The machine the child runs on, when that is not this one: no chat here observes it, so its result arrives through `settleFromElsewhere`.
|
|
33
34
|
machine: z.string().min(1).optional()
|
|
34
35
|
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { AgentStatus } from './agent.ts';
|
|
3
|
+
import type { ChatApprovalItem, ChatBackgroundTask, ChatEvent, ChatGoalStatus, ChatItem, ChatQuestionItem, ChatRequestKind, ChatTurnLimit, ChatUnknownEvent, ChatUnknownItem } from './chat.ts';
|
|
4
|
+
import type { RuntimeMode } from './model.ts';
|
|
5
|
+
import type { Task, TaskResult, TaskStatus } from './task.ts';
|
|
6
|
+
import type { UsageProvider } from './usage.ts';
|
|
7
|
+
import { type WireDegradation } from './wire-stamps.ts';
|
|
8
|
+
export { lossyItems, openUnion, openValues, wireStampOf, wireStampsIn, type WireDegradation, type WireStamp, type WireStampAt } from './wire-stamps.ts';
|
|
9
|
+
declare const unknownWord: unique symbol;
|
|
10
|
+
export type UnknownWord = string & {
|
|
11
|
+
readonly [unknownWord]: true;
|
|
12
|
+
};
|
|
13
|
+
export type OpenUnionTable = Record<string, {
|
|
14
|
+
readonly known: unknown;
|
|
15
|
+
readonly unknown: unknown;
|
|
16
|
+
}>;
|
|
17
|
+
export type OpenWordTable = Record<string, unknown>;
|
|
18
|
+
export type OpenUnions = {
|
|
19
|
+
ChatItem: {
|
|
20
|
+
known: ChatItem;
|
|
21
|
+
unknown: ChatUnknownItem;
|
|
22
|
+
};
|
|
23
|
+
ChatEvent: {
|
|
24
|
+
known: ChatEvent;
|
|
25
|
+
unknown: ChatUnknownEvent;
|
|
26
|
+
};
|
|
27
|
+
ChatPendingRequest: {
|
|
28
|
+
known: ChatApprovalItem | ChatQuestionItem;
|
|
29
|
+
unknown: ChatUnknownItem;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export type OpenWords = {
|
|
33
|
+
AgentStatus: AgentStatus;
|
|
34
|
+
ChatBackgroundTaskKind: ChatBackgroundTask['kind'];
|
|
35
|
+
ChatGoalStatus: ChatGoalStatus;
|
|
36
|
+
ChatRequestKind: ChatRequestKind;
|
|
37
|
+
ChatTurnLimitKind: ChatTurnLimit['kind'];
|
|
38
|
+
RuntimeMode: RuntimeMode;
|
|
39
|
+
TaskPauseKind: NonNullable<Task['paused']>['kind'];
|
|
40
|
+
TaskResultSource: TaskResult['source'];
|
|
41
|
+
TaskStatus: TaskStatus;
|
|
42
|
+
TaskWake: Task['wake'];
|
|
43
|
+
UsageProvider: UsageProvider;
|
|
44
|
+
};
|
|
45
|
+
type Same<A, B> = [A] extends [B] ? ([B] extends [A] ? true : false) : false;
|
|
46
|
+
type UnknownMemberOf<T, Unions extends OpenUnionTable> = {
|
|
47
|
+
[K in keyof Unions]: Same<T, Unions[K]['known']> extends true ? Unions[K]['unknown'] : never;
|
|
48
|
+
}[keyof Unions];
|
|
49
|
+
type IsOpenWord<T, Words extends OpenWordTable> = true extends {
|
|
50
|
+
[K in keyof Words]: Same<T, Words[K]>;
|
|
51
|
+
}[keyof Words] ? true : false;
|
|
52
|
+
type TolerantShape<T, Unions extends OpenUnionTable, Words extends OpenWordTable, Depth extends unknown[]> = T extends object ? {
|
|
53
|
+
[K in keyof T]: TolerantAt<T[K], Unions, Words, [...Depth, unknown]>;
|
|
54
|
+
} : T;
|
|
55
|
+
type MaxDepth = 12;
|
|
56
|
+
type TolerantAt<T, Unions extends OpenUnionTable, Words extends OpenWordTable, Depth extends unknown[]> = Depth['length'] extends MaxDepth ? T : [UnknownMemberOf<NonNullable<T>, Unions>] extends [never] ? IsOpenWord<NonNullable<T>, Words> extends true ? T | UnknownWord : TolerantShape<T, Unions, Words, Depth> : TolerantShape<NonNullable<T>, Unions, Words, Depth> | UnknownMemberOf<NonNullable<T>, Unions> | Extract<T, null | undefined>;
|
|
57
|
+
export type TolerantWith<T, Unions extends OpenUnionTable, Words extends OpenWordTable> = TolerantAt<T, Unions, Words, []>;
|
|
58
|
+
export type Tolerant<T> = TolerantWith<T, OpenUnions, OpenWords>;
|
|
59
|
+
export type ToleratedRead<T> = {
|
|
60
|
+
readonly success: true;
|
|
61
|
+
readonly data: T;
|
|
62
|
+
readonly degraded: readonly WireDegradation[];
|
|
63
|
+
} | {
|
|
64
|
+
readonly success: false;
|
|
65
|
+
readonly error: z.ZodError;
|
|
66
|
+
};
|
|
67
|
+
export declare function readTolerant<S extends z.core.$ZodType, Unions extends OpenUnionTable = OpenUnions, Words extends OpenWordTable = OpenWords>(schema: S, input: unknown): ToleratedRead<TolerantWith<z.output<S>, Unions, Words>>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { readStamped } from './wire-stamps.js';
|
|
2
|
+
export { lossyItems, openUnion, openValues, wireStampOf, wireStampsIn } from './wire-stamps.js';
|
|
3
|
+
/*
|
|
4
|
+
* Reads what a host sent the way a client of an older version should: the strict parse when it holds, otherwise
|
|
5
|
+
* every open union, lossy list and open vocabulary stamped below `schema` degrades in place, and `degraded` says
|
|
6
|
+
* where. A host reading what a client sent keeps parsing strictly. An app that stamps schemas of its own passes its
|
|
7
|
+
* tables joined with these (`OpenUnions & AppUnions`) to type what it reads.
|
|
8
|
+
*/
|
|
9
|
+
export function readTolerant(schema, input) {
|
|
10
|
+
return readStamped(schema, input);
|
|
11
|
+
}
|
package/dist/usage.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { ProviderAccountIdSchema } from './provider-accounts.js';
|
|
3
|
+
import { openValues } from './wire-stamps.js';
|
|
3
4
|
/* The providers whose usage the daemon reads: the CLIs' own records, and the log a host keeps of what it calls itself. A subset of `AgentKindSchema`: it grows with the readers. */
|
|
4
|
-
export const UsageProviderSchema = z.enum(['claude', 'codex', 'nanogpt', 'grok', 'copilot', 'anthropic-claude-api'])
|
|
5
|
+
export const UsageProviderSchema = openValues(z.enum(['claude', 'codex', 'nanogpt', 'grok', 'copilot', 'anthropic-claude-api']), 'UsageProvider', {
|
|
6
|
+
words: 'strings'
|
|
7
|
+
});
|
|
5
8
|
export const USAGE_PROVIDERS = UsageProviderSchema.options;
|
|
6
9
|
export const UsageResolutionSchema = z.enum(['hour', 'day']);
|
|
7
10
|
/* Token kinds are disjoint, so a total is their sum. Reasoning is a part of output and never counted twice. */
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export type WireStamp = {
|
|
3
|
+
readonly open: 'union';
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly tag: string;
|
|
6
|
+
readonly base: readonly string[];
|
|
7
|
+
} | {
|
|
8
|
+
readonly open: 'items';
|
|
9
|
+
} | {
|
|
10
|
+
readonly open: 'values';
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly words: 'cases' | 'strings';
|
|
13
|
+
readonly known: readonly string[];
|
|
14
|
+
};
|
|
15
|
+
export interface WireStampAt {
|
|
16
|
+
readonly path: readonly (string | number)[];
|
|
17
|
+
readonly stamp: WireStamp;
|
|
18
|
+
}
|
|
19
|
+
export type WireDegradation = {
|
|
20
|
+
readonly kind: 'unknown-member';
|
|
21
|
+
readonly path: readonly (string | number)[];
|
|
22
|
+
readonly name: string;
|
|
23
|
+
readonly tag: string;
|
|
24
|
+
} | {
|
|
25
|
+
readonly kind: 'dropped-element';
|
|
26
|
+
readonly path: readonly (string | number)[];
|
|
27
|
+
} | {
|
|
28
|
+
readonly kind: 'unknown-word';
|
|
29
|
+
readonly path: readonly (string | number)[];
|
|
30
|
+
readonly name: string;
|
|
31
|
+
readonly word: string;
|
|
32
|
+
};
|
|
33
|
+
export declare function openUnion<S extends z.core.$ZodType>(schema: S, name: string, options: {
|
|
34
|
+
readonly tag: string;
|
|
35
|
+
readonly base: readonly string[];
|
|
36
|
+
}): S;
|
|
37
|
+
export declare function lossyItems<S extends z.core.$ZodType>(schema: S): S;
|
|
38
|
+
export declare function openValues<S extends z.core.$ZodType>(schema: S, name: string, options?: {
|
|
39
|
+
readonly words?: 'cases' | 'strings';
|
|
40
|
+
readonly known?: readonly string[];
|
|
41
|
+
}): S;
|
|
42
|
+
export declare function wireStampOf(schema: object): WireStamp | undefined;
|
|
43
|
+
export declare function wireStampsIn(schema: z.core.$ZodType): WireStampAt[];
|
|
44
|
+
export type StampedRead = {
|
|
45
|
+
readonly success: true;
|
|
46
|
+
readonly data: unknown;
|
|
47
|
+
readonly degraded: readonly WireDegradation[];
|
|
48
|
+
} | {
|
|
49
|
+
readonly success: false;
|
|
50
|
+
readonly error: z.ZodError;
|
|
51
|
+
};
|
|
52
|
+
export declare function readStamped(schema: z.core.$ZodType, input: unknown): StampedRead;
|