@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/package.json CHANGED
@@ -1,11 +1,104 @@
1
1
  {
2
2
  "name": "@adecore/agent-contracts",
3
- "version": "0.0.1",
4
- "description": "Placeholder for the first release.",
3
+ "version": "0.17.0-beta.2",
4
+ "description": "Schemas and port contracts for agent chats, provider accounts, models and usage.",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "source": "./src/index.ts",
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ },
12
+ "./agent": {
13
+ "source": "./src/agent.ts",
14
+ "types": "./dist/agent.d.ts",
15
+ "default": "./dist/agent.js"
16
+ },
17
+ "./chat": {
18
+ "source": "./src/chat.ts",
19
+ "types": "./dist/chat.d.ts",
20
+ "default": "./dist/chat.js"
21
+ },
22
+ "./envelope": {
23
+ "source": "./src/envelope.ts",
24
+ "types": "./dist/envelope.d.ts",
25
+ "default": "./dist/envelope.js"
26
+ },
27
+ "./ids": {
28
+ "source": "./src/ids.ts",
29
+ "types": "./dist/ids.d.ts",
30
+ "default": "./dist/ids.js"
31
+ },
32
+ "./model": {
33
+ "source": "./src/model.ts",
34
+ "types": "./dist/model.d.ts",
35
+ "default": "./dist/model.js"
36
+ },
37
+ "./port": {
38
+ "source": "./src/port.ts",
39
+ "types": "./dist/port.d.ts",
40
+ "default": "./dist/port.js"
41
+ },
42
+ "./protocol": {
43
+ "source": "./src/protocol.ts",
44
+ "types": "./dist/protocol.d.ts",
45
+ "default": "./dist/protocol.js"
46
+ },
47
+ "./provider-accounts": {
48
+ "source": "./src/provider-accounts.ts",
49
+ "types": "./dist/provider-accounts.d.ts",
50
+ "default": "./dist/provider-accounts.js"
51
+ },
52
+ "./task": {
53
+ "source": "./src/task.ts",
54
+ "types": "./dist/task.d.ts",
55
+ "default": "./dist/task.js"
56
+ },
57
+ "./text": {
58
+ "source": "./src/text.ts",
59
+ "types": "./dist/text.d.ts",
60
+ "default": "./dist/text.js"
61
+ },
62
+ "./usage": {
63
+ "source": "./src/usage.ts",
64
+ "types": "./dist/usage.d.ts",
65
+ "default": "./dist/usage.js"
66
+ },
67
+ "./worktree": {
68
+ "source": "./src/worktree.ts",
69
+ "types": "./dist/worktree.d.ts",
70
+ "default": "./dist/worktree.js"
71
+ }
72
+ },
73
+ "scripts": {
74
+ "typecheck": "tsc --noEmit",
75
+ "build": "bun scripts/build.ts",
76
+ "test": "bun --conditions=source test"
77
+ },
78
+ "dependencies": {
79
+ "zod": "^4.6.5"
80
+ },
81
+ "devDependencies": {
82
+ "@types/bun": "^1.4.2",
83
+ "typescript": "^7.0.2"
84
+ },
5
85
  "license": "FSL-1.1-MIT",
86
+ "author": "Bas Milius",
6
87
  "repository": {
7
88
  "type": "git",
8
89
  "url": "git+https://github.com/basmilius/adecore.git",
9
90
  "directory": "packages/agent-contracts"
10
- }
91
+ },
92
+ "bugs": {
93
+ "url": "https://github.com/basmilius/adecore/issues"
94
+ },
95
+ "homepage": "https://adecore.dev/agent-contracts/",
96
+ "files": [
97
+ "dist",
98
+ "src",
99
+ "!src/**/*.test.ts",
100
+ "!src/**/*.test.tsx",
101
+ "!src/**/__snapshots__"
102
+ ],
103
+ "sideEffects": false
11
104
  }
package/src/agent.ts ADDED
@@ -0,0 +1,103 @@
1
+ import { z } from 'zod';
2
+ import { SessionIdSchema } from './ids.ts';
3
+
4
+ // The supported agent CLIs. Whether one has a chat backend or a hook normalizer is a capability
5
+ // on its provider, not a second list: a CLI without hooks still opens as a terminal agent.
6
+ export const AgentKindSchema = z.enum(['claude', 'codex', 'gemini', 'copilot', 'apple']);
7
+ export type AgentKind = z.infer<typeof AgentKindSchema>;
8
+
9
+ // `exited` is the daemon's own reading, not a hook's: the CLI went down with its shell without
10
+ // ever reporting an end, so the node offers a resume instead of a status that stays on running.
11
+ export const AgentStatusSchema = z.enum(['running', 'needs-you', 'idle', 'error', 'exited']);
12
+ export type AgentStatus = z.infer<typeof AgentStatusSchema>;
13
+
14
+ // Past this a model's name for a session is a summary, not a title.
15
+ export const SUGGESTED_TITLE_LIMIT = 80;
16
+
17
+ // Written by a model, so a node shows it as plain text and nothing reads it as an instruction.
18
+ export const SuggestedTitleSchema = z.string().min(1).max(SUGGESTED_TITLE_LIMIT);
19
+
20
+ export const AgentInfoSchema = z.object({
21
+ kind: AgentKindSchema,
22
+ // The CLI's own session id, what `--resume` takes.
23
+ agentSessionId: z.string().min(1),
24
+ transcriptPath: z.string().nullable(),
25
+ // The name the CLI wrote down for the session; Claude Code and the Codex TUI write one.
26
+ suggestedTitle: SuggestedTitleSchema.optional(),
27
+ status: AgentStatusSchema,
28
+ // False once the daemon came back after a restart: the CLI is gone but its session can be resumed.
29
+ live: z.boolean(),
30
+ updatedAt: z.number()
31
+ });
32
+ export type AgentInfo = z.infer<typeof AgentInfoSchema>;
33
+
34
+ export const SessionStatusEventSchema = z.object({
35
+ sessionId: SessionIdSchema,
36
+ agent: AgentInfoSchema.nullable()
37
+ });
38
+ export type SessionStatusEvent = z.infer<typeof SessionStatusEventSchema>;
39
+
40
+ export const AgentResumePayloadSchema = z.object({
41
+ sessionId: SessionIdSchema
42
+ });
43
+ export type AgentResumePayload = z.infer<typeof AgentResumePayloadSchema>;
44
+
45
+ /*
46
+ * One button under a permission request. `allow` and `deny` are always there; a `remember` choice
47
+ * only exists when the CLI offered a rule to widen, and the daemon holds that rule rather than the
48
+ * client, so a client never has to know a CLI's permission vocabulary.
49
+ */
50
+ export const ApprovalChoiceSchema = z.object({
51
+ id: z.string().min(1),
52
+ kind: z.enum(['allow', 'remember', 'deny']),
53
+ label: z.string().min(1)
54
+ });
55
+ export type ApprovalChoice = z.infer<typeof ApprovalChoiceSchema>;
56
+
57
+ /*
58
+ * A permission the agent in a terminal is waiting on. The CLI is asking in its own TUI at the same
59
+ * moment, so this is a second way to answer the same question, never the only one: whoever is first
60
+ * wins and `expiresAt` is when the daemon stops holding and leaves the TUI to it.
61
+ */
62
+ export const ApprovalRequestSchema = z.object({
63
+ requestId: z.string().min(1),
64
+ sessionId: SessionIdSchema,
65
+ toolName: z.string().min(1),
66
+ // The one line a person reads: the command for a shell call, the path for a file tool.
67
+ summary: z.string(),
68
+ choices: z.array(ApprovalChoiceSchema).min(1),
69
+ createdAt: z.number(),
70
+ expiresAt: z.number()
71
+ });
72
+ export type ApprovalRequest = z.infer<typeof ApprovalRequestSchema>;
73
+
74
+ // The whole pending list of one session, so a client that arrives late and one that missed a settle agree.
75
+ export const SessionApprovalsEventSchema = z.object({
76
+ sessionId: SessionIdSchema,
77
+ approvals: z.array(ApprovalRequestSchema)
78
+ });
79
+ export type SessionApprovalsEvent = z.infer<typeof SessionApprovalsEventSchema>;
80
+
81
+ export const ApprovalAnswerPayloadSchema = z.object({
82
+ sessionId: SessionIdSchema,
83
+ requestId: z.string().min(1),
84
+ choiceId: z.string().min(1)
85
+ });
86
+ export type ApprovalAnswerPayload = z.infer<typeof ApprovalAnswerPayloadSchema>;
87
+
88
+ // False when the request was already settled: another client was first, the person used the TUI, or it expired.
89
+ export const ApprovalAnswerResultSchema = z.object({
90
+ accepted: z.boolean()
91
+ });
92
+ export type ApprovalAnswerResult = z.infer<typeof ApprovalAnswerResultSchema>;
93
+
94
+ /*
95
+ * Whether this client offers permission requests to a person at all. One socket's answer, not the
96
+ * daemon's: with it off the daemon holds nothing for this client, while a second client that still
97
+ * wants them is asked as before. A client that never sends this wants them, which is what every
98
+ * client written before the switch existed meant.
99
+ */
100
+ export const ApprovalPreferencePayloadSchema = z.object({
101
+ enabled: z.boolean()
102
+ });
103
+ export type ApprovalPreferencePayload = z.infer<typeof ApprovalPreferencePayloadSchema>;