@jambonz/llm 0.1.0 → 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.
- package/dist/index.cjs +92 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +92 -0
- package/dist/index.js.map +1 -1
- package/dist/test-kit/index.cjs +142 -22
- package/dist/test-kit/index.cjs.map +1 -1
- package/dist/test-kit/index.d.cts +2 -14
- package/dist/test-kit/index.d.ts +2 -14
- package/dist/test-kit/index.js +142 -22
- package/dist/test-kit/index.js.map +1 -1
- package/dist/{types-D8rgMCbi.d.cts → types-bq1XMi_T.d.cts} +23 -4
- package/dist/{types-D8rgMCbi.d.ts → types-bq1XMi_T.d.ts} +23 -4
- package/package.json +1 -1
|
@@ -93,6 +93,10 @@ type LlmEvent = {
|
|
|
93
93
|
usage?: Usage;
|
|
94
94
|
rawReason?: string;
|
|
95
95
|
};
|
|
96
|
+
/** Convenience alias for the fully-accumulated tool-call event shape. */
|
|
97
|
+
type ToolCallEvent = Extract<LlmEvent, {
|
|
98
|
+
type: 'toolCall';
|
|
99
|
+
}>;
|
|
96
100
|
type FinishReason = 'stop' | 'tool' | 'length' | 'filtered' | 'error' | 'aborted';
|
|
97
101
|
interface Usage {
|
|
98
102
|
inputTokens?: number;
|
|
@@ -211,8 +215,9 @@ interface FormField {
|
|
|
211
215
|
* 1. Declares which auth kinds it accepts (`acceptedAuth`).
|
|
212
216
|
* 2. Initializes a client from an `AuthSpec` (`init`).
|
|
213
217
|
* 3. Streams a prompt as an AsyncIterable of `LlmEvent`s (`stream`).
|
|
214
|
-
* 4. Appends
|
|
215
|
-
* 5.
|
|
218
|
+
* 4. Appends an assistant-with-tool-call turn to history (`appendAssistantToolCall`).
|
|
219
|
+
* 5. Appends a tool result to history in the vendor's native shape (`appendToolResult`).
|
|
220
|
+
* 6. Lists models accessible to the credential (`listAvailableModels`).
|
|
216
221
|
*
|
|
217
222
|
* The `manifest` is exported as a module-level constant alongside the adapter.
|
|
218
223
|
* See src/adapters/_template/ for a working skeleton.
|
|
@@ -235,10 +240,24 @@ interface LlmAdapter<A extends AuthSpec = AuthSpec> {
|
|
|
235
240
|
* and do not emit any pending `toolCall` events.
|
|
236
241
|
*/
|
|
237
242
|
stream(req: PromptRequest): AsyncIterable<LlmEvent>;
|
|
243
|
+
/**
|
|
244
|
+
* Append an assistant turn containing one or more tool calls to history,
|
|
245
|
+
* in the vendor's native shape. Stateful callers use this after `stream()`
|
|
246
|
+
* yields `toolCall` events to build the assistant turn that must precede
|
|
247
|
+
* the tool-result messages on the next `stream()` call.
|
|
248
|
+
*
|
|
249
|
+
* Vendors encode this turn differently (OpenAI: `{role:'assistant',
|
|
250
|
+
* content:null, tool_calls:[...]}`; Anthropic: `{role:'assistant',
|
|
251
|
+
* content:[{type:'tool_use',...}]}`; Google: `{role:'model',
|
|
252
|
+
* parts:[{functionCall,...}]}`; etc.). The returned `Message` carries the
|
|
253
|
+
* wire shape in `vendorRaw` and is round-trippable through `stream()`.
|
|
254
|
+
*/
|
|
255
|
+
appendAssistantToolCall(history: Message[], toolCalls: ReadonlyArray<ToolCallEvent>): Message[];
|
|
238
256
|
/**
|
|
239
257
|
* Append a tool-result message to history in the vendor's native shape.
|
|
240
258
|
* The returned array MUST be a valid `messages` input for a subsequent `stream()` call
|
|
241
|
-
* on the same adapter.
|
|
259
|
+
* on the same adapter. Callers MUST have already appended the preceding
|
|
260
|
+
* assistant-with-tool-call turn via `appendAssistantToolCall`.
|
|
242
261
|
*/
|
|
243
262
|
appendToolResult(history: Message[], toolCallId: string, result: unknown): Message[];
|
|
244
263
|
/**
|
|
@@ -277,4 +296,4 @@ interface CreateLlmArgs<A extends AuthSpec = AuthSpec> {
|
|
|
277
296
|
client?: ClientOptions;
|
|
278
297
|
}
|
|
279
298
|
|
|
280
|
-
export type { AuthSpec as A, BedrockApiKeyAuth as B, CreateLlmArgs as C, FinishReason as F, GoogleApiKeyAuth as G, JsonSchema as J, LlmAdapter as L, Message as M, PromptRequest as P, Role as R, ServiceAccountJson as S, Tool as T, Usage as U, VertexServiceAccountAuth as V, AdapterFactory as a, AdapterManifest as b, ApiKeyAuth as c, AuthKind as d, AuthKindSchema as e, BedrockIamAuth as f, ClientOptions as g, ContentBlock as h, FormField as i, FormFieldType as j, GoogleServiceAccountAuth as k, LlmEvent as l, ModelCapabilities as m, ModelInfo as n };
|
|
299
|
+
export type { AuthSpec as A, BedrockApiKeyAuth as B, CreateLlmArgs as C, FinishReason as F, GoogleApiKeyAuth as G, JsonSchema as J, LlmAdapter as L, Message as M, PromptRequest as P, Role as R, ServiceAccountJson as S, Tool as T, Usage as U, VertexServiceAccountAuth as V, AdapterFactory as a, AdapterManifest as b, ApiKeyAuth as c, AuthKind as d, AuthKindSchema as e, BedrockIamAuth as f, ClientOptions as g, ContentBlock as h, FormField as i, FormFieldType as j, GoogleServiceAccountAuth as k, LlmEvent as l, ModelCapabilities as m, ModelInfo as n, ToolCallEvent as o };
|
|
@@ -93,6 +93,10 @@ type LlmEvent = {
|
|
|
93
93
|
usage?: Usage;
|
|
94
94
|
rawReason?: string;
|
|
95
95
|
};
|
|
96
|
+
/** Convenience alias for the fully-accumulated tool-call event shape. */
|
|
97
|
+
type ToolCallEvent = Extract<LlmEvent, {
|
|
98
|
+
type: 'toolCall';
|
|
99
|
+
}>;
|
|
96
100
|
type FinishReason = 'stop' | 'tool' | 'length' | 'filtered' | 'error' | 'aborted';
|
|
97
101
|
interface Usage {
|
|
98
102
|
inputTokens?: number;
|
|
@@ -211,8 +215,9 @@ interface FormField {
|
|
|
211
215
|
* 1. Declares which auth kinds it accepts (`acceptedAuth`).
|
|
212
216
|
* 2. Initializes a client from an `AuthSpec` (`init`).
|
|
213
217
|
* 3. Streams a prompt as an AsyncIterable of `LlmEvent`s (`stream`).
|
|
214
|
-
* 4. Appends
|
|
215
|
-
* 5.
|
|
218
|
+
* 4. Appends an assistant-with-tool-call turn to history (`appendAssistantToolCall`).
|
|
219
|
+
* 5. Appends a tool result to history in the vendor's native shape (`appendToolResult`).
|
|
220
|
+
* 6. Lists models accessible to the credential (`listAvailableModels`).
|
|
216
221
|
*
|
|
217
222
|
* The `manifest` is exported as a module-level constant alongside the adapter.
|
|
218
223
|
* See src/adapters/_template/ for a working skeleton.
|
|
@@ -235,10 +240,24 @@ interface LlmAdapter<A extends AuthSpec = AuthSpec> {
|
|
|
235
240
|
* and do not emit any pending `toolCall` events.
|
|
236
241
|
*/
|
|
237
242
|
stream(req: PromptRequest): AsyncIterable<LlmEvent>;
|
|
243
|
+
/**
|
|
244
|
+
* Append an assistant turn containing one or more tool calls to history,
|
|
245
|
+
* in the vendor's native shape. Stateful callers use this after `stream()`
|
|
246
|
+
* yields `toolCall` events to build the assistant turn that must precede
|
|
247
|
+
* the tool-result messages on the next `stream()` call.
|
|
248
|
+
*
|
|
249
|
+
* Vendors encode this turn differently (OpenAI: `{role:'assistant',
|
|
250
|
+
* content:null, tool_calls:[...]}`; Anthropic: `{role:'assistant',
|
|
251
|
+
* content:[{type:'tool_use',...}]}`; Google: `{role:'model',
|
|
252
|
+
* parts:[{functionCall,...}]}`; etc.). The returned `Message` carries the
|
|
253
|
+
* wire shape in `vendorRaw` and is round-trippable through `stream()`.
|
|
254
|
+
*/
|
|
255
|
+
appendAssistantToolCall(history: Message[], toolCalls: ReadonlyArray<ToolCallEvent>): Message[];
|
|
238
256
|
/**
|
|
239
257
|
* Append a tool-result message to history in the vendor's native shape.
|
|
240
258
|
* The returned array MUST be a valid `messages` input for a subsequent `stream()` call
|
|
241
|
-
* on the same adapter.
|
|
259
|
+
* on the same adapter. Callers MUST have already appended the preceding
|
|
260
|
+
* assistant-with-tool-call turn via `appendAssistantToolCall`.
|
|
242
261
|
*/
|
|
243
262
|
appendToolResult(history: Message[], toolCallId: string, result: unknown): Message[];
|
|
244
263
|
/**
|
|
@@ -277,4 +296,4 @@ interface CreateLlmArgs<A extends AuthSpec = AuthSpec> {
|
|
|
277
296
|
client?: ClientOptions;
|
|
278
297
|
}
|
|
279
298
|
|
|
280
|
-
export type { AuthSpec as A, BedrockApiKeyAuth as B, CreateLlmArgs as C, FinishReason as F, GoogleApiKeyAuth as G, JsonSchema as J, LlmAdapter as L, Message as M, PromptRequest as P, Role as R, ServiceAccountJson as S, Tool as T, Usage as U, VertexServiceAccountAuth as V, AdapterFactory as a, AdapterManifest as b, ApiKeyAuth as c, AuthKind as d, AuthKindSchema as e, BedrockIamAuth as f, ClientOptions as g, ContentBlock as h, FormField as i, FormFieldType as j, GoogleServiceAccountAuth as k, LlmEvent as l, ModelCapabilities as m, ModelInfo as n };
|
|
299
|
+
export type { AuthSpec as A, BedrockApiKeyAuth as B, CreateLlmArgs as C, FinishReason as F, GoogleApiKeyAuth as G, JsonSchema as J, LlmAdapter as L, Message as M, PromptRequest as P, Role as R, ServiceAccountJson as S, Tool as T, Usage as U, VertexServiceAccountAuth as V, AdapterFactory as a, AdapterManifest as b, ApiKeyAuth as c, AuthKind as d, AuthKindSchema as e, BedrockIamAuth as f, ClientOptions as g, ContentBlock as h, FormField as i, FormFieldType as j, GoogleServiceAccountAuth as k, LlmEvent as l, ModelCapabilities as m, ModelInfo as n, ToolCallEvent as o };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jambonz/llm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Voice-oriented LLM adapter library — a uniform interface for streaming chat completions from multiple LLM vendors, with first-class support for tool calls, AbortSignal interruption, and lossless history round-tripping.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|