@kernl-sdk/protocol 0.1.1 → 0.2.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.
@@ -1,4 +1,5 @@
1
-
2
- > @kernl-sdk/protocol@0.1.1 build /Users/andjones/Documents/projects/kernl/packages/protocol
3
- > tsc && tsc-alias
4
-
1
+
2
+ 
3
+ > @kernl-sdk/protocol@0.1.1 build /Users/andjones/Documents/projects/kernl/packages/protocol
4
+ > tsc && tsc-alias
5
+
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @kernl/protocol
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - fffa89e: Add thread/task state constants and language model helper functions
8
+
3
9
  ## 0.1.1
4
10
 
5
11
  ### Patch Changes
package/dist/codec.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Bidirectional codec for converting between Kernl protocol types and provider-specific types.
2
+ * Bidirectional codec for converting between kernl protocol types and provider-specific types.
3
3
  *
4
4
  * @example
5
5
  * ```typescript
@@ -11,11 +11,11 @@
11
11
  */
12
12
  export interface Codec<TKernl, TProvider> {
13
13
  /**
14
- * Transform from Kernl protocol format to provider format.
14
+ * Transform from kernl protocol format to provider format.
15
15
  */
16
16
  encode: (value: TKernl) => TProvider;
17
17
  /**
18
- * Transform from provider format to Kernl protocol format.
18
+ * Transform from provider format to kernl protocol format.
19
19
  */
20
20
  decode: (value: TProvider) => TKernl;
21
21
  }
@@ -1,11 +1,61 @@
1
1
  /**
2
2
  * Protocol Constants
3
3
  *
4
- * Centralized constants for the Kernl protocol.
4
+ * Centralized constants for the kernl protocol.
5
5
  */
6
6
  export declare const IN_PROGRESS = "in_progress";
7
7
  export declare const COMPLETED = "completed";
8
8
  export declare const FAILED = "failed";
9
+ /**
10
+ * Task is either:
11
+ * - Currently executing
12
+ * - In run queue waiting to be scheduled (might want to differentiate between running + queued here)
13
+ */
14
+ export declare const RUNNING = "running";
15
+ /**
16
+ * Task is sleeping/blocked, waiting for a condition.
17
+ * Can be woken up by:
18
+ * - The condition being met (e.g., approval granted)
19
+ * - A signal (e.g., user cancellation)
20
+ *
21
+ * Examples:
22
+ * - Waiting for tool approval
23
+ * - Waiting for user input
24
+ * - Sleeping on a timer
25
+ */
9
26
  export declare const INTERRUPTIBLE = "interruptible";
27
+ /**
28
+ * Task is sleeping/blocked and CANNOT be interrupted by signals.
29
+ * Only wakes when the condition is met.
30
+ *
31
+ * Examples:
32
+ * - Waiting for critical I/O (model API call)
33
+ * - Waiting for resource that MUST complete
34
+ *
35
+ * Use sparingly - these tasks can't be cancelled!
36
+ */
10
37
  export declare const UNINTERRUPTIBLE = "uninterruptible";
38
+ /**
39
+ * Task has been stopped by a signal (SIGSTOP).
40
+ * Will remain stopped until explicitly continued (SIGCONT).
41
+ *
42
+ * Examples:
43
+ * - User explicitly paused the agent
44
+ * - Debugger attached
45
+ */
46
+ export declare const STOPPED = "stopped";
47
+ /**
48
+ * Task has finished execution but hasn't been cleaned up yet.
49
+ * Waiting for parent to read exit status (wait/waitpid).
50
+ *
51
+ * Examples:
52
+ * - Agent completed but result not yet retrieved
53
+ * - Child agent finished, parent needs to collect result
54
+ */
55
+ export declare const ZOMBIE = "zombie";
56
+ /**
57
+ * Task is being removed from the system.
58
+ * Final cleanup in progress, about to be fully deleted.
59
+ */
60
+ export declare const DEAD = "dead";
11
61
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,eAAO,MAAM,WAAW,gBAAgB,CAAC;AACzC,eAAO,MAAM,SAAS,cAAc,CAAC;AACrC,eAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,eAAO,MAAM,aAAa,kBAAkB,CAAC;AAC7C,eAAO,MAAM,eAAe,oBAAoB,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,eAAO,MAAM,WAAW,gBAAgB,CAAC;AACzC,eAAO,MAAM,SAAS,cAAc,CAAC;AACrC,eAAO,MAAM,MAAM,WAAW,CAAC;AAM/B;;;;GAIG;AACH,eAAO,MAAM,OAAO,YAAY,CAAC;AAEjC;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,kBAAkB,CAAC;AAE7C;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,oBAAoB,CAAC;AAEjD;;;;;;;GAOG;AACH,eAAO,MAAM,OAAO,YAAY,CAAC;AAEjC;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,WAAW,CAAC;AAE/B;;;GAGG;AACH,eAAO,MAAM,IAAI,SAAS,CAAC"}
package/dist/constants.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Protocol Constants
3
3
  *
4
- * Centralized constants for the Kernl protocol.
4
+ * Centralized constants for the kernl protocol.
5
5
  */
6
6
  // ----------------------------
7
7
  // Tool states
@@ -9,5 +9,58 @@
9
9
  export const IN_PROGRESS = "in_progress";
10
10
  export const COMPLETED = "completed";
11
11
  export const FAILED = "failed";
12
+ // ----------------------------
13
+ // Thread/Task states
14
+ // ----------------------------
15
+ /**
16
+ * Task is either:
17
+ * - Currently executing
18
+ * - In run queue waiting to be scheduled (might want to differentiate between running + queued here)
19
+ */
20
+ export const RUNNING = "running";
21
+ /**
22
+ * Task is sleeping/blocked, waiting for a condition.
23
+ * Can be woken up by:
24
+ * - The condition being met (e.g., approval granted)
25
+ * - A signal (e.g., user cancellation)
26
+ *
27
+ * Examples:
28
+ * - Waiting for tool approval
29
+ * - Waiting for user input
30
+ * - Sleeping on a timer
31
+ */
12
32
  export const INTERRUPTIBLE = "interruptible";
33
+ /**
34
+ * Task is sleeping/blocked and CANNOT be interrupted by signals.
35
+ * Only wakes when the condition is met.
36
+ *
37
+ * Examples:
38
+ * - Waiting for critical I/O (model API call)
39
+ * - Waiting for resource that MUST complete
40
+ *
41
+ * Use sparingly - these tasks can't be cancelled!
42
+ */
13
43
  export const UNINTERRUPTIBLE = "uninterruptible";
44
+ /**
45
+ * Task has been stopped by a signal (SIGSTOP).
46
+ * Will remain stopped until explicitly continued (SIGCONT).
47
+ *
48
+ * Examples:
49
+ * - User explicitly paused the agent
50
+ * - Debugger attached
51
+ */
52
+ export const STOPPED = "stopped";
53
+ /**
54
+ * Task has finished execution but hasn't been cleaned up yet.
55
+ * Waiting for parent to read exit status (wait/waitpid).
56
+ *
57
+ * Examples:
58
+ * - Agent completed but result not yet retrieved
59
+ * - Child agent finished, parent needs to collect result
60
+ */
61
+ export const ZOMBIE = "zombie";
62
+ /**
63
+ * Task is being removed from the system.
64
+ * Final cleanup in progress, about to be fully deleted.
65
+ */
66
+ export const DEAD = "dead";
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Kernl Provider Protocol
2
+ * kernl Provider Protocol
3
3
  *
4
4
  * Standard interfaces and types for AI model providers.
5
5
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,cAAc,aAAa,CAAC;AAG5B,cAAc,kBAAkB,CAAC;AAGjC,cAAc,mBAAmB,CAAC;AAGlC,cAAc,YAAY,CAAC;AAG3B,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -1,15 +1,10 @@
1
1
  /**
2
- * Kernl Provider Protocol
2
+ * kernl Provider Protocol
3
3
  *
4
4
  * Standard interfaces and types for AI model providers.
5
5
  */
6
- // Constants
7
6
  export * from "./constants";
8
- // Language Model Protocol
9
7
  export * from "./language-model";
10
- // Embedding Model Protocol
11
8
  export * from "./embedding-model";
12
- // Provider Base Types
13
9
  export * from "./provider";
14
- // Codec Interface
15
10
  export * from "./codec";
@@ -3,4 +3,5 @@ export * from "./model";
3
3
  export * from "./request";
4
4
  export * from "./stream";
5
5
  export * from "./tool";
6
+ export * from "./utils";
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/language-model/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/language-model/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC"}
@@ -3,3 +3,4 @@ export * from "./model";
3
3
  export * from "./request";
4
4
  export * from "./stream";
5
5
  export * from "./tool";
6
+ export * from "./utils";
@@ -1,12 +1,12 @@
1
1
  import { SharedProviderMetadata } from "../provider";
2
2
  import { JSONValue } from "../json";
3
3
  import { IN_PROGRESS, COMPLETED, FAILED, INTERRUPTIBLE, UNINTERRUPTIBLE } from "../constants";
4
- export type LanguageModelItem = Message | Reasoning | ToolCall | ToolResult | Unknown;
4
+ export type LanguageModelItem = Message | Reasoning | ToolCall | ToolResult;
5
5
  /**
6
6
  * A subset of LanguageModelItem that excludes items that wouldn't
7
7
  * make sense for a model to generate (e.g. system/user messages, tool results).
8
8
  */
9
- export type LanguageModelResponseItem = AssistantMessage | Reasoning | ToolCall | Unknown;
9
+ export type LanguageModelResponseItem = AssistantMessage | Reasoning | ToolCall | ToolResult;
10
10
  export interface SharedBase {
11
11
  /**
12
12
  * Optional provider-specific metadata for the text part.
@@ -82,18 +82,6 @@ export interface Reasoning extends LanguageModelItemBase {
82
82
  */
83
83
  text: string;
84
84
  }
85
- /**
86
- * This is a catch all for events that are not part of the protocol.
87
- *
88
- * For example, a model might return an event that is not part of the protocol using this type.
89
- *
90
- * In that case everything returned from the model should be passed in the `providerMetadata` field.
91
- *
92
- * This enables new features to be added to be added by a model provider without breaking the protocol.
93
- */
94
- export interface Unknown extends LanguageModelItemBase {
95
- readonly kind: "unknown";
96
- }
97
85
  export interface MessageBase extends SharedBase {
98
86
  readonly kind: "message";
99
87
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"item.d.ts","sourceRoot":"","sources":["../../src/language-model/item.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EACL,WAAW,EACX,SAAS,EACT,MAAM,EACN,aAAa,EACb,eAAe,EAChB,MAAM,aAAa,CAAC;AAErB,MAAM,MAAM,iBAAiB,GACzB,OAAO,GACP,SAAS,GACT,QAAQ,GACR,UAAU,GACV,OAAO,CAAC;AAEZ;;;GAGG;AACH,MAAM,MAAM,yBAAyB,GACjC,gBAAgB,GAChB,SAAS,GACT,QAAQ,GACR,OAAO,CAAC;AAEZ,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,gBAAgB,CAAC,EAAE,sBAAsB,CAAC;CAC3C;AAED;;GAEG;AACH,MAAM,WAAW,qBAAsB,SAAQ,UAAU;IACvD;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAMD;;GAEG;AACH,MAAM,WAAW,QAAS,SAAQ,UAAU;IAC1C,mDAAmD;IACnD,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,QAAS,SAAQ,QAAQ;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AAC,CAAC;IAE/B;;OAEG;IACH,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GACrB,OAAO,WAAW,GAClB,OAAO,SAAS,GAChB,OAAO,MAAM,GACb,OAAO,aAAa,GACpB,OAAO,eAAe,CAAC"}
@@ -1,10 +1,10 @@
1
1
  import { SharedProviderMetadata } from "../provider";
2
2
  import type { LanguageModelFinishReason, LanguageModelUsage, LanguageModelWarning } from "./model";
3
- import type { ToolCallState } from "./item";
3
+ import type { Message, Reasoning, ToolCall, ToolResult } from "./item";
4
4
  /**
5
- * Union of all possible language model stream events.
5
+ * Union of all language model stream events.
6
6
  */
7
- export type LanguageModelStreamEvent = TextStartEvent | TextEndEvent | TextDeltaEvent | ReasoningStartEvent | ReasoningEndEvent | ReasoningDeltaEvent | ToolInputStartEvent | ToolInputEndEvent | ToolInputDeltaEvent | ToolCallEvent | ToolResultEvent | StartEvent | FinishEvent | AbortEvent | ErrorEvent | RawEvent;
7
+ export type LanguageModelStreamEvent = TextStartEvent | TextDeltaEvent | TextEndEvent | Message | ReasoningStartEvent | ReasoningDeltaEvent | ReasoningEndEvent | Reasoning | ToolInputStartEvent | ToolInputEndEvent | ToolInputDeltaEvent | ToolCall | ToolResult | StartEvent | FinishEvent | AbortEvent | ErrorEvent | RawEvent;
8
8
  /**
9
9
  * Base interface for all stream events.
10
10
  */
@@ -101,47 +101,6 @@ export interface ToolInputDeltaEvent extends StreamEventBase {
101
101
  */
102
102
  delta: string;
103
103
  }
104
- /**
105
- * Stream event containing a complete tool call.
106
- */
107
- export interface ToolCallEvent extends StreamEventBase {
108
- readonly kind: "tool-call";
109
- id: string;
110
- /**
111
- * The name of the tool being called.
112
- */
113
- toolName: string;
114
- /**
115
- * The arguments for the tool call as a JSON string.
116
- */
117
- arguments: string;
118
- }
119
- /**
120
- * Stream event containing a tool result from a provider-executed tool.
121
- */
122
- export interface ToolResultEvent extends StreamEventBase {
123
- readonly kind: "tool-result";
124
- /**
125
- * The ID of the tool call that this result is associated with.
126
- */
127
- callId: string;
128
- /**
129
- * Name of the tool that generated this result.
130
- */
131
- toolId: string;
132
- /**
133
- * The state of the tool call.
134
- */
135
- state: ToolCallState;
136
- /**
137
- * Result of the tool call. This is a JSON-serializable value.
138
- */
139
- result: unknown;
140
- /**
141
- * Error message if the tool call failed.
142
- */
143
- error: string | null;
144
- }
145
104
  /**
146
105
  * Stream event indicating the start of agent execution.
147
106
  */
@@ -1 +1 @@
1
- {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/language-model/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEpD,OAAO,KAAK,EACV,yBAAyB,EACzB,kBAAkB,EAClB,oBAAoB,EACrB,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAE5C;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAChC,cAAc,GACd,YAAY,GACZ,cAAc,GACd,mBAAmB,GACnB,iBAAiB,GACjB,mBAAmB,GACnB,mBAAmB,GACnB,iBAAiB,GACjB,mBAAmB,GACnB,aAAa,GACb,eAAe,GACf,UAAU,GACV,WAAW,GACX,UAAU,GACV,UAAU,GACV,QAAQ,CAAC;AAEb;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,gBAAgB,CAAC,EAAE,sBAAsB,CAAC;CAC3C;AAED;;GAEG;AACH,MAAM,WAAW,cAAe,SAAQ,eAAe;IACrD,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,EAAE,EAAE,MAAM,CAAC;CACZ;AAED;;GAEG;AACH,MAAM,WAAW,YAAa,SAAQ,eAAe;IACnD,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,EAAE,EAAE,MAAM,CAAC;CACZ;AAED;;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C,IAAI,EAAE,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,UAAW,SAAQ,eAAe;IACjD,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAEvB;;OAEG;IACH,KAAK,EAAE,OAAO,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,QAAS,SAAQ,eAAe;IAC/C,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IAErB;;OAEG;IACH,QAAQ,EAAE,OAAO,CAAC;CACnB"}
@@ -0,0 +1,19 @@
1
+ import { SharedProviderMetadata } from "../provider";
2
+ import { Message, Reasoning } from "./item";
3
+ /**
4
+ * Create a message with text content
5
+ */
6
+ export declare function message(options: {
7
+ role: "system" | "assistant" | "user";
8
+ text: string;
9
+ metadata?: Record<string, unknown>;
10
+ providerMetadata?: SharedProviderMetadata;
11
+ }): Message;
12
+ /**
13
+ * Create a reasoning item
14
+ */
15
+ export declare function reasoning(options: {
16
+ text: string;
17
+ providerMetadata?: SharedProviderMetadata;
18
+ }): Reasoning;
19
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/language-model/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAGpD,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAE5C;;GAEG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE;IAC/B,IAAI,EAAE,QAAQ,GAAG,WAAW,GAAG,MAAM,CAAC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,gBAAgB,CAAC,EAAE,sBAAsB,CAAC;CAC3C,GAAG,OAAO,CASV;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,gBAAgB,CAAC,EAAE,sBAAsB,CAAC;CAC3C,GAAG,SAAS,CAOZ"}
@@ -0,0 +1,25 @@
1
+ import { randomID } from "@kernl-sdk/shared/lib";
2
+ /**
3
+ * Create a message with text content
4
+ */
5
+ export function message(options) {
6
+ return {
7
+ kind: "message",
8
+ role: options.role,
9
+ id: `msg_${randomID()}`,
10
+ content: [{ kind: "text", text: options.text }],
11
+ providerMetadata: options.providerMetadata,
12
+ metadata: options.metadata,
13
+ };
14
+ }
15
+ /**
16
+ * Create a reasoning item
17
+ */
18
+ export function reasoning(options) {
19
+ return {
20
+ kind: "reasoning",
21
+ id: `rsn_${randomID()}`,
22
+ text: options.text,
23
+ providerMetadata: options.providerMetadata,
24
+ };
25
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kernl-sdk/protocol",
3
- "version": "0.1.1",
4
- "description": "Kernl Provider Protocol - Standard interfaces for AI model providers",
3
+ "version": "0.2.0",
4
+ "description": "Protocol specification for kernl",
5
5
  "keywords": [
6
6
  "kernl",
7
7
  "protocol",
@@ -26,6 +26,9 @@
26
26
  "import": "./dist/index.js"
27
27
  }
28
28
  },
29
+ "dependencies": {
30
+ "@kernl-sdk/shared": "0.1.1"
31
+ },
29
32
  "devDependencies": {
30
33
  "@types/json-schema": "^7.0.15",
31
34
  "@types/node": "^24.10.0",
package/src/codec.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Bidirectional codec for converting between Kernl protocol types and provider-specific types.
2
+ * Bidirectional codec for converting between kernl protocol types and provider-specific types.
3
3
  *
4
4
  * @example
5
5
  * ```typescript
@@ -11,12 +11,12 @@
11
11
  */
12
12
  export interface Codec<TKernl, TProvider> {
13
13
  /**
14
- * Transform from Kernl protocol format to provider format.
14
+ * Transform from kernl protocol format to provider format.
15
15
  */
16
16
  encode: (value: TKernl) => TProvider;
17
17
 
18
18
  /**
19
- * Transform from provider format to Kernl protocol format.
19
+ * Transform from provider format to kernl protocol format.
20
20
  */
21
21
  decode: (value: TProvider) => TKernl;
22
22
  }
package/src/constants.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Protocol Constants
3
3
  *
4
- * Centralized constants for the Kernl protocol.
4
+ * Centralized constants for the kernl protocol.
5
5
  */
6
6
 
7
7
  // ----------------------------
@@ -11,5 +11,65 @@
11
11
  export const IN_PROGRESS = "in_progress";
12
12
  export const COMPLETED = "completed";
13
13
  export const FAILED = "failed";
14
+
15
+ // ----------------------------
16
+ // Thread/Task states
17
+ // ----------------------------
18
+
19
+ /**
20
+ * Task is either:
21
+ * - Currently executing
22
+ * - In run queue waiting to be scheduled (might want to differentiate between running + queued here)
23
+ */
24
+ export const RUNNING = "running";
25
+
26
+ /**
27
+ * Task is sleeping/blocked, waiting for a condition.
28
+ * Can be woken up by:
29
+ * - The condition being met (e.g., approval granted)
30
+ * - A signal (e.g., user cancellation)
31
+ *
32
+ * Examples:
33
+ * - Waiting for tool approval
34
+ * - Waiting for user input
35
+ * - Sleeping on a timer
36
+ */
14
37
  export const INTERRUPTIBLE = "interruptible";
38
+
39
+ /**
40
+ * Task is sleeping/blocked and CANNOT be interrupted by signals.
41
+ * Only wakes when the condition is met.
42
+ *
43
+ * Examples:
44
+ * - Waiting for critical I/O (model API call)
45
+ * - Waiting for resource that MUST complete
46
+ *
47
+ * Use sparingly - these tasks can't be cancelled!
48
+ */
15
49
  export const UNINTERRUPTIBLE = "uninterruptible";
50
+
51
+ /**
52
+ * Task has been stopped by a signal (SIGSTOP).
53
+ * Will remain stopped until explicitly continued (SIGCONT).
54
+ *
55
+ * Examples:
56
+ * - User explicitly paused the agent
57
+ * - Debugger attached
58
+ */
59
+ export const STOPPED = "stopped";
60
+
61
+ /**
62
+ * Task has finished execution but hasn't been cleaned up yet.
63
+ * Waiting for parent to read exit status (wait/waitpid).
64
+ *
65
+ * Examples:
66
+ * - Agent completed but result not yet retrieved
67
+ * - Child agent finished, parent needs to collect result
68
+ */
69
+ export const ZOMBIE = "zombie";
70
+
71
+ /**
72
+ * Task is being removed from the system.
73
+ * Final cleanup in progress, about to be fully deleted.
74
+ */
75
+ export const DEAD = "dead";
package/src/index.ts CHANGED
@@ -1,20 +1,11 @@
1
1
  /**
2
- * Kernl Provider Protocol
2
+ * kernl Provider Protocol
3
3
  *
4
4
  * Standard interfaces and types for AI model providers.
5
5
  */
6
6
 
7
- // Constants
8
7
  export * from "./constants";
9
-
10
- // Language Model Protocol
11
8
  export * from "./language-model";
12
-
13
- // Embedding Model Protocol
14
9
  export * from "./embedding-model";
15
-
16
- // Provider Base Types
17
10
  export * from "./provider";
18
-
19
- // Codec Interface
20
11
  export * from "./codec";
@@ -3,3 +3,4 @@ export * from "./model";
3
3
  export * from "./request";
4
4
  export * from "./stream";
5
5
  export * from "./tool";
6
+ export * from "./utils";
@@ -8,12 +8,7 @@ import {
8
8
  UNINTERRUPTIBLE,
9
9
  } from "@/constants";
10
10
 
11
- export type LanguageModelItem =
12
- | Message
13
- | Reasoning
14
- | ToolCall
15
- | ToolResult
16
- | Unknown;
11
+ export type LanguageModelItem = Message | Reasoning | ToolCall | ToolResult;
17
12
 
18
13
  /**
19
14
  * A subset of LanguageModelItem that excludes items that wouldn't
@@ -23,7 +18,7 @@ export type LanguageModelResponseItem =
23
18
  | AssistantMessage
24
19
  | Reasoning
25
20
  | ToolCall
26
- | Unknown;
21
+ | ToolResult;
27
22
 
28
23
  export interface SharedBase {
29
24
  /**
@@ -118,19 +113,6 @@ export interface Reasoning extends LanguageModelItemBase {
118
113
  text: string;
119
114
  }
120
115
 
121
- /**
122
- * This is a catch all for events that are not part of the protocol.
123
- *
124
- * For example, a model might return an event that is not part of the protocol using this type.
125
- *
126
- * In that case everything returned from the model should be passed in the `providerMetadata` field.
127
- *
128
- * This enables new features to be added to be added by a model provider without breaking the protocol.
129
- */
130
- export interface Unknown extends LanguageModelItemBase {
131
- readonly kind: "unknown";
132
- }
133
-
134
116
  // ----------------------------
135
117
  // Message types
136
118
  // ----------------------------
@@ -5,23 +5,25 @@ import type {
5
5
  LanguageModelUsage,
6
6
  LanguageModelWarning,
7
7
  } from "./model";
8
- import type { ToolCallState } from "./item";
8
+ import type { Message, Reasoning, ToolCall, ToolResult } from "./item";
9
9
 
10
10
  /**
11
- * Union of all possible language model stream events.
11
+ * Union of all language model stream events.
12
12
  */
13
13
  export type LanguageModelStreamEvent =
14
14
  | TextStartEvent
15
- | TextEndEvent
16
15
  | TextDeltaEvent
16
+ | TextEndEvent
17
+ | Message
17
18
  | ReasoningStartEvent
18
- | ReasoningEndEvent
19
19
  | ReasoningDeltaEvent
20
+ | ReasoningEndEvent
21
+ | Reasoning
20
22
  | ToolInputStartEvent
21
23
  | ToolInputEndEvent
22
24
  | ToolInputDeltaEvent
23
- | ToolCallEvent
24
- | ToolResultEvent
25
+ | ToolCall
26
+ | ToolResult
25
27
  | StartEvent
26
28
  | FinishEvent
27
29
  | AbortEvent
@@ -140,56 +142,6 @@ export interface ToolInputDeltaEvent extends StreamEventBase {
140
142
  delta: string;
141
143
  }
142
144
 
143
- /**
144
- * Stream event containing a complete tool call.
145
- */
146
- export interface ToolCallEvent extends StreamEventBase {
147
- readonly kind: "tool-call";
148
- id: string;
149
-
150
- /**
151
- * The name of the tool being called.
152
- */
153
- toolName: string;
154
-
155
- /**
156
- * The arguments for the tool call as a JSON string.
157
- */
158
- arguments: string;
159
- }
160
-
161
- /**
162
- * Stream event containing a tool result from a provider-executed tool.
163
- */
164
- export interface ToolResultEvent extends StreamEventBase {
165
- readonly kind: "tool-result";
166
-
167
- /**
168
- * The ID of the tool call that this result is associated with.
169
- */
170
- callId: string;
171
-
172
- /**
173
- * Name of the tool that generated this result.
174
- */
175
- toolId: string;
176
-
177
- /**
178
- * The state of the tool call.
179
- */
180
- state: ToolCallState;
181
-
182
- /**
183
- * Result of the tool call. This is a JSON-serializable value.
184
- */
185
- result: unknown;
186
-
187
- /**
188
- * Error message if the tool call failed.
189
- */
190
- error: string | null;
191
- }
192
-
193
145
  /**
194
146
  * Stream event indicating the start of agent execution.
195
147
  */
@@ -0,0 +1,38 @@
1
+ import { SharedProviderMetadata } from "@/provider";
2
+
3
+ import { randomID } from "@kernl-sdk/shared/lib";
4
+ import { Message, Reasoning } from "./item";
5
+
6
+ /**
7
+ * Create a message with text content
8
+ */
9
+ export function message(options: {
10
+ role: "system" | "assistant" | "user";
11
+ text: string;
12
+ metadata?: Record<string, unknown>;
13
+ providerMetadata?: SharedProviderMetadata;
14
+ }): Message {
15
+ return {
16
+ kind: "message",
17
+ role: options.role,
18
+ id: `msg_${randomID()}`,
19
+ content: [{ kind: "text", text: options.text }],
20
+ providerMetadata: options.providerMetadata,
21
+ metadata: options.metadata,
22
+ };
23
+ }
24
+
25
+ /**
26
+ * Create a reasoning item
27
+ */
28
+ export function reasoning(options: {
29
+ text: string;
30
+ providerMetadata?: SharedProviderMetadata;
31
+ }): Reasoning {
32
+ return {
33
+ kind: "reasoning",
34
+ id: `rsn_${randomID()}`,
35
+ text: options.text,
36
+ providerMetadata: options.providerMetadata,
37
+ };
38
+ }