@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.
package/LICENSE ADDED
@@ -0,0 +1,110 @@
1
+ # Functional Source License, Version 1.1, MIT Future License
2
+
3
+ ## Abbreviation
4
+
5
+ FSL-1.1-MIT
6
+
7
+ ## Notice
8
+
9
+ Copyright 2026 - present Bas Milius
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the MIT license that is effective on the second anniversary of the date we make
91
+ the Software available. On or after that date, you may use the Software under
92
+ the MIT license, in which case the following will apply:
93
+
94
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
95
+ this software and associated documentation files (the "Software"), to deal in
96
+ the Software without restriction, including without limitation the rights to
97
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
98
+ of the Software, and to permit persons to whom the Software is furnished to do
99
+ so, subject to the following conditions:
100
+
101
+ The above copyright notice and this permission notice shall be included in all
102
+ copies or substantial portions of the Software.
103
+
104
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
105
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
106
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
107
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
108
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
109
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
110
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # @adecore/agent-contracts
2
+
3
+ [![npm](https://img.shields.io/npm/v/@adecore/agent-contracts)](https://www.npmjs.com/package/@adecore/agent-contracts)
4
+ [![Docs](https://img.shields.io/badge/docs-adecore.dev-blue)](https://adecore.dev/agent-contracts/)
5
+
6
+ The Zod schemas and TypeScript types an agent chat host and its clients share: the frames on the wire, the requests and events, a chat and its items, providers, models, accounts, tasks, worktrees and usage. It opens no connection and starts no process, so a browser, a preload and a backend can all import it.
7
+
8
+ ## Install
9
+
10
+ ```sh
11
+ bun add @adecore/agent-contracts
12
+ ```
13
+
14
+ ## Use
15
+
16
+ ```ts
17
+ import { AGENT_REQUEST_SCHEMAS, parseRequest } from '@adecore/agent-contracts';
18
+
19
+ const frame = parseRequest(incoming);
20
+ if (frame.ok && frame.value.type === 'chat.send') {
21
+ const payload = AGENT_REQUEST_SCHEMAS['chat.send'].payload.parse(frame.value.payload);
22
+ }
23
+ ```
24
+
25
+ The root exports everything. Each group also has a subpath of its own: `agent`, `chat`, `envelope`, `ids`, `model`, `port`, `protocol`, `provider-accounts`, `task`, `text`, `usage` and `worktree`.
26
+
27
+ ## Documentation
28
+
29
+ | Page | What it covers |
30
+ |---|---|
31
+ | [Overview](https://adecore.dev/agent-contracts/) | Install, a first check and the entry points |
32
+ | [Protocol](https://adecore.dev/agent-contracts/protocol) | Frames, the request and event tables, replay and adding requests |
33
+ | [Conversation](https://adecore.dev/agent-contracts/conversation) | A chat's info and items, attachments, approvals, bookmarks and forks |
34
+ | [Providers and accounts](https://adecore.dev/agent-contracts/providers-and-accounts) | Agent kinds, model catalogs, capabilities, runtime modes and accounts |
35
+ | [Tasks and usage](https://adecore.dev/agent-contracts/tasks-and-usage) | Tasks, worktrees, token totals, summaries and plan limits |
36
+
37
+ ## License
38
+
39
+ FSL-1.1-MIT. See [LICENSE](./LICENSE).
@@ -0,0 +1,133 @@
1
+ import { z } from 'zod';
2
+ export declare const AgentKindSchema: z.ZodEnum<{
3
+ apple: "apple";
4
+ claude: "claude";
5
+ codex: "codex";
6
+ copilot: "copilot";
7
+ gemini: "gemini";
8
+ }>;
9
+ export type AgentKind = z.infer<typeof AgentKindSchema>;
10
+ export declare const AgentStatusSchema: z.ZodEnum<{
11
+ error: "error";
12
+ exited: "exited";
13
+ idle: "idle";
14
+ "needs-you": "needs-you";
15
+ running: "running";
16
+ }>;
17
+ export type AgentStatus = z.infer<typeof AgentStatusSchema>;
18
+ export declare const SUGGESTED_TITLE_LIMIT = 80;
19
+ export declare const SuggestedTitleSchema: z.ZodString;
20
+ export declare const AgentInfoSchema: z.ZodObject<{
21
+ kind: z.ZodEnum<{
22
+ apple: "apple";
23
+ claude: "claude";
24
+ codex: "codex";
25
+ copilot: "copilot";
26
+ gemini: "gemini";
27
+ }>;
28
+ agentSessionId: z.ZodString;
29
+ transcriptPath: z.ZodNullable<z.ZodString>;
30
+ suggestedTitle: z.ZodOptional<z.ZodString>;
31
+ status: z.ZodEnum<{
32
+ error: "error";
33
+ exited: "exited";
34
+ idle: "idle";
35
+ "needs-you": "needs-you";
36
+ running: "running";
37
+ }>;
38
+ live: z.ZodBoolean;
39
+ updatedAt: z.ZodNumber;
40
+ }, z.core.$strip>;
41
+ export type AgentInfo = z.infer<typeof AgentInfoSchema>;
42
+ export declare const SessionStatusEventSchema: z.ZodObject<{
43
+ sessionId: z.ZodString;
44
+ agent: z.ZodNullable<z.ZodObject<{
45
+ kind: z.ZodEnum<{
46
+ apple: "apple";
47
+ claude: "claude";
48
+ codex: "codex";
49
+ copilot: "copilot";
50
+ gemini: "gemini";
51
+ }>;
52
+ agentSessionId: z.ZodString;
53
+ transcriptPath: z.ZodNullable<z.ZodString>;
54
+ suggestedTitle: z.ZodOptional<z.ZodString>;
55
+ status: z.ZodEnum<{
56
+ error: "error";
57
+ exited: "exited";
58
+ idle: "idle";
59
+ "needs-you": "needs-you";
60
+ running: "running";
61
+ }>;
62
+ live: z.ZodBoolean;
63
+ updatedAt: z.ZodNumber;
64
+ }, z.core.$strip>>;
65
+ }, z.core.$strip>;
66
+ export type SessionStatusEvent = z.infer<typeof SessionStatusEventSchema>;
67
+ export declare const AgentResumePayloadSchema: z.ZodObject<{
68
+ sessionId: z.ZodString;
69
+ }, z.core.$strip>;
70
+ export type AgentResumePayload = z.infer<typeof AgentResumePayloadSchema>;
71
+ export declare const ApprovalChoiceSchema: z.ZodObject<{
72
+ id: z.ZodString;
73
+ kind: z.ZodEnum<{
74
+ allow: "allow";
75
+ deny: "deny";
76
+ remember: "remember";
77
+ }>;
78
+ label: z.ZodString;
79
+ }, z.core.$strip>;
80
+ export type ApprovalChoice = z.infer<typeof ApprovalChoiceSchema>;
81
+ export declare const ApprovalRequestSchema: z.ZodObject<{
82
+ requestId: z.ZodString;
83
+ sessionId: z.ZodString;
84
+ toolName: z.ZodString;
85
+ summary: z.ZodString;
86
+ choices: z.ZodArray<z.ZodObject<{
87
+ id: z.ZodString;
88
+ kind: z.ZodEnum<{
89
+ allow: "allow";
90
+ deny: "deny";
91
+ remember: "remember";
92
+ }>;
93
+ label: z.ZodString;
94
+ }, z.core.$strip>>;
95
+ createdAt: z.ZodNumber;
96
+ expiresAt: z.ZodNumber;
97
+ }, z.core.$strip>;
98
+ export type ApprovalRequest = z.infer<typeof ApprovalRequestSchema>;
99
+ export declare const SessionApprovalsEventSchema: z.ZodObject<{
100
+ sessionId: z.ZodString;
101
+ approvals: z.ZodArray<z.ZodObject<{
102
+ requestId: z.ZodString;
103
+ sessionId: z.ZodString;
104
+ toolName: z.ZodString;
105
+ summary: z.ZodString;
106
+ choices: z.ZodArray<z.ZodObject<{
107
+ id: z.ZodString;
108
+ kind: z.ZodEnum<{
109
+ allow: "allow";
110
+ deny: "deny";
111
+ remember: "remember";
112
+ }>;
113
+ label: z.ZodString;
114
+ }, z.core.$strip>>;
115
+ createdAt: z.ZodNumber;
116
+ expiresAt: z.ZodNumber;
117
+ }, z.core.$strip>>;
118
+ }, z.core.$strip>;
119
+ export type SessionApprovalsEvent = z.infer<typeof SessionApprovalsEventSchema>;
120
+ export declare const ApprovalAnswerPayloadSchema: z.ZodObject<{
121
+ sessionId: z.ZodString;
122
+ requestId: z.ZodString;
123
+ choiceId: z.ZodString;
124
+ }, z.core.$strip>;
125
+ export type ApprovalAnswerPayload = z.infer<typeof ApprovalAnswerPayloadSchema>;
126
+ export declare const ApprovalAnswerResultSchema: z.ZodObject<{
127
+ accepted: z.ZodBoolean;
128
+ }, z.core.$strip>;
129
+ export type ApprovalAnswerResult = z.infer<typeof ApprovalAnswerResultSchema>;
130
+ export declare const ApprovalPreferencePayloadSchema: z.ZodObject<{
131
+ enabled: z.ZodBoolean;
132
+ }, z.core.$strip>;
133
+ export type ApprovalPreferencePayload = z.infer<typeof ApprovalPreferencePayloadSchema>;
package/dist/agent.js ADDED
@@ -0,0 +1,79 @@
1
+ import { z } from 'zod';
2
+ import { SessionIdSchema } from './ids.js';
3
+ // The supported agent CLIs. Whether one has a chat backend or a hook normalizer is a capability
4
+ // on its provider, not a second list: a CLI without hooks still opens as a terminal agent.
5
+ export const AgentKindSchema = z.enum(['claude', 'codex', 'gemini', 'copilot', 'apple']);
6
+ // `exited` is the daemon's own reading, not a hook's: the CLI went down with its shell without
7
+ // ever reporting an end, so the node offers a resume instead of a status that stays on running.
8
+ export const AgentStatusSchema = z.enum(['running', 'needs-you', 'idle', 'error', 'exited']);
9
+ // Past this a model's name for a session is a summary, not a title.
10
+ export const SUGGESTED_TITLE_LIMIT = 80;
11
+ // Written by a model, so a node shows it as plain text and nothing reads it as an instruction.
12
+ export const SuggestedTitleSchema = z.string().min(1).max(SUGGESTED_TITLE_LIMIT);
13
+ export const AgentInfoSchema = z.object({
14
+ kind: AgentKindSchema,
15
+ // The CLI's own session id, what `--resume` takes.
16
+ agentSessionId: z.string().min(1),
17
+ transcriptPath: z.string().nullable(),
18
+ // The name the CLI wrote down for the session; Claude Code and the Codex TUI write one.
19
+ suggestedTitle: SuggestedTitleSchema.optional(),
20
+ status: AgentStatusSchema,
21
+ // False once the daemon came back after a restart: the CLI is gone but its session can be resumed.
22
+ live: z.boolean(),
23
+ updatedAt: z.number()
24
+ });
25
+ export const SessionStatusEventSchema = z.object({
26
+ sessionId: SessionIdSchema,
27
+ agent: AgentInfoSchema.nullable()
28
+ });
29
+ export const AgentResumePayloadSchema = z.object({
30
+ sessionId: SessionIdSchema
31
+ });
32
+ /*
33
+ * One button under a permission request. `allow` and `deny` are always there; a `remember` choice
34
+ * only exists when the CLI offered a rule to widen, and the daemon holds that rule rather than the
35
+ * client, so a client never has to know a CLI's permission vocabulary.
36
+ */
37
+ export const ApprovalChoiceSchema = z.object({
38
+ id: z.string().min(1),
39
+ kind: z.enum(['allow', 'remember', 'deny']),
40
+ label: z.string().min(1)
41
+ });
42
+ /*
43
+ * A permission the agent in a terminal is waiting on. The CLI is asking in its own TUI at the same
44
+ * moment, so this is a second way to answer the same question, never the only one: whoever is first
45
+ * wins and `expiresAt` is when the daemon stops holding and leaves the TUI to it.
46
+ */
47
+ export const ApprovalRequestSchema = z.object({
48
+ requestId: z.string().min(1),
49
+ sessionId: SessionIdSchema,
50
+ toolName: z.string().min(1),
51
+ // The one line a person reads: the command for a shell call, the path for a file tool.
52
+ summary: z.string(),
53
+ choices: z.array(ApprovalChoiceSchema).min(1),
54
+ createdAt: z.number(),
55
+ expiresAt: z.number()
56
+ });
57
+ // The whole pending list of one session, so a client that arrives late and one that missed a settle agree.
58
+ export const SessionApprovalsEventSchema = z.object({
59
+ sessionId: SessionIdSchema,
60
+ approvals: z.array(ApprovalRequestSchema)
61
+ });
62
+ export const ApprovalAnswerPayloadSchema = z.object({
63
+ sessionId: SessionIdSchema,
64
+ requestId: z.string().min(1),
65
+ choiceId: z.string().min(1)
66
+ });
67
+ // False when the request was already settled: another client was first, the person used the TUI, or it expired.
68
+ export const ApprovalAnswerResultSchema = z.object({
69
+ accepted: z.boolean()
70
+ });
71
+ /*
72
+ * Whether this client offers permission requests to a person at all. One socket's answer, not the
73
+ * daemon's: with it off the daemon holds nothing for this client, while a second client that still
74
+ * wants them is asked as before. A client that never sends this wants them, which is what every
75
+ * client written before the switch existed meant.
76
+ */
77
+ export const ApprovalPreferencePayloadSchema = z.object({
78
+ enabled: z.boolean()
79
+ });