@adecore/agent-contracts 0.0.1 → 0.17.0-beta.2

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.
@@ -0,0 +1,64 @@
1
+ import { z } from 'zod';
2
+ import { ChatAddBookmarkPayloadSchema, ChatAnswerPayloadSchema, ChatApprovePayloadSchema, ChatAttachPayloadSchema, ChatAttachResultSchema, ChatBookmarksEventSchema, ChatBookmarksResultSchema, ChatCancelPayloadSchema, ChatClearPayloadSchema, ChatConfigurePayloadSchema, ChatContinueOnPayloadSchema, ChatContinueOnResultSchema, ChatCreatePayloadSchema, ChatDismissPayloadSchema, ChatEventEnvelopeSchema, ChatForkInfoPayloadSchema, ChatForkInfoResultSchema, ChatForkPayloadSchema, ChatForkResultSchema, ChatHistoryPayloadSchema, ChatHistoryResultSchema, ChatInfoSchema, ChatListResultSchema, ChatPreferencesPayloadSchema, ChatQueuePayloadSchema, ChatRemoveBookmarkPayloadSchema, ChatRenameBookmarkPayloadSchema, ChatSendPayloadSchema, ChatSendResultSchema, ChatStatusEventSchema, ChatStopSubagentPayloadSchema, ChatStopTaskPayloadSchema, ChatSubagentChangedEventSchema, ChatSubagentPayloadSchema, ChatSubagentResultSchema, ChatSummarizePayloadSchema, ChatSummarizeResultSchema, ChatTargetPayloadSchema, ChatTurnDiffPayloadSchema, ChatTurnDiffResultSchema, ChatUnqueueResultSchema, SkillsListPayloadSchema, SkillsListResultSchema } from './chat.js';
3
+ import { ProviderListResultSchema } from './model.js';
4
+ import { ProviderAccountCreatePayloadSchema, ProviderAccountCreateResultSchema, ProviderAccountWatchLoginPayloadSchema, ProviderAccountsSavePayloadSchema, ProviderAccountsSchema } from './provider-accounts.js';
5
+ import { UsageChangedEventSchema, UsageLimitsSnapshotSchema, UsageSummaryPayloadSchema, UsageSummaryResultSchema } from './usage.js';
6
+ export const EmptySchema = z.object({});
7
+ /*
8
+ * The requests a chat, its providers and their usage answer, with what goes in and what comes back.
9
+ * An application places each one in its own wire table, so a host that only runs chats serves
10
+ * exactly these and a client reads the same shapes either way.
11
+ */
12
+ export const AGENT_REQUEST_SCHEMAS = {
13
+ 'chat.create': { payload: ChatCreatePayloadSchema, result: ChatInfoSchema },
14
+ 'chat.history': { payload: ChatHistoryPayloadSchema, result: ChatHistoryResultSchema },
15
+ 'chat.attach': { payload: ChatAttachPayloadSchema, result: ChatAttachResultSchema },
16
+ 'chat.detach': { payload: ChatTargetPayloadSchema, result: EmptySchema },
17
+ 'chat.send': { payload: ChatSendPayloadSchema, result: ChatSendResultSchema },
18
+ 'chat.unqueue': { payload: ChatQueuePayloadSchema, result: ChatUnqueueResultSchema },
19
+ 'chat.sendNow': { payload: ChatQueuePayloadSchema, result: EmptySchema },
20
+ 'chat.cancel': { payload: ChatCancelPayloadSchema, result: EmptySchema },
21
+ 'chat.approve': { payload: ChatApprovePayloadSchema, result: EmptySchema },
22
+ 'chat.answer': { payload: ChatAnswerPayloadSchema, result: EmptySchema },
23
+ 'chat.dismiss': { payload: ChatDismissPayloadSchema, result: EmptySchema },
24
+ 'chat.configure': { payload: ChatConfigurePayloadSchema, result: ChatInfoSchema },
25
+ 'chat.setPreferences': { payload: ChatPreferencesPayloadSchema, result: EmptySchema },
26
+ 'chat.compact': { payload: ChatTargetPayloadSchema, result: EmptySchema },
27
+ 'chat.clear': { payload: ChatClearPayloadSchema, result: EmptySchema },
28
+ 'chat.turnDiff': { payload: ChatTurnDiffPayloadSchema, result: ChatTurnDiffResultSchema },
29
+ 'chat.fork': { payload: ChatForkPayloadSchema, result: ChatForkResultSchema },
30
+ 'chat.continueOn': { payload: ChatContinueOnPayloadSchema, result: ChatContinueOnResultSchema },
31
+ 'chat.forkInfo': { payload: ChatForkInfoPayloadSchema, result: ChatForkInfoResultSchema },
32
+ 'chat.summarize': { payload: ChatSummarizePayloadSchema, result: ChatSummarizeResultSchema },
33
+ 'chat.subagent': { payload: ChatSubagentPayloadSchema, result: ChatSubagentResultSchema },
34
+ 'chat.stopSubagent': { payload: ChatStopSubagentPayloadSchema, result: EmptySchema },
35
+ 'chat.stopTask': { payload: ChatStopTaskPayloadSchema, result: EmptySchema },
36
+ 'chat.addBookmark': { payload: ChatAddBookmarkPayloadSchema, result: ChatBookmarksResultSchema },
37
+ 'chat.renameBookmark': { payload: ChatRenameBookmarkPayloadSchema, result: ChatBookmarksResultSchema },
38
+ 'chat.removeBookmark': { payload: ChatRemoveBookmarkPayloadSchema, result: ChatBookmarksResultSchema },
39
+ 'skills.list': { payload: SkillsListPayloadSchema, result: SkillsListResultSchema },
40
+ 'provider.list': { payload: EmptySchema, result: ProviderListResultSchema },
41
+ 'accounts.list': { payload: EmptySchema, result: ProviderAccountsSchema },
42
+ 'accounts.save': { payload: ProviderAccountsSavePayloadSchema, result: ProviderAccountsSchema },
43
+ // Asks every CLI again and answers once they all did.
44
+ 'accounts.refresh': { payload: EmptySchema, result: ProviderAccountsSchema },
45
+ 'accounts.create': { payload: ProviderAccountCreatePayloadSchema, result: ProviderAccountCreateResultSchema },
46
+ // Answers at once; what the CLI says arrives as `accounts.changed`.
47
+ 'accounts.watchLogin': { payload: ProviderAccountWatchLoginPayloadSchema, result: EmptySchema },
48
+ 'usage.summary': { payload: UsageSummaryPayloadSchema, result: UsageSummaryResultSchema },
49
+ 'usage.subscribe': { payload: EmptySchema, result: EmptySchema },
50
+ 'usage.unsubscribe': { payload: EmptySchema, result: EmptySchema },
51
+ 'usage.limits': { payload: EmptySchema, result: UsageLimitsSnapshotSchema },
52
+ 'usage.refreshLimits': { payload: EmptySchema, result: UsageLimitsSnapshotSchema },
53
+ 'chat.kill': { payload: ChatTargetPayloadSchema, result: EmptySchema },
54
+ 'chat.list': { payload: EmptySchema, result: ChatListResultSchema }
55
+ };
56
+ export const AGENT_EVENT_SCHEMAS = {
57
+ 'chat.event': ChatEventEnvelopeSchema,
58
+ 'chat.status': ChatStatusEventSchema,
59
+ 'chat.subagentChanged': ChatSubagentChangedEventSchema,
60
+ 'chat.bookmarks': ChatBookmarksEventSchema,
61
+ 'usage.changed': UsageChangedEventSchema,
62
+ 'usage.limitsChanged': UsageLimitsSnapshotSchema,
63
+ 'accounts.changed': ProviderAccountsSchema
64
+ };
@@ -0,0 +1,199 @@
1
+ import { z } from 'zod';
2
+ export declare const ProviderAccountIdSchema: z.ZodString;
3
+ export type ProviderAccountId = z.infer<typeof ProviderAccountIdSchema>;
4
+ export declare const ProviderAccountVariableSchema: z.ZodObject<{
5
+ name: z.ZodString;
6
+ value: z.ZodString;
7
+ sensitive: z.ZodBoolean;
8
+ valueRedacted: z.ZodOptional<z.ZodBoolean>;
9
+ }, z.core.$strip>;
10
+ export type ProviderAccountVariable = z.infer<typeof ProviderAccountVariableSchema>;
11
+ export declare const ProviderAccountSchema: z.ZodObject<{
12
+ kind: z.ZodString;
13
+ label: z.ZodOptional<z.ZodString>;
14
+ color: z.ZodOptional<z.ZodString>;
15
+ enabled: z.ZodOptional<z.ZodBoolean>;
16
+ home: z.ZodOptional<z.ZodString>;
17
+ shadowHome: z.ZodOptional<z.ZodString>;
18
+ env: z.ZodOptional<z.ZodArray<z.ZodObject<{
19
+ name: z.ZodString;
20
+ value: z.ZodString;
21
+ sensitive: z.ZodBoolean;
22
+ valueRedacted: z.ZodOptional<z.ZodBoolean>;
23
+ }, z.core.$strip>>>;
24
+ }, z.core.$strip>;
25
+ export type ProviderAccount = z.infer<typeof ProviderAccountSchema>;
26
+ export declare const ProviderAccountStateSchema: z.ZodEnum<{
27
+ checking: "checking";
28
+ disabled: "disabled";
29
+ failed: "failed";
30
+ "folder-missing": "folder-missing";
31
+ "not-found": "not-found";
32
+ ready: "ready";
33
+ "signed-out": "signed-out";
34
+ unavailable: "unavailable";
35
+ }>;
36
+ export type ProviderAccountState = z.infer<typeof ProviderAccountStateSchema>;
37
+ export declare const ProviderAccountStatusSchema: z.ZodObject<{
38
+ id: z.ZodString;
39
+ kind: z.ZodString;
40
+ state: z.ZodEnum<{
41
+ checking: "checking";
42
+ disabled: "disabled";
43
+ failed: "failed";
44
+ "folder-missing": "folder-missing";
45
+ "not-found": "not-found";
46
+ ready: "ready";
47
+ "signed-out": "signed-out";
48
+ unavailable: "unavailable";
49
+ }>;
50
+ email: z.ZodNullable<z.ZodString>;
51
+ plan: z.ZodNullable<z.ZodString>;
52
+ organization: z.ZodNullable<z.ZodString>;
53
+ home: z.ZodString;
54
+ transcripts: z.ZodOptional<z.ZodString>;
55
+ message: z.ZodNullable<z.ZodString>;
56
+ checkedAt: z.ZodNumber;
57
+ }, z.core.$strip>;
58
+ export type ProviderAccountStatus = z.infer<typeof ProviderAccountStatusSchema>;
59
+ export declare const ProviderAccountMapSchema: z.ZodRecord<z.ZodString, z.ZodObject<{
60
+ kind: z.ZodString;
61
+ label: z.ZodOptional<z.ZodString>;
62
+ color: z.ZodOptional<z.ZodString>;
63
+ enabled: z.ZodOptional<z.ZodBoolean>;
64
+ home: z.ZodOptional<z.ZodString>;
65
+ shadowHome: z.ZodOptional<z.ZodString>;
66
+ env: z.ZodOptional<z.ZodArray<z.ZodObject<{
67
+ name: z.ZodString;
68
+ value: z.ZodString;
69
+ sensitive: z.ZodBoolean;
70
+ valueRedacted: z.ZodOptional<z.ZodBoolean>;
71
+ }, z.core.$strip>>>;
72
+ }, z.core.$strip>>;
73
+ export type ProviderAccountMap = z.infer<typeof ProviderAccountMapSchema>;
74
+ export declare const ProviderAccountsSchema: z.ZodObject<{
75
+ accounts: z.ZodRecord<z.ZodString, z.ZodObject<{
76
+ kind: z.ZodString;
77
+ label: z.ZodOptional<z.ZodString>;
78
+ color: z.ZodOptional<z.ZodString>;
79
+ enabled: z.ZodOptional<z.ZodBoolean>;
80
+ home: z.ZodOptional<z.ZodString>;
81
+ shadowHome: z.ZodOptional<z.ZodString>;
82
+ env: z.ZodOptional<z.ZodArray<z.ZodObject<{
83
+ name: z.ZodString;
84
+ value: z.ZodString;
85
+ sensitive: z.ZodBoolean;
86
+ valueRedacted: z.ZodOptional<z.ZodBoolean>;
87
+ }, z.core.$strip>>>;
88
+ }, z.core.$strip>>;
89
+ statuses: z.ZodArray<z.ZodObject<{
90
+ id: z.ZodString;
91
+ kind: z.ZodString;
92
+ state: z.ZodEnum<{
93
+ checking: "checking";
94
+ disabled: "disabled";
95
+ failed: "failed";
96
+ "folder-missing": "folder-missing";
97
+ "not-found": "not-found";
98
+ ready: "ready";
99
+ "signed-out": "signed-out";
100
+ unavailable: "unavailable";
101
+ }>;
102
+ email: z.ZodNullable<z.ZodString>;
103
+ plan: z.ZodNullable<z.ZodString>;
104
+ organization: z.ZodNullable<z.ZodString>;
105
+ home: z.ZodString;
106
+ transcripts: z.ZodOptional<z.ZodString>;
107
+ message: z.ZodNullable<z.ZodString>;
108
+ checkedAt: z.ZodNumber;
109
+ }, z.core.$strip>>;
110
+ secretsAvailable: z.ZodOptional<z.ZodBoolean>;
111
+ loginCommands: z.ZodOptional<z.ZodRecord<z.ZodEnum<{
112
+ apple: "apple";
113
+ claude: "claude";
114
+ codex: "codex";
115
+ copilot: "copilot";
116
+ gemini: "gemini";
117
+ }> & z.core.$partial, z.ZodString>>;
118
+ }, z.core.$strip>;
119
+ export type ProviderAccounts = z.infer<typeof ProviderAccountsSchema>;
120
+ export declare const ProviderAccountsSavePayloadSchema: z.ZodObject<{
121
+ accounts: z.ZodRecord<z.ZodString, z.ZodObject<{
122
+ kind: z.ZodString;
123
+ label: z.ZodOptional<z.ZodString>;
124
+ color: z.ZodOptional<z.ZodString>;
125
+ enabled: z.ZodOptional<z.ZodBoolean>;
126
+ home: z.ZodOptional<z.ZodString>;
127
+ shadowHome: z.ZodOptional<z.ZodString>;
128
+ env: z.ZodOptional<z.ZodArray<z.ZodObject<{
129
+ name: z.ZodString;
130
+ value: z.ZodString;
131
+ sensitive: z.ZodBoolean;
132
+ valueRedacted: z.ZodOptional<z.ZodBoolean>;
133
+ }, z.core.$strip>>>;
134
+ }, z.core.$strip>>;
135
+ }, z.core.$strip>;
136
+ export type ProviderAccountsSavePayload = z.infer<typeof ProviderAccountsSavePayloadSchema>;
137
+ export declare const ProviderAccountCreatePayloadSchema: z.ZodObject<{
138
+ kind: z.ZodEnum<{
139
+ apple: "apple";
140
+ claude: "claude";
141
+ codex: "codex";
142
+ copilot: "copilot";
143
+ gemini: "gemini";
144
+ }>;
145
+ label: z.ZodString;
146
+ color: z.ZodOptional<z.ZodString>;
147
+ }, z.core.$strip>;
148
+ export type ProviderAccountCreatePayload = z.infer<typeof ProviderAccountCreatePayloadSchema>;
149
+ export declare const ProviderAccountCreateResultSchema: z.ZodObject<{
150
+ accounts: z.ZodRecord<z.ZodString, z.ZodObject<{
151
+ kind: z.ZodString;
152
+ label: z.ZodOptional<z.ZodString>;
153
+ color: z.ZodOptional<z.ZodString>;
154
+ enabled: z.ZodOptional<z.ZodBoolean>;
155
+ home: z.ZodOptional<z.ZodString>;
156
+ shadowHome: z.ZodOptional<z.ZodString>;
157
+ env: z.ZodOptional<z.ZodArray<z.ZodObject<{
158
+ name: z.ZodString;
159
+ value: z.ZodString;
160
+ sensitive: z.ZodBoolean;
161
+ valueRedacted: z.ZodOptional<z.ZodBoolean>;
162
+ }, z.core.$strip>>>;
163
+ }, z.core.$strip>>;
164
+ statuses: z.ZodArray<z.ZodObject<{
165
+ id: z.ZodString;
166
+ kind: z.ZodString;
167
+ state: z.ZodEnum<{
168
+ checking: "checking";
169
+ disabled: "disabled";
170
+ failed: "failed";
171
+ "folder-missing": "folder-missing";
172
+ "not-found": "not-found";
173
+ ready: "ready";
174
+ "signed-out": "signed-out";
175
+ unavailable: "unavailable";
176
+ }>;
177
+ email: z.ZodNullable<z.ZodString>;
178
+ plan: z.ZodNullable<z.ZodString>;
179
+ organization: z.ZodNullable<z.ZodString>;
180
+ home: z.ZodString;
181
+ transcripts: z.ZodOptional<z.ZodString>;
182
+ message: z.ZodNullable<z.ZodString>;
183
+ checkedAt: z.ZodNumber;
184
+ }, z.core.$strip>>;
185
+ secretsAvailable: z.ZodOptional<z.ZodBoolean>;
186
+ loginCommands: z.ZodOptional<z.ZodRecord<z.ZodEnum<{
187
+ apple: "apple";
188
+ claude: "claude";
189
+ codex: "codex";
190
+ copilot: "copilot";
191
+ gemini: "gemini";
192
+ }> & z.core.$partial, z.ZodString>>;
193
+ id: z.ZodString;
194
+ }, z.core.$strip>;
195
+ export type ProviderAccountCreateResult = z.infer<typeof ProviderAccountCreateResultSchema>;
196
+ export declare const ProviderAccountWatchLoginPayloadSchema: z.ZodObject<{
197
+ id: z.ZodString;
198
+ }, z.core.$strip>;
199
+ export type ProviderAccountWatchLoginPayload = z.infer<typeof ProviderAccountWatchLoginPayloadSchema>;
@@ -0,0 +1,91 @@
1
+ import { z } from 'zod';
2
+ import { AgentKindSchema } from './agent.js';
3
+ /*
4
+ * An account of an agent CLI is one config folder of that CLI, handed to it through the variable it
5
+ * reads its folder from. The person signs in with the CLI itself; the daemon only asks the CLI who
6
+ * that is. Accounts belong to one host and live in its provider account store.
7
+ */
8
+ /* A slug, never a path. The default account of a CLI has the CLI's kind as its id. */
9
+ export const ProviderAccountIdSchema = z.string().regex(/^[a-z][a-z0-9_-]{0,63}$/);
10
+ /*
11
+ * A variable the CLI of an account is started with. A sensitive value lives in the keychain of the
12
+ * machine and never on the wire: the daemon sends it as an empty `value` with `valueRedacted`, and a
13
+ * save that sends that back keeps what the keychain holds.
14
+ */
15
+ export const ProviderAccountVariableSchema = z.object({
16
+ name: z.string().regex(/^[A-Za-z_][A-Za-z0-9_]{0,127}$/),
17
+ value: z.string(),
18
+ sensitive: z.boolean(),
19
+ valueRedacted: z.boolean().optional()
20
+ });
21
+ export const ProviderAccountSchema = z.object({
22
+ // An agent kind. A kind this version does not know still parses, so the entry is written back unchanged.
23
+ kind: z.string().min(1),
24
+ label: z.string().optional(),
25
+ // A node accent name (`NODE_ACCENT_NAMES`), kept a plain string so an older name is written back; the client paints any other with its accent.
26
+ color: z.string().optional(),
27
+ // Absent is on. An account that is off is left out of every picker.
28
+ enabled: z.boolean().optional(),
29
+ // The CLI's config folder, `~` allowed. Absent on the default account, which uses the CLI's own folder.
30
+ home: z.string().min(1).optional(),
31
+ // Codex only: a folder of its own for the login, sharing everything else with `home`.
32
+ shadowHome: z.string().min(1).optional(),
33
+ // Set on the CLI's environment after the login variables are taken off, so a key here is one a person chose.
34
+ env: z.array(ProviderAccountVariableSchema).optional()
35
+ });
36
+ export const ProviderAccountStateSchema = z.enum([
37
+ 'checking',
38
+ 'disabled',
39
+ // The CLI is not installed on this machine.
40
+ 'not-found',
41
+ 'signed-out',
42
+ 'ready',
43
+ 'folder-missing',
44
+ // A kind this version does not know, or a CLI with no variable for its config folder.
45
+ 'unavailable',
46
+ 'failed'
47
+ ]);
48
+ /* What the CLI said about an account the last time it was asked. Never stored: the CLI is the truth. */
49
+ export const ProviderAccountStatusSchema = z.object({
50
+ id: ProviderAccountIdSchema,
51
+ kind: z.string(),
52
+ state: ProviderAccountStateSchema,
53
+ email: z.string().nullable(),
54
+ plan: z.string().nullable(),
55
+ organization: z.string().nullable(),
56
+ // The folder the CLI is started with, resolved; empty for a CLI without a config folder variable.
57
+ home: z.string(),
58
+ // Where the account's conversations are written, resolved: a chat goes on under another account only when both write here.
59
+ transcripts: z.string().optional(),
60
+ // Why the state is what it is, in a sentence, when the CLI or the daemon said.
61
+ message: z.string().nullable(),
62
+ // Milliseconds since the epoch; 0 while the account was never checked.
63
+ checkedAt: z.number()
64
+ });
65
+ export const ProviderAccountMapSchema = z.record(ProviderAccountIdSchema, ProviderAccountSchema);
66
+ export const ProviderAccountsSchema = z.object({
67
+ accounts: ProviderAccountMapSchema,
68
+ statuses: z.array(ProviderAccountStatusSchema),
69
+ // Whether this machine can keep a sensitive variable; false off macOS, where no keychain is used.
70
+ secretsAvailable: z.boolean().optional(),
71
+ // Per agent kind, what a terminal types to sign that CLI in under an account, which the account's environment points at.
72
+ loginCommands: z.partialRecord(AgentKindSchema, z.string()).optional()
73
+ });
74
+ /* The whole map: an id left out is removed, and its folder stays where it is. */
75
+ export const ProviderAccountsSavePayloadSchema = z.object({
76
+ accounts: ProviderAccountMapSchema
77
+ });
78
+ /* An account in a folder the daemon makes for it under its account data directory; a Codex one is a shadow home over the CLI's own folder. */
79
+ export const ProviderAccountCreatePayloadSchema = z.object({
80
+ kind: AgentKindSchema,
81
+ label: z.string().trim().min(1).max(80),
82
+ color: z.string().optional()
83
+ });
84
+ export const ProviderAccountCreateResultSchema = ProviderAccountsSchema.extend({
85
+ // The id the daemon minted from the label.
86
+ id: ProviderAccountIdSchema
87
+ });
88
+ /* Asks the CLI of one account again every few seconds until it is signed in, for a login running in a terminal. */
89
+ export const ProviderAccountWatchLoginPayloadSchema = z.object({
90
+ id: ProviderAccountIdSchema
91
+ });
package/dist/task.d.ts ADDED
@@ -0,0 +1,110 @@
1
+ import { z } from 'zod';
2
+ export declare const TaskStatusSchema: z.ZodEnum<{
3
+ cancelled: "cancelled";
4
+ done: "done";
5
+ failed: "failed";
6
+ open: "open";
7
+ }>;
8
+ export type TaskStatus = z.infer<typeof TaskStatusSchema>;
9
+ export declare const TaskResultSchema: z.ZodObject<{
10
+ text: z.ZodString;
11
+ source: z.ZodEnum<{
12
+ done: "done";
13
+ exit: "exit";
14
+ turn: "turn";
15
+ }>;
16
+ at: z.ZodNumber;
17
+ }, z.core.$strip>;
18
+ export type TaskResult = z.infer<typeof TaskResultSchema>;
19
+ export declare const TaskSchema: z.ZodObject<{
20
+ id: z.ZodString;
21
+ projectId: z.ZodString;
22
+ parentId: z.ZodString;
23
+ childId: z.ZodString;
24
+ title: z.ZodString;
25
+ prompt: z.ZodString;
26
+ batchId: z.ZodOptional<z.ZodString>;
27
+ requiresTaskTurn: z.ZodOptional<z.ZodBoolean>;
28
+ background: z.ZodOptional<z.ZodObject<{
29
+ turnId: z.ZodString;
30
+ itemIds: z.ZodArray<z.ZodString>;
31
+ commands: z.ZodArray<z.ZodString>;
32
+ }, z.core.$strip>>;
33
+ status: z.ZodEnum<{
34
+ cancelled: "cancelled";
35
+ done: "done";
36
+ failed: "failed";
37
+ open: "open";
38
+ }>;
39
+ result: z.ZodNullable<z.ZodObject<{
40
+ text: z.ZodString;
41
+ source: z.ZodEnum<{
42
+ done: "done";
43
+ exit: "exit";
44
+ turn: "turn";
45
+ }>;
46
+ at: z.ZodNumber;
47
+ }, z.core.$strip>>;
48
+ createdAt: z.ZodNumber;
49
+ settledAt: z.ZodNullable<z.ZodNumber>;
50
+ wake: z.ZodEnum<{
51
+ none: "none";
52
+ pending: "pending";
53
+ sent: "sent";
54
+ }>;
55
+ paused: z.ZodOptional<z.ZodObject<{
56
+ kind: z.ZodEnum<{
57
+ overload: "overload";
58
+ usage: "usage";
59
+ }>;
60
+ until: z.ZodOptional<z.ZodNumber>;
61
+ }, z.core.$strip>>;
62
+ }, z.core.$strip>;
63
+ export type Task = z.infer<typeof TaskSchema>;
64
+ export declare const TaskChangedEventSchema: z.ZodObject<{
65
+ task: z.ZodObject<{
66
+ id: z.ZodString;
67
+ projectId: z.ZodString;
68
+ parentId: z.ZodString;
69
+ childId: z.ZodString;
70
+ title: z.ZodString;
71
+ prompt: z.ZodString;
72
+ batchId: z.ZodOptional<z.ZodString>;
73
+ requiresTaskTurn: z.ZodOptional<z.ZodBoolean>;
74
+ background: z.ZodOptional<z.ZodObject<{
75
+ turnId: z.ZodString;
76
+ itemIds: z.ZodArray<z.ZodString>;
77
+ commands: z.ZodArray<z.ZodString>;
78
+ }, z.core.$strip>>;
79
+ status: z.ZodEnum<{
80
+ cancelled: "cancelled";
81
+ done: "done";
82
+ failed: "failed";
83
+ open: "open";
84
+ }>;
85
+ result: z.ZodNullable<z.ZodObject<{
86
+ text: z.ZodString;
87
+ source: z.ZodEnum<{
88
+ done: "done";
89
+ exit: "exit";
90
+ turn: "turn";
91
+ }>;
92
+ at: z.ZodNumber;
93
+ }, z.core.$strip>>;
94
+ createdAt: z.ZodNumber;
95
+ settledAt: z.ZodNullable<z.ZodNumber>;
96
+ wake: z.ZodEnum<{
97
+ none: "none";
98
+ pending: "pending";
99
+ sent: "sent";
100
+ }>;
101
+ paused: z.ZodOptional<z.ZodObject<{
102
+ kind: z.ZodEnum<{
103
+ overload: "overload";
104
+ usage: "usage";
105
+ }>;
106
+ until: z.ZodOptional<z.ZodNumber>;
107
+ }, z.core.$strip>>;
108
+ }, z.core.$strip>;
109
+ }, z.core.$strip>;
110
+ export type TaskChangedEvent = z.infer<typeof TaskChangedEventSchema>;
package/dist/task.js ADDED
@@ -0,0 +1,33 @@
1
+ import { z } from 'zod';
2
+ export const TaskStatusSchema = z.enum(['open', 'done', 'failed', 'cancelled']);
3
+ export const TaskResultSchema = z.object({
4
+ text: z.string(),
5
+ // 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
+ at: z.number()
8
+ });
9
+ /*
10
+ * What a chat asked of a node it opened with `--task`, kept by the host under its data folder rather
11
+ * than anywhere an agent can write: waking the parent is a promise the host keeps.
12
+ */
13
+ export const TaskSchema = z.object({
14
+ id: z.string().min(1),
15
+ projectId: z.string().min(1),
16
+ parentId: z.string().min(1),
17
+ childId: z.string().min(1),
18
+ title: z.string(),
19
+ prompt: z.string(),
20
+ // The one `team --task` call it came from: the parent is woken about that call once every task of it settled.
21
+ batchId: z.string().min(1).optional(),
22
+ requiresTaskTurn: z.boolean().optional(),
23
+ background: z.object({ turnId: z.string(), itemIds: z.array(z.string()), commands: z.array(z.string()) }).optional(),
24
+ status: TaskStatusSchema,
25
+ result: TaskResultSchema.nullable(),
26
+ createdAt: z.number(),
27
+ settledAt: z.number().nullable(),
28
+ // 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
+ // 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
+ });
33
+ export const TaskChangedEventSchema = z.object({ task: TaskSchema });
package/dist/text.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function clipText(text: string, max: number): string;
package/dist/text.js ADDED
@@ -0,0 +1,19 @@
1
+ const graphemes = new Intl.Segmenter(undefined, { granularity: 'grapheme' });
2
+ /*
3
+ * The longest start of `text` that fits in `max` UTF-16 units, the measure a schema's `max` counts in,
4
+ * cut only between characters as a person sees them. A cut between the halves of a surrogate pair
5
+ * leaves a lone half, which JSON writes as an escape the iPhone app refuses along with its whole frame.
6
+ */
7
+ export function clipText(text, max) {
8
+ if (text.length <= max) {
9
+ return text;
10
+ }
11
+ let end = 0;
12
+ for (const { segment } of graphemes.segment(text)) {
13
+ if (end + segment.length > max) {
14
+ break;
15
+ }
16
+ end += segment.length;
17
+ }
18
+ return text.slice(0, end);
19
+ }