@termlink/protocol 0.1.0

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,224 @@
1
+ import { z } from "zod";
2
+ export declare const ItemStatus: z.ZodEnum<{
3
+ completed: "completed";
4
+ declined: "declined";
5
+ failed: "failed";
6
+ in_progress: "in_progress";
7
+ interrupted: "interrupted";
8
+ }>;
9
+ export type ItemStatus = z.infer<typeof ItemStatus>;
10
+ export declare const MessageItem: z.ZodObject<{
11
+ id: z.ZodString;
12
+ status: z.ZodEnum<{
13
+ completed: "completed";
14
+ declined: "declined";
15
+ failed: "failed";
16
+ in_progress: "in_progress";
17
+ interrupted: "interrupted";
18
+ }>;
19
+ kind: z.ZodLiteral<"message">;
20
+ role: z.ZodEnum<{
21
+ assistant: "assistant";
22
+ user: "user";
23
+ }>;
24
+ text: z.ZodString;
25
+ }, z.core.$strip>;
26
+ export type MessageItem = z.infer<typeof MessageItem>;
27
+ export declare const ReasoningItem: z.ZodObject<{
28
+ id: z.ZodString;
29
+ status: z.ZodEnum<{
30
+ completed: "completed";
31
+ declined: "declined";
32
+ failed: "failed";
33
+ in_progress: "in_progress";
34
+ interrupted: "interrupted";
35
+ }>;
36
+ kind: z.ZodLiteral<"reasoning">;
37
+ text: z.ZodString;
38
+ }, z.core.$strip>;
39
+ export type ReasoningItem = z.infer<typeof ReasoningItem>;
40
+ export declare const CommandItem: z.ZodObject<{
41
+ id: z.ZodString;
42
+ status: z.ZodEnum<{
43
+ completed: "completed";
44
+ declined: "declined";
45
+ failed: "failed";
46
+ in_progress: "in_progress";
47
+ interrupted: "interrupted";
48
+ }>;
49
+ kind: z.ZodLiteral<"command">;
50
+ command: z.ZodString;
51
+ display: z.ZodOptional<z.ZodString>;
52
+ cwd: z.ZodOptional<z.ZodString>;
53
+ output: z.ZodOptional<z.ZodString>;
54
+ exitCode: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
55
+ }, z.core.$strip>;
56
+ export type CommandItem = z.infer<typeof CommandItem>;
57
+ export declare const FileChange: z.ZodObject<{
58
+ path: z.ZodString;
59
+ action: z.ZodEnum<{
60
+ add: "add";
61
+ delete: "delete";
62
+ modify: "modify";
63
+ rename: "rename";
64
+ }>;
65
+ movePath: z.ZodOptional<z.ZodString>;
66
+ diff: z.ZodOptional<z.ZodString>;
67
+ }, z.core.$strip>;
68
+ export type FileChange = z.infer<typeof FileChange>;
69
+ export declare const FileChangeItem: z.ZodObject<{
70
+ id: z.ZodString;
71
+ status: z.ZodEnum<{
72
+ completed: "completed";
73
+ declined: "declined";
74
+ failed: "failed";
75
+ in_progress: "in_progress";
76
+ interrupted: "interrupted";
77
+ }>;
78
+ kind: z.ZodLiteral<"file_change">;
79
+ changes: z.ZodArray<z.ZodObject<{
80
+ path: z.ZodString;
81
+ action: z.ZodEnum<{
82
+ add: "add";
83
+ delete: "delete";
84
+ modify: "modify";
85
+ rename: "rename";
86
+ }>;
87
+ movePath: z.ZodOptional<z.ZodString>;
88
+ diff: z.ZodOptional<z.ZodString>;
89
+ }, z.core.$strip>>;
90
+ }, z.core.$strip>;
91
+ export type FileChangeItem = z.infer<typeof FileChangeItem>;
92
+ /** Any tool call that is not a shell command or a file edit (MCP, web search, ...). */
93
+ export declare const ToolItem: z.ZodObject<{
94
+ id: z.ZodString;
95
+ status: z.ZodEnum<{
96
+ completed: "completed";
97
+ declined: "declined";
98
+ failed: "failed";
99
+ in_progress: "in_progress";
100
+ interrupted: "interrupted";
101
+ }>;
102
+ kind: z.ZodLiteral<"tool">;
103
+ name: z.ZodString;
104
+ input: z.ZodOptional<z.ZodUnknown>;
105
+ output: z.ZodOptional<z.ZodUnknown>;
106
+ }, z.core.$strip>;
107
+ export type ToolItem = z.infer<typeof ToolItem>;
108
+ export declare const TodoItem: z.ZodObject<{
109
+ id: z.ZodString;
110
+ status: z.ZodEnum<{
111
+ completed: "completed";
112
+ declined: "declined";
113
+ failed: "failed";
114
+ in_progress: "in_progress";
115
+ interrupted: "interrupted";
116
+ }>;
117
+ kind: z.ZodLiteral<"todo">;
118
+ entries: z.ZodArray<z.ZodObject<{
119
+ text: z.ZodString;
120
+ done: z.ZodBoolean;
121
+ }, z.core.$strip>>;
122
+ }, z.core.$strip>;
123
+ export type TodoItem = z.infer<typeof TodoItem>;
124
+ export declare const Item: z.ZodDiscriminatedUnion<[z.ZodObject<{
125
+ id: z.ZodString;
126
+ status: z.ZodEnum<{
127
+ completed: "completed";
128
+ declined: "declined";
129
+ failed: "failed";
130
+ in_progress: "in_progress";
131
+ interrupted: "interrupted";
132
+ }>;
133
+ kind: z.ZodLiteral<"message">;
134
+ role: z.ZodEnum<{
135
+ assistant: "assistant";
136
+ user: "user";
137
+ }>;
138
+ text: z.ZodString;
139
+ }, z.core.$strip>, z.ZodObject<{
140
+ id: z.ZodString;
141
+ status: z.ZodEnum<{
142
+ completed: "completed";
143
+ declined: "declined";
144
+ failed: "failed";
145
+ in_progress: "in_progress";
146
+ interrupted: "interrupted";
147
+ }>;
148
+ kind: z.ZodLiteral<"reasoning">;
149
+ text: z.ZodString;
150
+ }, z.core.$strip>, z.ZodObject<{
151
+ id: z.ZodString;
152
+ status: z.ZodEnum<{
153
+ completed: "completed";
154
+ declined: "declined";
155
+ failed: "failed";
156
+ in_progress: "in_progress";
157
+ interrupted: "interrupted";
158
+ }>;
159
+ kind: z.ZodLiteral<"command">;
160
+ command: z.ZodString;
161
+ display: z.ZodOptional<z.ZodString>;
162
+ cwd: z.ZodOptional<z.ZodString>;
163
+ output: z.ZodOptional<z.ZodString>;
164
+ exitCode: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
165
+ }, z.core.$strip>, z.ZodObject<{
166
+ id: z.ZodString;
167
+ status: z.ZodEnum<{
168
+ completed: "completed";
169
+ declined: "declined";
170
+ failed: "failed";
171
+ in_progress: "in_progress";
172
+ interrupted: "interrupted";
173
+ }>;
174
+ kind: z.ZodLiteral<"file_change">;
175
+ changes: z.ZodArray<z.ZodObject<{
176
+ path: z.ZodString;
177
+ action: z.ZodEnum<{
178
+ add: "add";
179
+ delete: "delete";
180
+ modify: "modify";
181
+ rename: "rename";
182
+ }>;
183
+ movePath: z.ZodOptional<z.ZodString>;
184
+ diff: z.ZodOptional<z.ZodString>;
185
+ }, z.core.$strip>>;
186
+ }, z.core.$strip>, z.ZodObject<{
187
+ id: z.ZodString;
188
+ status: z.ZodEnum<{
189
+ completed: "completed";
190
+ declined: "declined";
191
+ failed: "failed";
192
+ in_progress: "in_progress";
193
+ interrupted: "interrupted";
194
+ }>;
195
+ kind: z.ZodLiteral<"tool">;
196
+ name: z.ZodString;
197
+ input: z.ZodOptional<z.ZodUnknown>;
198
+ output: z.ZodOptional<z.ZodUnknown>;
199
+ }, z.core.$strip>, z.ZodObject<{
200
+ id: z.ZodString;
201
+ status: z.ZodEnum<{
202
+ completed: "completed";
203
+ declined: "declined";
204
+ failed: "failed";
205
+ in_progress: "in_progress";
206
+ interrupted: "interrupted";
207
+ }>;
208
+ kind: z.ZodLiteral<"todo">;
209
+ entries: z.ZodArray<z.ZodObject<{
210
+ text: z.ZodString;
211
+ done: z.ZodBoolean;
212
+ }, z.core.$strip>>;
213
+ }, z.core.$strip>], "kind">;
214
+ export type Item = z.infer<typeof Item>;
215
+ export type ItemKind = Item["kind"];
216
+ /** Which string field an item.delta appends to. */
217
+ export declare const DeltaField: z.ZodEnum<{
218
+ output: "output";
219
+ text: "text";
220
+ }>;
221
+ export type DeltaField = z.infer<typeof DeltaField>;
222
+ /** Applies an item.delta to an item. Shared by host and clients so both accumulate the same way. */
223
+ export declare function applyDelta(item: Item, field: DeltaField, delta: string): Item;
224
+ //# sourceMappingURL=items.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"items.d.ts","sourceRoot":"","sources":["../src/items.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,UAAU;;;;;;EAA4E,CAAC;AACpG,MAAM,MAAM,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xC,MAAM,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;AAEpC,mDAAmD;AACnD,eAAO,MAAM,UAAU;;;EAA6B,CAAC;AACrD,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AAEpD,oGAAoG;AACpG,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAQ7E"}
package/dist/items.js ADDED
@@ -0,0 +1,76 @@
1
+ import { z } from "zod";
2
+ export const ItemStatus = z.enum(["in_progress", "completed", "failed", "declined", "interrupted"]);
3
+ const itemBase = {
4
+ id: z.string(),
5
+ status: ItemStatus,
6
+ };
7
+ export const MessageItem = z.object({
8
+ ...itemBase,
9
+ kind: z.literal("message"),
10
+ role: z.enum(["user", "assistant"]),
11
+ text: z.string(),
12
+ });
13
+ export const ReasoningItem = z.object({
14
+ ...itemBase,
15
+ kind: z.literal("reasoning"),
16
+ text: z.string(),
17
+ });
18
+ export const CommandItem = z.object({
19
+ ...itemBase,
20
+ kind: z.literal("command"),
21
+ command: z.string(),
22
+ /**
23
+ * Short form for the timeline, e.g. without a PowerShell or `sh -lc` wrapper.
24
+ * Absent when the command is already plain. Approvals always carry the full command.
25
+ */
26
+ display: z.string().optional(),
27
+ cwd: z.string().optional(),
28
+ output: z.string().optional(),
29
+ exitCode: z.number().int().nullable().optional(),
30
+ });
31
+ export const FileChange = z.object({
32
+ path: z.string(),
33
+ action: z.enum(["add", "modify", "delete", "rename"]),
34
+ movePath: z.string().optional(),
35
+ /** Unified diff. Hosts compute it when the provider only reports old/new text. */
36
+ diff: z.string().optional(),
37
+ });
38
+ export const FileChangeItem = z.object({
39
+ ...itemBase,
40
+ kind: z.literal("file_change"),
41
+ changes: z.array(FileChange),
42
+ });
43
+ /** Any tool call that is not a shell command or a file edit (MCP, web search, ...). */
44
+ export const ToolItem = z.object({
45
+ ...itemBase,
46
+ kind: z.literal("tool"),
47
+ name: z.string(),
48
+ input: z.unknown().optional(),
49
+ output: z.unknown().optional(),
50
+ });
51
+ export const TodoItem = z.object({
52
+ ...itemBase,
53
+ kind: z.literal("todo"),
54
+ entries: z.array(z.object({ text: z.string(), done: z.boolean() })),
55
+ });
56
+ export const Item = z.discriminatedUnion("kind", [
57
+ MessageItem,
58
+ ReasoningItem,
59
+ CommandItem,
60
+ FileChangeItem,
61
+ ToolItem,
62
+ TodoItem,
63
+ ]);
64
+ /** Which string field an item.delta appends to. */
65
+ export const DeltaField = z.enum(["text", "output"]);
66
+ /** Applies an item.delta to an item. Shared by host and clients so both accumulate the same way. */
67
+ export function applyDelta(item, field, delta) {
68
+ if (field === "text" && (item.kind === "message" || item.kind === "reasoning")) {
69
+ return { ...item, text: item.text + delta };
70
+ }
71
+ if (field === "output" && item.kind === "command") {
72
+ return { ...item, output: (item.output ?? "") + delta };
73
+ }
74
+ return item;
75
+ }
76
+ //# sourceMappingURL=items.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"items.js","sourceRoot":"","sources":["../src/items.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC;AAGpG,MAAM,QAAQ,GAAG;IACf,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,MAAM,EAAE,UAAU;CACnB,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,GAAG,QAAQ;IACX,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC;IAC1B,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACnC,IAAI,EAAE,CA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,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,GAAG,KAAK,EAAE,CAAC;IAC9C,CAAC;IACD,IAAI,KAAK,KAAK,QAAQ,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAClD,OAAO,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC;IAC1D,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@termlink/protocol",
3
+ "version": "0.1.0",
4
+ "description": "TermLink agent protocol: command, response and event schemas shared by host and clients",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "source": "./src/index.ts",
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ }
12
+ },
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "scripts": {
17
+ "build": "tsc -b",
18
+ "test": "node --conditions=source --import tsx --test \"test/**/*.test.ts\"",
19
+ "prepublishOnly": "tsc -b"
20
+ },
21
+ "dependencies": {
22
+ "zod": "^4.6.2"
23
+ },
24
+ "license": "MIT",
25
+ "author": "Bert Shim",
26
+ "homepage": "https://getterm.link",
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "keywords": [
31
+ "termlink",
32
+ "protocol"
33
+ ]
34
+ }