@kernl-sdk/protocol 0.1.1

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.
Files changed (81) hide show
  1. package/.turbo/turbo-build.log +4 -0
  2. package/CHANGELOG.md +7 -0
  3. package/LICENSE +201 -0
  4. package/README.md +1 -0
  5. package/dist/codec.d.ts +22 -0
  6. package/dist/codec.d.ts.map +1 -0
  7. package/dist/codec.js +1 -0
  8. package/dist/constants.d.ts +11 -0
  9. package/dist/constants.d.ts.map +1 -0
  10. package/dist/constants.js +13 -0
  11. package/dist/embedding-model/embedding-model.d.ts +57 -0
  12. package/dist/embedding-model/embedding-model.d.ts.map +1 -0
  13. package/dist/embedding-model/embedding-model.js +6 -0
  14. package/dist/embedding-model/index.d.ts +3 -0
  15. package/dist/embedding-model/index.d.ts.map +1 -0
  16. package/dist/embedding-model/index.js +2 -0
  17. package/dist/embedding-model/model.d.ts +65 -0
  18. package/dist/embedding-model/model.d.ts.map +1 -0
  19. package/dist/embedding-model/model.js +1 -0
  20. package/dist/embedding-model/request.d.ts +27 -0
  21. package/dist/embedding-model/request.d.ts.map +1 -0
  22. package/dist/embedding-model/request.js +1 -0
  23. package/dist/index.d.ts +11 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +15 -0
  26. package/dist/json.d.ts +10 -0
  27. package/dist/json.d.ts.map +1 -0
  28. package/dist/json.js +1 -0
  29. package/dist/language-model/content.d.ts +141 -0
  30. package/dist/language-model/content.d.ts.map +1 -0
  31. package/dist/language-model/content.js +1 -0
  32. package/dist/language-model/index.d.ts +6 -0
  33. package/dist/language-model/index.d.ts.map +1 -0
  34. package/dist/language-model/index.js +5 -0
  35. package/dist/language-model/item.d.ts +183 -0
  36. package/dist/language-model/item.d.ts.map +1 -0
  37. package/dist/language-model/item.js +1 -0
  38. package/dist/language-model/language-model.d.ts +114 -0
  39. package/dist/language-model/language-model.d.ts.map +1 -0
  40. package/dist/language-model/language-model.js +1 -0
  41. package/dist/language-model/model.d.ts +110 -0
  42. package/dist/language-model/model.d.ts.map +1 -0
  43. package/dist/language-model/model.js +1 -0
  44. package/dist/language-model/request.d.ts +175 -0
  45. package/dist/language-model/request.d.ts.map +1 -0
  46. package/dist/language-model/request.js +1 -0
  47. package/dist/language-model/settings.d.ts +99 -0
  48. package/dist/language-model/settings.d.ts.map +1 -0
  49. package/dist/language-model/settings.js +1 -0
  50. package/dist/language-model/stream.d.ts +195 -0
  51. package/dist/language-model/stream.d.ts.map +1 -0
  52. package/dist/language-model/stream.js +1 -0
  53. package/dist/language-model/tool.d.ts +48 -0
  54. package/dist/language-model/tool.d.ts.map +1 -0
  55. package/dist/language-model/tool.js +1 -0
  56. package/dist/provider/index.d.ts +2 -0
  57. package/dist/provider/index.d.ts.map +1 -0
  58. package/dist/provider/index.js +1 -0
  59. package/dist/provider/metadata.d.ts +21 -0
  60. package/dist/provider/metadata.d.ts.map +1 -0
  61. package/dist/provider/metadata.js +1 -0
  62. package/dist/provider/provider.d.ts +42 -0
  63. package/dist/provider/provider.d.ts.map +1 -0
  64. package/dist/provider/provider.js +1 -0
  65. package/package.json +41 -0
  66. package/src/codec.ts +22 -0
  67. package/src/constants.ts +15 -0
  68. package/src/embedding-model/index.ts +2 -0
  69. package/src/embedding-model/model.ts +76 -0
  70. package/src/embedding-model/request.ts +31 -0
  71. package/src/index.ts +20 -0
  72. package/src/json.ts +17 -0
  73. package/src/language-model/index.ts +5 -0
  74. package/src/language-model/item.ts +251 -0
  75. package/src/language-model/model.ts +161 -0
  76. package/src/language-model/request.ts +210 -0
  77. package/src/language-model/stream.ts +251 -0
  78. package/src/language-model/tool.ts +56 -0
  79. package/src/provider/index.ts +1 -0
  80. package/src/provider/provider.ts +79 -0
  81. package/tsconfig.json +13 -0
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Settings to use when calling an LLM.
3
+ *
4
+ * This class holds optional model configuration parameters (e.g. temperature,
5
+ * topP, penalties, truncation, etc.).
6
+ *
7
+ * Not all models/providers support all of these parameters, so please check the API documentation
8
+ * for the specific model and provider you are using.
9
+ */
10
+ export interface LanguageModelSettings {
11
+ /**
12
+ * The temperature to use when calling the model.
13
+ */
14
+ temperature?: number;
15
+ /**
16
+ * The topP to use when calling the model.
17
+ */
18
+ topP?: number;
19
+ /**
20
+ * The frequency penalty to use when calling the model.
21
+ */
22
+ frequencyPenalty?: number;
23
+ /**
24
+ * The presence penalty to use when calling the model.
25
+ */
26
+ presencePenalty?: number;
27
+ /**
28
+ * The tool choice to use when calling the model.
29
+ */
30
+ toolChoice?: ModelSettingsToolChoice;
31
+ /**
32
+ * Whether to use parallel tool calls when calling the model.
33
+ * Defaults to false if not provided.
34
+ */
35
+ parallelToolCalls?: boolean;
36
+ /**
37
+ * The truncation strategy to use when calling the model.
38
+ */
39
+ truncation?: "auto" | "disabled";
40
+ /**
41
+ * The maximum number of output tokens to generate.
42
+ */
43
+ maxTokens?: number;
44
+ /**
45
+ * Whether to store the generated model response for later retrieval.
46
+ * Defaults to true if not provided.
47
+ */
48
+ store?: boolean;
49
+ /**
50
+ * The reasoning settings to use when calling the model.
51
+ */
52
+ reasoning?: ModelSettingsReasoning;
53
+ /**
54
+ * The text settings to use when calling the model.
55
+ */
56
+ text?: ModelSettingsText;
57
+ /**
58
+ * Additional provider specific settings to be passed directly to the model
59
+ * request.
60
+ */
61
+ providerData?: Record<string, any>;
62
+ }
63
+ export type ModelSettingsToolChoice = "auto" | "required" | "none";
64
+ /**
65
+ * Constrains effort on reasoning for [reasoning models](https://platform.openai.com/docs/guides/reasoning).
66
+ *
67
+ * Supported for providers:
68
+ *
69
+ * - OpenAI
70
+ * - ... ?
71
+ */
72
+ export type ModelSettingsReasoningEffort = "minimal" | "low" | "medium" | "high" | null;
73
+ /**
74
+ * Configuration options for model reasoning
75
+ */
76
+ export type ModelSettingsReasoning = {
77
+ /**
78
+ * Constrains effort on reasoning for [reasoning models](https://platform.openai.com/docs/guides/reasoning).
79
+ */
80
+ effort?: ModelSettingsReasoningEffort | null;
81
+ /**
82
+ * A summary of the reasoning performed by the model.
83
+ * This can be useful for debugging and understanding the model's reasoning process.
84
+ * One of `auto`, `concise`, or `detailed`.
85
+ */
86
+ summary?: "auto" | "concise" | "detailed" | null;
87
+ };
88
+ export interface ModelSettingsText {
89
+ /**
90
+ * Constrains the verbosity of the model's response.
91
+ *
92
+ * Supported for providers:
93
+ *
94
+ * - OpenAI
95
+ * - ... ?
96
+ */
97
+ verbosity?: "low" | "medium" | "high" | null;
98
+ }
99
+ //# sourceMappingURL=settings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../../src/language-model/settings.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,UAAU,CAAC,EAAE,uBAAuB,CAAC;IAErC;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAE5B;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;IAEjC;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;OAEG;IACH,SAAS,CAAC,EAAE,sBAAsB,CAAC;IAEnC;;OAEG;IACH,IAAI,CAAC,EAAE,iBAAiB,CAAC;IAEzB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACpC;AAED,MAAM,MAAM,uBAAuB,GAAG,MAAM,GAAG,UAAU,GAAG,MAAM,CAAC;AAEnE;;;;;;;GAOG;AACH,MAAM,MAAM,4BAA4B,GACpC,SAAS,GACT,KAAK,GACL,QAAQ,GACR,MAAM,GACN,IAAI,CAAC;AAET;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC;;OAEG;IACH,MAAM,CAAC,EAAE,4BAA4B,GAAG,IAAI,CAAC;IAE7C;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,UAAU,GAAG,IAAI,CAAC;CAClD,CAAC;AAEF,MAAM,WAAW,iBAAiB;IAChC;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,IAAI,CAAC;CAC9C"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,195 @@
1
+ import { SharedProviderMetadata } from "../provider";
2
+ import type { LanguageModelFinishReason, LanguageModelUsage, LanguageModelWarning } from "./model";
3
+ import type { ToolCallState } from "./item";
4
+ /**
5
+ * Union of all possible language model stream events.
6
+ */
7
+ export type LanguageModelStreamEvent = TextStartEvent | TextEndEvent | TextDeltaEvent | ReasoningStartEvent | ReasoningEndEvent | ReasoningDeltaEvent | ToolInputStartEvent | ToolInputEndEvent | ToolInputDeltaEvent | ToolCallEvent | ToolResultEvent | StartEvent | FinishEvent | AbortEvent | ErrorEvent | RawEvent;
8
+ /**
9
+ * Base interface for all stream events.
10
+ */
11
+ export interface StreamEventBase {
12
+ /**
13
+ * The ID associated with this stream event.
14
+ */
15
+ id?: string;
16
+ /**
17
+ * Additional provider-specific metadata for the event.
18
+ */
19
+ providerMetadata?: SharedProviderMetadata;
20
+ }
21
+ /**
22
+ * Stream event indicating the start of a text output.
23
+ */
24
+ export interface TextStartEvent extends StreamEventBase {
25
+ readonly kind: "text-start";
26
+ id: string;
27
+ }
28
+ /**
29
+ * Stream event indicating the end of a text output.
30
+ */
31
+ export interface TextEndEvent extends StreamEventBase {
32
+ readonly kind: "text-end";
33
+ id: string;
34
+ }
35
+ /**
36
+ * Stream event containing a delta (chunk) of text output.
37
+ */
38
+ export interface TextDeltaEvent extends StreamEventBase {
39
+ readonly kind: "text-delta";
40
+ id: string;
41
+ /**
42
+ * The incremental text chunk.
43
+ */
44
+ text: string;
45
+ }
46
+ /**
47
+ * Stream event indicating the start of reasoning output.
48
+ */
49
+ export interface ReasoningStartEvent extends StreamEventBase {
50
+ readonly kind: "reasoning-start";
51
+ id: string;
52
+ }
53
+ /**
54
+ * Stream event indicating the end of reasoning output.
55
+ */
56
+ export interface ReasoningEndEvent extends StreamEventBase {
57
+ readonly kind: "reasoning-end";
58
+ id: string;
59
+ }
60
+ /**
61
+ * Stream event containing a delta (chunk) of reasoning output.
62
+ */
63
+ export interface ReasoningDeltaEvent extends StreamEventBase {
64
+ readonly kind: "reasoning-delta";
65
+ id: string;
66
+ /**
67
+ * The incremental reasoning text chunk.
68
+ */
69
+ text: string;
70
+ }
71
+ /**
72
+ * Stream event indicating the start of tool input generation.
73
+ */
74
+ export interface ToolInputStartEvent extends StreamEventBase {
75
+ readonly kind: "tool-input-start";
76
+ id: string;
77
+ /**
78
+ * The name of the tool being called.
79
+ */
80
+ toolName: string;
81
+ /**
82
+ * Optional title for the tool call.
83
+ */
84
+ title?: string;
85
+ }
86
+ /**
87
+ * Stream event indicating the end of tool input generation.
88
+ */
89
+ export interface ToolInputEndEvent extends StreamEventBase {
90
+ readonly kind: "tool-input-end";
91
+ id: string;
92
+ }
93
+ /**
94
+ * Stream event containing a delta (chunk) of tool input.
95
+ */
96
+ export interface ToolInputDeltaEvent extends StreamEventBase {
97
+ readonly kind: "tool-input-delta";
98
+ id: string;
99
+ /**
100
+ * The incremental tool input chunk.
101
+ */
102
+ delta: string;
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
+ /**
146
+ * Stream event indicating the start of agent execution.
147
+ */
148
+ export interface StartEvent extends StreamEventBase {
149
+ readonly kind: "stream-start";
150
+ /**
151
+ * Warnings for the call (e.g., unsupported settings).
152
+ */
153
+ warnings?: LanguageModelWarning[];
154
+ }
155
+ /**
156
+ * Stream event indicating the completion of agent execution.
157
+ */
158
+ export interface FinishEvent extends StreamEventBase {
159
+ readonly kind: "finish";
160
+ /**
161
+ * The reason for completion.
162
+ */
163
+ finishReason: LanguageModelFinishReason;
164
+ /**
165
+ * Total usage data for the execution.
166
+ */
167
+ usage: LanguageModelUsage;
168
+ }
169
+ /**
170
+ * Stream event indicating the agent execution was aborted.
171
+ */
172
+ export interface AbortEvent extends StreamEventBase {
173
+ readonly kind: "abort";
174
+ }
175
+ /**
176
+ * Stream event indicating an error occurred during execution.
177
+ */
178
+ export interface ErrorEvent extends StreamEventBase {
179
+ readonly kind: "error";
180
+ /**
181
+ * The error that occurred.
182
+ */
183
+ error: unknown;
184
+ }
185
+ /**
186
+ * Stream event containing raw provider-specific data.
187
+ */
188
+ export interface RawEvent extends StreamEventBase {
189
+ readonly kind: "raw";
190
+ /**
191
+ * The raw value from the provider.
192
+ */
193
+ rawValue: unknown;
194
+ }
195
+ //# sourceMappingURL=stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../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,MAAM,EAAE,OAAO,CAAC;IAEhB;;OAEG;IACH,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,UAAW,SAAQ,eAAe;IACjD,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAE9B;;OAEG;IACH,QAAQ,CAAC,EAAE,oBAAoB,EAAE,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,WAAY,SAAQ,eAAe;IAClD,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAExB;;OAEG;IACH,YAAY,EAAE,yBAAyB,CAAC;IAExC;;OAEG;IACH,KAAK,EAAE,kBAAkB,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,UAAW,SAAQ,eAAe;IACjD,QAAQ,CAAC,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 @@
1
+ export {};
@@ -0,0 +1,48 @@
1
+ import type { JSONSchema7 } from "json-schema";
2
+ import type { SharedProviderOptions } from "../provider";
3
+ /**
4
+ * A tool has a name, a description, and a set of parameters.
5
+ *
6
+ * Note: this is **not** the user-facing tool definition. The AI SDK methods will
7
+ * map the user-facing tool definitions to this format.
8
+ */
9
+ export type LanguageModelFunctionTool = {
10
+ readonly kind: "function";
11
+ /**
12
+ * The name of the tool. Unique within this model call.
13
+ */
14
+ name: string;
15
+ /**
16
+ * A description of the tool. The language model uses this to understand the
17
+ * tool's purpose and to provide better completion suggestions.
18
+ */
19
+ description?: string;
20
+ /**
21
+ * The parameters that the tool expects. The language model uses this to
22
+ * understand the tool's input requirements and to provide matching suggestions.
23
+ */
24
+ parameters: JSONSchema7;
25
+ /**
26
+ * The provider-specific options for the tool.
27
+ */
28
+ providerOptions?: SharedProviderOptions;
29
+ };
30
+ /**
31
+ * The configuration of a tool that is defined by the provider.
32
+ */
33
+ export type LanguageModelProviderTool = {
34
+ readonly kind: "provider-defined";
35
+ /**
36
+ * The ID of the tool. Should follow the format `<provider-id>.<unique-tool-name>`.
37
+ */
38
+ id: `${string}.${string}`;
39
+ /**
40
+ * The name of the tool that the user must use in the tool set.
41
+ */
42
+ name: string;
43
+ /**
44
+ * The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
45
+ */
46
+ args: Record<string, unknown>;
47
+ };
48
+ //# sourceMappingURL=tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../src/language-model/tool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAExD;;;;;GAKG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAE1B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,UAAU,EAAE,WAAW,CAAC;IAExB;;OAEG;IACH,eAAe,CAAC,EAAE,qBAAqB,CAAC;CACzC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;IAElC;;OAEG;IACH,EAAE,EAAE,GAAG,MAAM,IAAI,MAAM,EAAE,CAAC;IAE1B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from "./provider";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/provider/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC"}
@@ -0,0 +1 @@
1
+ export * from "./provider";
@@ -0,0 +1,21 @@
1
+ import { JSONObject } from "../json";
2
+ /**
3
+ * Additional provider-specific metadata.
4
+ *
5
+ * They are passed through to the provider from the AI SDK
6
+ * and enable provider-specific functionality
7
+ * that can be fully encapsulated in the provider.
8
+ *
9
+ * The outer record is keyed by the provider name, and the inner
10
+ * record is keyed by the provider-specific metadata key.
11
+ *
12
+ * ```ts
13
+ * {
14
+ * "anthropic": {
15
+ * "cacheControl": { "type": "ephemeral" }
16
+ * }
17
+ * }
18
+ * ```
19
+ */
20
+ export type SharedProviderMetadata = Record<string, JSONObject>;
21
+ //# sourceMappingURL=metadata.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../../src/provider/metadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,42 @@
1
+ import { EmbeddingModel } from "../embedding-model";
2
+ import { LanguageModel } from "../language-model";
3
+ import { JSONObject } from "../json";
4
+ /**
5
+ * Provider for language, text embedding, and image generation models.
6
+ */
7
+ export interface Provider {
8
+ readonly spec: "1.0";
9
+ /**
10
+ * Returns the language model with the given id.
11
+ *
12
+ * @throws {NoSuchModelError} If no such model exists.
13
+ */
14
+ languageModel(modelId: string): LanguageModel;
15
+ /**
16
+ * Returns the text embedding model with the given id.
17
+ *
18
+ * @throws {NoSuchModelError} If no such model exists.
19
+ */
20
+ textEmbeddingModel(modelId: string): EmbeddingModel<string>;
21
+ }
22
+ /**
23
+ * Additional provider-specific metadata.
24
+ *
25
+ * They are passed through to the provider from the AI SDK
26
+ * and enable provider-specific functionality
27
+ * that can be fully encapsulated in the provider.
28
+ *
29
+ * The outer record is keyed by the provider name, and the inner
30
+ * record is keyed by the provider-specific metadata key.
31
+ *
32
+ * ```ts
33
+ * {
34
+ * "anthropic": {
35
+ * "cacheControl": { "type": "ephemeral" }
36
+ * }
37
+ * }
38
+ * ```
39
+ */
40
+ export type SharedProviderMetadata = Record<string, JSONObject>;
41
+ export type SharedProviderOptions = Record<string, JSONObject>;
42
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/provider/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IAErB;;;;OAIG;IACH,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,aAAa,CAAC;IAE9C;;;;OAIG;IACH,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;CAkC7D;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AAEhE,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@kernl-sdk/protocol",
3
+ "version": "0.1.1",
4
+ "description": "Kernl Provider Protocol - Standard interfaces for AI model providers",
5
+ "keywords": [
6
+ "kernl",
7
+ "protocol",
8
+ "ai",
9
+ "llm"
10
+ ],
11
+ "author": "dremnik",
12
+ "license": "MIT",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/dremnik/kernl.git",
16
+ "directory": "packages/protocol"
17
+ },
18
+ "homepage": "https://github.com/dremnik/kernl#readme",
19
+ "bugs": {
20
+ "url": "https://github.com/dremnik/kernl/issues"
21
+ },
22
+ "type": "module",
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/index.d.ts",
26
+ "import": "./dist/index.js"
27
+ }
28
+ },
29
+ "devDependencies": {
30
+ "@types/json-schema": "^7.0.15",
31
+ "@types/node": "^24.10.0",
32
+ "tsc-alias": "^1.8.10",
33
+ "typescript": "5.9.2"
34
+ },
35
+ "scripts": {
36
+ "build": "tsc && tsc-alias",
37
+ "dev": "tsc --watch",
38
+ "lint": "eslint src/",
39
+ "check-types": "tsc --noEmit"
40
+ }
41
+ }
package/src/codec.ts ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Bidirectional codec for converting between Kernl protocol types and provider-specific types.
3
+ *
4
+ * @example
5
+ * ```typescript
6
+ * const tools: Codec<LanguageModelTool[], ProviderTool[]> = {
7
+ * encode: (tools: Tool[]) => tools.map(convertToProvider),
8
+ * decode: () => { throw new Error("codec:unimplemented"); },
9
+ * };
10
+ * ```
11
+ */
12
+ export interface Codec<TKernl, TProvider> {
13
+ /**
14
+ * Transform from Kernl protocol format to provider format.
15
+ */
16
+ encode: (value: TKernl) => TProvider;
17
+
18
+ /**
19
+ * Transform from provider format to Kernl protocol format.
20
+ */
21
+ decode: (value: TProvider) => TKernl;
22
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Protocol Constants
3
+ *
4
+ * Centralized constants for the Kernl protocol.
5
+ */
6
+
7
+ // ----------------------------
8
+ // Tool states
9
+ // ----------------------------
10
+
11
+ export const IN_PROGRESS = "in_progress";
12
+ export const COMPLETED = "completed";
13
+ export const FAILED = "failed";
14
+ export const INTERRUPTIBLE = "interruptible";
15
+ export const UNINTERRUPTIBLE = "uninterruptible";
@@ -0,0 +1,2 @@
1
+ export * from "./model";
2
+ export * from "./request";
@@ -0,0 +1,76 @@
1
+ import { SharedProviderMetadata } from "@/provider";
2
+
3
+ import { EmbeddingModelRequest } from "./request";
4
+
5
+ export type Embedding = number[];
6
+
7
+ /**
8
+ * Embedding model interface.
9
+ *
10
+ * TValue is the type of values that can be embedded.
11
+ * Currently string for text, but could support images, audio, etc. in the future.
12
+ */
13
+ export interface EmbeddingModel<TValue = string> {
14
+ /**
15
+ * The embedding model must specify which embedding model interface version it implements.
16
+ */
17
+ readonly spec: "1.0";
18
+
19
+ /**
20
+ * Provider ID.
21
+ */
22
+ readonly provider: string;
23
+
24
+ /**
25
+ * Provider-specific model ID.
26
+ */
27
+ readonly modelId: string;
28
+
29
+ /**
30
+ * Maximum number of values that can be embedded in a single call.
31
+ * undefined means no limit is known.
32
+ */
33
+ readonly maxEmbeddingsPerCall?: number;
34
+
35
+ /**
36
+ * Whether this model can handle multiple embed calls in parallel.
37
+ */
38
+ readonly supportsParallelCalls?: boolean;
39
+
40
+ /**
41
+ * Generate embeddings for the given input values.
42
+ *
43
+ * @param request - The embedding request.
44
+ */
45
+ embed(request: EmbeddingModelRequest<TValue>): Promise<EmbeddingModelResponse>;
46
+ }
47
+
48
+ /**
49
+ * The response from an embedding model.
50
+ */
51
+ export interface EmbeddingModelResponse {
52
+ /**
53
+ * Generated embeddings in the same order as input values.
54
+ */
55
+ embeddings: Embedding[];
56
+
57
+ /**
58
+ * Token usage for the embedding call.
59
+ */
60
+ usage: EmbeddingModelUsage;
61
+
62
+ /**
63
+ * Provider-specific metadata.
64
+ */
65
+ providerMetadata?: SharedProviderMetadata;
66
+ }
67
+
68
+ /**
69
+ * Usage information for an embedding model call.
70
+ */
71
+ export interface EmbeddingModelUsage {
72
+ /**
73
+ * The number of input tokens used.
74
+ */
75
+ inputTokens: number | undefined;
76
+ }
@@ -0,0 +1,31 @@
1
+ import { SharedProviderOptions } from "@/provider";
2
+
3
+ export interface EmbeddingModelRequest<TValue = string> {
4
+ /**
5
+ * Values to embed.
6
+ */
7
+ values: TValue[];
8
+
9
+ /**
10
+ * Optional settings for the embedding request.
11
+ */
12
+ settings?: EmbeddingModelRequestSettings;
13
+
14
+ /**
15
+ * Abort signal for cancelling the operation.
16
+ */
17
+ abort?: AbortSignal;
18
+ }
19
+
20
+ export interface EmbeddingModelRequestSettings {
21
+ /**
22
+ * Desired dimension of the output embeddings.
23
+ * Not supported by all providers.
24
+ */
25
+ dimensions?: number;
26
+
27
+ /**
28
+ * Additional provider-specific options.
29
+ */
30
+ providerOptions?: SharedProviderOptions;
31
+ }
package/src/index.ts ADDED
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Kernl Provider Protocol
3
+ *
4
+ * Standard interfaces and types for AI model providers.
5
+ */
6
+
7
+ // Constants
8
+ export * from "./constants";
9
+
10
+ // Language Model Protocol
11
+ export * from "./language-model";
12
+
13
+ // Embedding Model Protocol
14
+ export * from "./embedding-model";
15
+
16
+ // Provider Base Types
17
+ export * from "./provider";
18
+
19
+ // Codec Interface
20
+ export * from "./codec";