@acentric/llm 0.0.0-stage → 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.
- package/README.md +128 -2
- package/dist/catalog/anthropic.d.ts +77 -0
- package/dist/catalog/anthropic.d.ts.map +1 -0
- package/dist/catalog/anthropic.js +73 -0
- package/dist/catalog/anthropic.js.map +1 -0
- package/dist/catalog/fireworks.d.ts +93 -0
- package/dist/catalog/fireworks.d.ts.map +1 -0
- package/dist/catalog/fireworks.js +117 -0
- package/dist/catalog/fireworks.js.map +1 -0
- package/dist/catalog/openai.d.ts +103 -0
- package/dist/catalog/openai.d.ts.map +1 -0
- package/dist/catalog/openai.js +102 -0
- package/dist/catalog/openai.js.map +1 -0
- package/dist/client/anthropic/errors.d.ts +4 -0
- package/dist/client/anthropic/errors.d.ts.map +1 -0
- package/dist/client/anthropic/errors.js +80 -0
- package/dist/client/anthropic/errors.js.map +1 -0
- package/dist/client/anthropic/request.d.ts +9 -0
- package/dist/client/anthropic/request.d.ts.map +1 -0
- package/dist/client/anthropic/request.js +232 -0
- package/dist/client/anthropic/request.js.map +1 -0
- package/dist/client/anthropic/response.d.ts +13 -0
- package/dist/client/anthropic/response.d.ts.map +1 -0
- package/dist/client/anthropic/response.js +207 -0
- package/dist/client/anthropic/response.js.map +1 -0
- package/dist/client/direct.d.ts +18 -0
- package/dist/client/direct.d.ts.map +1 -0
- package/dist/client/direct.js +104 -0
- package/dist/client/direct.js.map +1 -0
- package/dist/client/gateway.d.ts +43 -0
- package/dist/client/gateway.d.ts.map +1 -0
- package/dist/client/gateway.js +72 -0
- package/dist/client/gateway.js.map +1 -0
- package/dist/client/http.d.ts +41 -0
- package/dist/client/http.d.ts.map +1 -0
- package/dist/client/http.js +190 -0
- package/dist/client/http.js.map +1 -0
- package/dist/client/llm.d.ts +41 -0
- package/dist/client/llm.d.ts.map +1 -0
- package/dist/client/llm.js +100 -0
- package/dist/client/llm.js.map +1 -0
- package/dist/client/responses/errors.d.ts +13 -0
- package/dist/client/responses/errors.d.ts.map +1 -0
- package/dist/client/responses/errors.js +144 -0
- package/dist/client/responses/errors.js.map +1 -0
- package/dist/client/responses/profile.d.ts +50 -0
- package/dist/client/responses/profile.d.ts.map +1 -0
- package/dist/client/responses/profile.js +4 -0
- package/dist/client/responses/profile.js.map +1 -0
- package/dist/client/responses/providers.d.ts +4 -0
- package/dist/client/responses/providers.d.ts.map +1 -0
- package/dist/client/responses/providers.js +75 -0
- package/dist/client/responses/providers.js.map +1 -0
- package/dist/client/responses/request.d.ts +5 -0
- package/dist/client/responses/request.d.ts.map +1 -0
- package/dist/client/responses/request.js +248 -0
- package/dist/client/responses/request.js.map +1 -0
- package/dist/client/responses/response.d.ts +10 -0
- package/dist/client/responses/response.d.ts.map +1 -0
- package/dist/client/responses/response.js +176 -0
- package/dist/client/responses/response.js.map +1 -0
- package/dist/client/util.d.ts +21 -0
- package/dist/client/util.d.ts.map +1 -0
- package/dist/client/util.js +63 -0
- package/dist/client/util.js.map +1 -0
- package/dist/client.d.ts +9 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +10 -0
- package/dist/client.js.map +1 -0
- package/dist/content.d.ts +38 -0
- package/dist/content.d.ts.map +1 -0
- package/dist/content.js +5 -0
- package/dist/content.js.map +1 -0
- package/dist/convert/anthropic.d.ts +3 -0
- package/dist/convert/anthropic.d.ts.map +1 -0
- package/dist/convert/anthropic.js +114 -0
- package/dist/convert/anthropic.js.map +1 -0
- package/dist/convert/index.d.ts +12 -0
- package/dist/convert/index.d.ts.map +1 -0
- package/dist/convert/index.js +221 -0
- package/dist/convert/index.js.map +1 -0
- package/dist/convert/responses.d.ts +3 -0
- package/dist/convert/responses.d.ts.map +1 -0
- package/dist/convert/responses.js +197 -0
- package/dist/convert/responses.js.map +1 -0
- package/dist/convert/types.d.ts +88 -0
- package/dist/convert/types.d.ts.map +1 -0
- package/dist/convert/types.js +3 -0
- package/dist/convert/types.js.map +1 -0
- package/dist/cost.d.ts +18 -0
- package/dist/cost.d.ts.map +1 -0
- package/dist/cost.js +49 -0
- package/dist/cost.js.map +1 -0
- package/dist/failure.d.ts +90 -0
- package/dist/failure.d.ts.map +1 -0
- package/dist/failure.js +111 -0
- package/dist/failure.js.map +1 -0
- package/dist/fields.d.ts +14 -0
- package/dist/fields.d.ts.map +1 -0
- package/dist/fields.js +3 -0
- package/dist/fields.js.map +1 -0
- package/dist/formats/anthropic.d.ts +152 -0
- package/dist/formats/anthropic.d.ts.map +1 -0
- package/dist/formats/anthropic.js +7 -0
- package/dist/formats/anthropic.js.map +1 -0
- package/dist/formats/responses.d.ts +179 -0
- package/dist/formats/responses.d.ts.map +1 -0
- package/dist/formats/responses.js +9 -0
- package/dist/formats/responses.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/json.d.ts +6 -0
- package/dist/json.d.ts.map +1 -0
- package/dist/json.js +10 -0
- package/dist/json.js.map +1 -0
- package/dist/messages.d.ts +82 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +4 -0
- package/dist/messages.js.map +1 -0
- package/dist/model.d.ts +36 -0
- package/dist/model.d.ts.map +1 -0
- package/dist/model.js +4 -0
- package/dist/model.js.map +1 -0
- package/dist/models.d.ts +9 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +19 -0
- package/dist/models.js.map +1 -0
- package/dist/providers/anthropic.d.ts +130 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +5 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/fireworks.d.ts +108 -0
- package/dist/providers/fireworks.d.ts.map +1 -0
- package/dist/providers/fireworks.js +6 -0
- package/dist/providers/fireworks.js.map +1 -0
- package/dist/providers/openai.d.ts +193 -0
- package/dist/providers/openai.d.ts.map +1 -0
- package/dist/providers/openai.js +4 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/providers.d.ts +50 -0
- package/dist/providers.d.ts.map +1 -0
- package/dist/providers.js +5 -0
- package/dist/providers.js.map +1 -0
- package/dist/read/anthropic.d.ts +15 -0
- package/dist/read/anthropic.d.ts.map +1 -0
- package/dist/read/anthropic.js +56 -0
- package/dist/read/anthropic.js.map +1 -0
- package/dist/read/responses.d.ts +26 -0
- package/dist/read/responses.d.ts.map +1 -0
- package/dist/read/responses.js +121 -0
- package/dist/read/responses.js.map +1 -0
- package/dist/read.d.ts +32 -0
- package/dist/read.d.ts.map +1 -0
- package/dist/read.js +73 -0
- package/dist/read.js.map +1 -0
- package/dist/request.d.ts +23 -0
- package/dist/request.d.ts.map +1 -0
- package/dist/request.js +4 -0
- package/dist/request.js.map +1 -0
- package/dist/response.d.ts +38 -0
- package/dist/response.d.ts.map +1 -0
- package/dist/response.js +4 -0
- package/dist/response.js.map +1 -0
- package/dist/secrets.d.ts +22 -0
- package/dist/secrets.d.ts.map +1 -0
- package/dist/secrets.js +35 -0
- package/dist/secrets.js.map +1 -0
- package/dist/tool-calls.d.ts +28 -0
- package/dist/tool-calls.d.ts.map +1 -0
- package/dist/tool-calls.js +4 -0
- package/dist/tool-calls.js.map +1 -0
- package/dist/tools.d.ts +33 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +4 -0
- package/dist/tools.js.map +1 -0
- package/dist/usage.d.ts +31 -0
- package/dist/usage.d.ts.map +1 -0
- package/dist/usage.js +3 -0
- package/dist/usage.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +6 -0
- package/dist/version.js.map +1 -0
- package/package.json +33 -3
- package/src/catalog/anthropic.ts +83 -0
- package/src/catalog/fireworks.ts +121 -0
- package/src/catalog/openai.ts +133 -0
- package/src/client/anthropic/errors.ts +88 -0
- package/src/client/anthropic/request.ts +272 -0
- package/src/client/anthropic/response.ts +236 -0
- package/src/client/direct.ts +157 -0
- package/src/client/gateway.ts +120 -0
- package/src/client/http.ts +231 -0
- package/src/client/llm.ts +151 -0
- package/src/client/responses/errors.ts +166 -0
- package/src/client/responses/profile.ts +55 -0
- package/src/client/responses/providers.ts +87 -0
- package/src/client/responses/request.ts +326 -0
- package/src/client/responses/response.ts +203 -0
- package/src/client/util.ts +81 -0
- package/src/client.ts +20 -0
- package/src/content.ts +46 -0
- package/src/convert/anthropic.ts +115 -0
- package/src/convert/index.ts +275 -0
- package/src/convert/responses.ts +203 -0
- package/src/convert/types.ts +104 -0
- package/src/cost.ts +71 -0
- package/src/failure.ts +164 -0
- package/src/fields.ts +13 -0
- package/src/formats/anthropic.ts +191 -0
- package/src/formats/responses.ts +207 -0
- package/src/index.ts +44 -0
- package/src/json.ts +13 -0
- package/src/messages.ts +99 -0
- package/src/model.ts +41 -0
- package/src/models.ts +23 -0
- package/src/providers/anthropic.ts +137 -0
- package/src/providers/fireworks.ts +140 -0
- package/src/providers/openai.ts +275 -0
- package/src/providers.ts +59 -0
- package/src/read/anthropic.ts +64 -0
- package/src/read/responses.ts +159 -0
- package/src/read.ts +108 -0
- package/src/request.ts +28 -0
- package/src/response.ts +44 -0
- package/src/secrets.ts +40 -0
- package/src/tool-calls.ts +33 -0
- package/src/tools.ts +38 -0
- package/src/usage.ts +33 -0
- package/src/version.ts +6 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Readers over an Anthropic assistant message. They never change the message,
|
|
2
|
+
// which is sent back as it is.
|
|
3
|
+
import { isObject } from '../json.js';
|
|
4
|
+
function blocks(items) {
|
|
5
|
+
return items.filter(isObject);
|
|
6
|
+
}
|
|
7
|
+
/** Text blocks split around citations are joined as written. */
|
|
8
|
+
export function outputText(items) {
|
|
9
|
+
return blocks(items)
|
|
10
|
+
.map((block) => {
|
|
11
|
+
const text = block['text'];
|
|
12
|
+
return block['type'] === 'text' && typeof text === 'string' ? text : '';
|
|
13
|
+
})
|
|
14
|
+
.join('');
|
|
15
|
+
}
|
|
16
|
+
/** Anthropic reports a refusal as the stop reason, not as content. */
|
|
17
|
+
export function refusals() {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
/** Empty unless the request asked for `display: "summarized"`. */
|
|
21
|
+
export function reasoningSummary(items) {
|
|
22
|
+
return blocks(items).flatMap((block) => {
|
|
23
|
+
const thinking = block['thinking'];
|
|
24
|
+
return block['type'] === 'thinking' && typeof thinking === 'string' && thinking !== ''
|
|
25
|
+
? [thinking]
|
|
26
|
+
: [];
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Calls to the caller's tools. Server tools (`server_tool_use`, `mcp_tool_use`)
|
|
31
|
+
* run at Anthropic and are answered in the same message, so they are not here,
|
|
32
|
+
* and every call here is pending.
|
|
33
|
+
*/
|
|
34
|
+
export function toolCalls(items) {
|
|
35
|
+
return blocks(items).flatMap((block) => {
|
|
36
|
+
const id = block['id'];
|
|
37
|
+
const name = block['name'];
|
|
38
|
+
const toolset = block['toolset_name'];
|
|
39
|
+
if (block['type'] !== 'tool_use' || typeof id !== 'string' || typeof name !== 'string') {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
return [
|
|
43
|
+
{
|
|
44
|
+
toolCallId: id,
|
|
45
|
+
toolName: name,
|
|
46
|
+
toolType: 'function',
|
|
47
|
+
arguments: JSON.stringify(block['input'] ?? {}),
|
|
48
|
+
// A toolset member's result must name its toolset.
|
|
49
|
+
...(typeof toolset === 'string' ? { resultOptions: { toolset_name: toolset } } : {}),
|
|
50
|
+
itemType: 'tool_use',
|
|
51
|
+
item: block,
|
|
52
|
+
},
|
|
53
|
+
];
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=anthropic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../src/read/anthropic.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,+BAA+B;AAI/B,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,C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AAc,CAAC,CAAC;QACtC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,UAAU,IAAI,OAAO,EAAE,KAAK,QAAQ,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YACvF,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,OAAO;YACL;gBACE,UAAU,EAAE,EAAE;gBACd,QAAQ,EAAE,IAAI;gBACd,QAAQ,EAAE,UAAU;gBACpB,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;gBAC/C,mDAAmD;gBACnD,GAAG,CAAC,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,EAAE,YAAY,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACpF,QAAQ,EAAE,UAAU;gBACpB,IAAI,EAAE,KAAK;aACZ;SACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Json, JsonObject } from '@acentric/types';
|
|
2
|
+
/** What a reader returns for one call, before it is typed for its provider. */
|
|
3
|
+
export type ReadCall = {
|
|
4
|
+
readonly toolCallId: string;
|
|
5
|
+
readonly toolName: string;
|
|
6
|
+
readonly toolType: 'function' | 'custom' | 'native';
|
|
7
|
+
readonly arguments?: string;
|
|
8
|
+
readonly input?: string;
|
|
9
|
+
readonly namespace?: string;
|
|
10
|
+
readonly async?: boolean;
|
|
11
|
+
readonly resultOptions?: JsonObject;
|
|
12
|
+
readonly itemType: string;
|
|
13
|
+
readonly item: JsonObject;
|
|
14
|
+
};
|
|
15
|
+
export type TextOptions = {
|
|
16
|
+
/** `final`, the default, leaves out commentary, which is a progress update and not the answer. */
|
|
17
|
+
readonly phase?: 'final' | 'all';
|
|
18
|
+
};
|
|
19
|
+
export declare function outputText(items: readonly Json[], { phase }?: TextOptions): string;
|
|
20
|
+
export declare function refusals(items: readonly Json[]): string[];
|
|
21
|
+
export declare function reasoningSummary(items: readonly Json[]): string[];
|
|
22
|
+
/** Every call the caller answers, answered within the message or not. */
|
|
23
|
+
export declare function toolCalls(items: readonly Json[]): ReadCall[];
|
|
24
|
+
/** Calls with no answer in the message itself, as a hosted shell call has in its output. */
|
|
25
|
+
export declare function pendingToolCalls(items: readonly Json[]): ReadCall[];
|
|
26
|
+
//# sourceMappingURL=responses.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responses.d.ts","sourceRoot":"","sources":["../../src/read/responses.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAIxD,+EAA+E;AAC/E,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,UAAU,GAAG,QAAQ,GAAG,QAAQ,CAAC;IACpD,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,aAAa,CAAC,EAAE,UAAU,CAAC;IACpC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,kGAAkG;IAClG,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;CAClC,CAAC;AA8BF,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,EAAE,EAAE,KAAe,EAAE,GAAE,WAAgB,GAAG,MAAM,CAUhG;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,GAAG,MAAM,EAAE,CAOzD;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,GAAG,MAAM,EAAE,CASjE;AAED,yEAAyE;AACzE,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,GAAG,QAAQ,EAAE,CAe5D;AAED,4FAA4F;AAC5F,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,GAAG,QAAQ,EAAE,CAYnE"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// Readers over a Responses assistant message (OpenAI, Fireworks). They never
|
|
2
|
+
// change the message, which is sent back as it is.
|
|
3
|
+
import { isArray, isObject } from '../json.js';
|
|
4
|
+
/** Item types answered with a `tool_result` message, and the tool type they answer. */
|
|
5
|
+
const RESULT_CALLS = {
|
|
6
|
+
function_call: 'function',
|
|
7
|
+
custom_tool_call: 'custom',
|
|
8
|
+
};
|
|
9
|
+
/** Provider-defined calls the caller runs and answers with a `native` message. */
|
|
10
|
+
const NATIVE_CALLS = new Set([
|
|
11
|
+
'computer_call',
|
|
12
|
+
'shell_call',
|
|
13
|
+
'apply_patch_call',
|
|
14
|
+
'local_shell_call',
|
|
15
|
+
'tool_search_call',
|
|
16
|
+
'mcp_approval_request',
|
|
17
|
+
]);
|
|
18
|
+
function messages(items) {
|
|
19
|
+
return items.filter((item) => isObject(item) && item['type'] === 'message' && isArray(item['content']));
|
|
20
|
+
}
|
|
21
|
+
function parts(message) {
|
|
22
|
+
const content = message['content'];
|
|
23
|
+
return isArray(content) ? content.filter(isObject) : [];
|
|
24
|
+
}
|
|
25
|
+
export function outputText(items, { phase = 'final' } = {}) {
|
|
26
|
+
return messages(items)
|
|
27
|
+
.filter((message) => phase === 'all' || message['phase'] !== 'commentary')
|
|
28
|
+
.map((message) => parts(message)
|
|
29
|
+
.map((part) => (part['type'] === 'output_text' ? text(part['text']) : ''))
|
|
30
|
+
.join(''))
|
|
31
|
+
.filter((joined) => joined !== '')
|
|
32
|
+
.join('\n\n');
|
|
33
|
+
}
|
|
34
|
+
export function refusals(items) {
|
|
35
|
+
return messages(items).flatMap((message) => parts(message).flatMap((part) => {
|
|
36
|
+
const refusal = part['refusal'];
|
|
37
|
+
return part['type'] === 'refusal' && typeof refusal === 'string' ? [refusal] : [];
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
export function reasoningSummary(items) {
|
|
41
|
+
return items.flatMap((item) => {
|
|
42
|
+
if (!isObject(item) || item['type'] !== 'reasoning')
|
|
43
|
+
return [];
|
|
44
|
+
const summary = item['summary'];
|
|
45
|
+
if (!isArray(summary))
|
|
46
|
+
return [];
|
|
47
|
+
return summary.flatMap((part) => isObject(part) && typeof part['text'] === 'string' ? [part['text']] : []);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/** Every call the caller answers, answered within the message or not. */
|
|
51
|
+
export function toolCalls(items) {
|
|
52
|
+
const calls = [];
|
|
53
|
+
for (const item of items) {
|
|
54
|
+
if (!isObject(item))
|
|
55
|
+
continue;
|
|
56
|
+
const type = item['type'];
|
|
57
|
+
if (typeof type !== 'string')
|
|
58
|
+
continue;
|
|
59
|
+
const toolType = RESULT_CALLS[type] ?? (NATIVE_CALLS.has(type) ? 'native' : undefined);
|
|
60
|
+
if (toolType === undefined)
|
|
61
|
+
continue;
|
|
62
|
+
// Tool search that runs at the provider has no call to answer.
|
|
63
|
+
if (type === 'tool_search_call' && item['execution'] !== 'client')
|
|
64
|
+
continue;
|
|
65
|
+
const id = type === 'mcp_approval_request' ? item['id'] : item['call_id'];
|
|
66
|
+
if (typeof id !== 'string' || id === '')
|
|
67
|
+
continue;
|
|
68
|
+
calls.push(toCall(item, type, id, toolType));
|
|
69
|
+
}
|
|
70
|
+
return calls;
|
|
71
|
+
}
|
|
72
|
+
/** Calls with no answer in the message itself, as a hosted shell call has in its output. */
|
|
73
|
+
export function pendingToolCalls(items) {
|
|
74
|
+
const answered = new Set();
|
|
75
|
+
for (const item of items) {
|
|
76
|
+
if (!isObject(item))
|
|
77
|
+
continue;
|
|
78
|
+
const type = item['type'];
|
|
79
|
+
const request = item['approval_request_id'];
|
|
80
|
+
const callId = item['call_id'];
|
|
81
|
+
if (type === 'mcp_approval_response' && typeof request === 'string')
|
|
82
|
+
answered.add(request);
|
|
83
|
+
else if (typeof type === 'string' && type.endsWith('_output') && typeof callId === 'string')
|
|
84
|
+
answered.add(callId);
|
|
85
|
+
}
|
|
86
|
+
return toolCalls(items).filter((call) => !answered.has(call.toolCallId));
|
|
87
|
+
}
|
|
88
|
+
function toCall(item, type, id, toolType) {
|
|
89
|
+
const name = item['name'];
|
|
90
|
+
const namespace = item['namespace'];
|
|
91
|
+
const serverLabel = item['server_label'];
|
|
92
|
+
const args = item['arguments'];
|
|
93
|
+
const input = item['input'];
|
|
94
|
+
const caller = item['caller'];
|
|
95
|
+
const callNamespace = typeof namespace === 'string'
|
|
96
|
+
? namespace
|
|
97
|
+
: type === 'mcp_approval_request' && typeof serverLabel === 'string'
|
|
98
|
+
? serverLabel
|
|
99
|
+
: undefined;
|
|
100
|
+
// A result must repeat the call's caller (programmatic tool calling) and may name its namespace.
|
|
101
|
+
const resultOptions = {
|
|
102
|
+
...(isObject(caller) ? { caller } : {}),
|
|
103
|
+
...(toolType === 'function' && typeof namespace === 'string' ? { namespace } : {}),
|
|
104
|
+
};
|
|
105
|
+
return {
|
|
106
|
+
toolCallId: id,
|
|
107
|
+
toolName: typeof name === 'string' ? name : type.replace(/_call$/, ''),
|
|
108
|
+
toolType,
|
|
109
|
+
...(typeof args === 'string' && toolType !== 'native' ? { arguments: args } : {}),
|
|
110
|
+
...(typeof input === 'string' ? { input } : {}),
|
|
111
|
+
...(callNamespace === undefined ? {} : { namespace: callNamespace }),
|
|
112
|
+
...(item['async'] === true ? { async: true } : {}),
|
|
113
|
+
...(Object.keys(resultOptions).length > 0 ? { resultOptions } : {}),
|
|
114
|
+
itemType: type,
|
|
115
|
+
item,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function text(value) {
|
|
119
|
+
return typeof value === 'string' ? value : '';
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=responses.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responses.js","sourceRoot":"","sources":["../../src/read/responses.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,mDAAmD;AAInD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAqB/C,uFAAuF;AACvF,MAAM,YAAY,GAAuD;IACvE,aAAa,EAAE,UAAU;IACzB,gBAAgB,EAAE,QAAQ;CAC3B,CAAC;AAEF,kFAAkF;AAClF,MAAM,YAAY,GAAwB,IAAI,GAAG,CAAC;IAChD,eAAe;IACf,YAAY;IACZ,kBAAkB;IAClB,kBAAkB;IAClB,kBAAkB;IAClB,sBAAsB;CACvB,CAAC,CAAC;AAEH,SAAS,QAAQ,CAAC,KAAsB;IACtC,OAAO,KAAK,CAAC,MAAM,CACjB,CAAC,IAAI,EAAsB,EAAE,CAC3B,QAAQ,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAC3E,CAAC;AACJ,CAAC;AAED,SAAS,KAAK,CAAC,OAAmB;IAChC,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IACnC,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAC1D,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAsB,EAAE,EAAE,KAAK,GAAG,OAAO,KAAkB,EAAE;IACtF,OAAO,QAAQ,CAAC,KAAK,CAAC;SACnB,MAAM,CAAC,CAAC,O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AI,CAAC,aAAa,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACnE,QAAQ,EAAE,IAAI;QACd,IAAI;KACL,CAAC;AACJ,CAAC;AAED,SAAS,IAAI,CAAC,KAAuB;IACnC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;AAChD,CAAC"}
|
package/dist/read.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ContentPart } from './content.js';
|
|
2
|
+
import type { AssistantMessage, Message, RequestMessage, ToolResultMessage } from './messages.js';
|
|
3
|
+
import type { Provider } from './providers.js';
|
|
4
|
+
import type { TextOptions } from './read/responses.js';
|
|
5
|
+
import type { ToolCall } from './tool-calls.js';
|
|
6
|
+
export type { TextOptions } from './read/responses.js';
|
|
7
|
+
/**
|
|
8
|
+
* The text of the message's answer. On the Responses format, messages are
|
|
9
|
+
* joined by a blank line and commentary is left out unless `{ phase: 'all' }`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function outputText(message: AssistantMessage, options?: TextOptions): string;
|
|
12
|
+
/** What the model refused to do, in order. Anthropic says so in the stop reason instead, so its messages have none. */
|
|
13
|
+
export declare function refusals(message: AssistantMessage): string[];
|
|
14
|
+
/** Reasoning summaries or thinking texts, in order. Encrypted reasoning stays in the message. */
|
|
15
|
+
export declare function reasoningSummary(message: AssistantMessage): string[];
|
|
16
|
+
/** Every call in the message that the caller answers, answered within it or not. */
|
|
17
|
+
export declare function toolCalls<P extends Provider>(message: AssistantMessage<P>): ToolCall<P>[];
|
|
18
|
+
/** Calls the caller still has to answer. An async call may stay pending while the conversation goes on. */
|
|
19
|
+
export declare function pendingToolCalls<P extends Provider>(message: AssistantMessage<P>): ToolCall<P>[];
|
|
20
|
+
export type ToolResultOptions = {
|
|
21
|
+
/** Sent only where the provider has a field for it, so the content must say what failed. */
|
|
22
|
+
readonly isError?: boolean;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* The message answering a `function` or `custom` call, with the fields the
|
|
26
|
+
* provider requires on its result, such as OpenAI's `caller`. A `native` call
|
|
27
|
+
* is answered with a `native` message instead.
|
|
28
|
+
*/
|
|
29
|
+
export declare function toolResult(call: ToolCall, content: string | readonly ContentPart[], { isError }?: ToolResultOptions): ToolResultMessage;
|
|
30
|
+
/** The messages a provider receives: the application's own `custom` messages left out. */
|
|
31
|
+
export declare function requestMessages<P extends Provider>(messages: readonly Message<P>[]): RequestMessage<P>[];
|
|
32
|
+
//# sourceMappingURL=read.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../src/read.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,EAAE,gBAAgB,EAAE,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClG,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG/C,OAAO,KAAK,EAAY,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEhD,YAAY,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAavD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,MAAM,CAInF;AAED,uHAAuH;AACvH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,gBAAgB,GAAG,MAAM,EAAE,CAI5D;AAED,iGAAiG;AACjG,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,gBAAgB,GAAG,MAAM,EAAE,CAIpE;AAED,oFAAoF;AACpF,wBAAgB,SAAS,CAAC,CAAC,SAAS,QAAQ,EAAE,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,EAAE,CAOzF;AAED,2GAA2G;AAC3G,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,QAAQ,EAAE,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,EAAE,CAOhG;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,4FAA4F;IAC5F,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,IAAI,EAAE,QAAQ,EACd,OAAO,EAAE,MAAM,GAAG,SAAS,WAAW,EAAE,EACxC,EAAE,OAAO,EAAE,GAAE,iBAAsB,GAClC,iBAAiB,CAenB;AAED,0FAA0F;AAC1F,wBAAgB,eAAe,CAAC,CAAC,SAAS,QAAQ,EAChD,QAAQ,EAAE,SAAS,OAAO,CAAC,CAAC,CAAC,EAAE,GAC9B,cAAc,CAAC,CAAC,CAAC,EAAE,CAErB"}
|
package/dist/read.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Readers over any provider's assistant message, and the helpers that build
|
|
2
|
+
// what a request sends. Each reader goes to its message's API format. Pure:
|
|
3
|
+
// a step can use them.
|
|
4
|
+
import * as anthropic from './read/anthropic.js';
|
|
5
|
+
import * as responses from './read/responses.js';
|
|
6
|
+
/** The message's items, read as plain Json. */
|
|
7
|
+
function items(message) {
|
|
8
|
+
return message.content;
|
|
9
|
+
}
|
|
10
|
+
/** Typed for the message's provider: a reader returns that message's own items. */
|
|
11
|
+
function typed(calls) {
|
|
12
|
+
// oxlint-disable-next-line typescript/no-unsafe-type-assertion
|
|
13
|
+
return calls;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The text of the message's answer. On the Responses format, messages are
|
|
17
|
+
* joined by a blank line and commentary is left out unless `{ phase: 'all' }`.
|
|
18
|
+
*/
|
|
19
|
+
export function outputText(message, options) {
|
|
20
|
+
return message.api === 'anthropic-messages'
|
|
21
|
+
? anthropic.outputText(items(message))
|
|
22
|
+
: responses.outputText(items(message), options);
|
|
23
|
+
}
|
|
24
|
+
/** What the model refused to do, in order. Anthropic says so in the stop reason instead, so its messages have none. */
|
|
25
|
+
export function refusals(message) {
|
|
26
|
+
return message.api === 'anthropic-messages'
|
|
27
|
+
? anthropic.refusals()
|
|
28
|
+
: responses.refusals(items(message));
|
|
29
|
+
}
|
|
30
|
+
/** Reasoning summaries or thinking texts, in order. Encrypted reasoning stays in the message. */
|
|
31
|
+
export function reasoningSummary(message) {
|
|
32
|
+
return message.api === 'anthropic-messages'
|
|
33
|
+
? anthropic.reasoningSummary(items(message))
|
|
34
|
+
: responses.reasoningSummary(items(message));
|
|
35
|
+
}
|
|
36
|
+
/** Every call in the message that the caller answers, answered within it or not. */
|
|
37
|
+
export function toolCalls(message) {
|
|
38
|
+
const any = message;
|
|
39
|
+
return typed(any.api === 'anthropic-messages'
|
|
40
|
+
? anthropic.toolCalls(items(any))
|
|
41
|
+
: responses.toolCalls(items(any)));
|
|
42
|
+
}
|
|
43
|
+
/** Calls the caller still has to answer. An async call may stay pending while the conversation goes on. */
|
|
44
|
+
export function pendingToolCalls(message) {
|
|
45
|
+
const any = message;
|
|
46
|
+
return typed(any.api === 'anthropic-messages'
|
|
47
|
+
? anthropic.toolCalls(items(any))
|
|
48
|
+
: responses.pendingToolCalls(items(any)));
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The message answering a `function` or `custom` call, with the fields the
|
|
52
|
+
* provider requires on its result, such as OpenAI's `caller`. A `native` call
|
|
53
|
+
* is answered with a `native` message instead.
|
|
54
|
+
*/
|
|
55
|
+
export function toolResult(call, content, { isError } = {}) {
|
|
56
|
+
if (call.toolType === 'native') {
|
|
57
|
+
throw new TypeError(`${call.itemType} is a provider-defined call: answer it with a native message`);
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
role: 'tool_result',
|
|
61
|
+
toolCallId: call.toolCallId,
|
|
62
|
+
toolName: call.toolName,
|
|
63
|
+
toolType: call.toolType,
|
|
64
|
+
content: typeof content === 'string' ? [{ type: 'text', text: content }] : content,
|
|
65
|
+
...(isError === undefined ? {} : { isError }),
|
|
66
|
+
...(call.resultOptions === undefined ? {} : { providerOptions: call.resultOptions }),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/** The messages a provider receives: the application's own `custom` messages left out. */
|
|
70
|
+
export function requestMessages(messages) {
|
|
71
|
+
return messages.filter((message) => message.role !== 'custom');
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=read.js.map
|
package/dist/read.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read.js","sourceRoot":"","sources":["../src/read.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,4EAA4E;AAC5E,uBAAuB;AAOvB,OAAO,KAAK,SAAS,MAAM,qBAAqB,CAAC;AACjD,OAAO,KAAK,SAAS,MAAM,qBAAqB,CAAC;AAMjD,+CAA+C;AAC/C,SAAS,KAAK,CAAC,OAAyB;IACtC,OAAO,OAAO,CAAC,OAAO,CAAC;AACzB,CAAC;AAED,mFAAmF;AACnF,SAAS,KAAK,CAAqB,KAA0B;IAC3D,+DAA+D;IAC/D,OAAO,KAAiC,CAAC;AAC3C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,OAAyB,EAAE,OAAqB;IACzE,OAAO,OAAO,CAAC,GAAG,KAAK,oBAAoB;QACzC,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACtC,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC;AACpD,CAAC;AAED,uHAAuH;AACvH,MAAM,UAAU,QAAQ,CAAC,OAAyB;IAChD,OAAO,OAAO,CAAC,GAAG,KAAK,oB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IAAI,CAAC,QAAQ,8DAA8D,CAC/E,CAAC;IACJ,CAAC;IACD,OAAO;QACL,IAAI,EAAE,aAAa;QACnB,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,OAAO,EAAE,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO;QAClF,GAAG,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC;QAC7C,GAAG,CAAC,IAAI,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,IAAI,CAAC,aAAa,EAAE,CAAC;KACrF,CAAC;AACJ,CAAC;AAED,0FAA0F;AAC1F,MAAM,UAAU,eAAe,CAC7B,QAA+B;IAE/B,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAgC,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC;AAC/F,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { TextPart } from './content.js';
|
|
2
|
+
import type { Message } from './messages.js';
|
|
3
|
+
import type { ModelId, Provider, ProviderOptions } from './providers.js';
|
|
4
|
+
import type { ToolDefinition } from './tools.js';
|
|
5
|
+
/**
|
|
6
|
+
* One completion from provider `P`. Distributes over providers, so the model
|
|
7
|
+
* IDs, options and messages sent back all belong to `provider`.
|
|
8
|
+
*/
|
|
9
|
+
export type LlmRequest<P extends Provider = Provider> = P extends Provider ? {
|
|
10
|
+
readonly provider: P;
|
|
11
|
+
readonly model: ModelId<P>;
|
|
12
|
+
/** The provider's top-level system instructions. */
|
|
13
|
+
readonly instructions?: string | readonly TextPart[];
|
|
14
|
+
/** The conversation. `custom` messages are left out when sending. */
|
|
15
|
+
readonly messages: readonly Message<P>[];
|
|
16
|
+
/** Tools the caller runs. Hosted tools go in `options.tools`. */
|
|
17
|
+
readonly tools?: readonly ToolDefinition[];
|
|
18
|
+
/** The provider's own request fields, passed through. */
|
|
19
|
+
readonly options?: ProviderOptions<P>;
|
|
20
|
+
/** The most the call may take, in milliseconds. */
|
|
21
|
+
readonly timeoutMs?: number;
|
|
22
|
+
} : never;
|
|
23
|
+
//# sourceMappingURL=request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACzE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD;;;GAGG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,QAAQ,GAAG,QAAQ,IAAI,CAAC,SAAS,QAAQ,GACtE;IACE,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAC3B,oDAAoD;IACpD,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,QAAQ,EAAE,CAAC;IACrD,qEAAqE;IACrE,QAAQ,CAAC,QAAQ,EAAE,SAAS,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;IACzC,iEAAiE;IACjE,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,cAAc,EAAE,CAAC;IAC3C,yDAAyD;IACzD,QAAQ,CAAC,OAAO,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC;IACtC,mDAAmD;IACnD,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B,GACD,KAAK,CAAC"}
|
package/dist/request.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.js","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,8EAA8E"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { AssistantMessage } from './messages.js';
|
|
2
|
+
import type { ModelId, NativeResponse, Provider } from './providers.js';
|
|
3
|
+
import type { Usage } from './usage.js';
|
|
4
|
+
export type StopReason =
|
|
5
|
+
/** Generation ended normally, a stop sequence included. */
|
|
6
|
+
'stop'
|
|
7
|
+
/** Cut short by an output token or length limit. */
|
|
8
|
+
| 'length'
|
|
9
|
+
/** The model called tools for the caller to run. */
|
|
10
|
+
| 'tool_use'
|
|
11
|
+
/** The model declined. */
|
|
12
|
+
| 'refusal'
|
|
13
|
+
/** A provider's safety filter blocked or ended generation. */
|
|
14
|
+
| 'content_filter'
|
|
15
|
+
/** The provider paused a turn that can be continued, such as during a long server tool run. */
|
|
16
|
+
| 'pause_turn';
|
|
17
|
+
/** One completion from provider `P`. */
|
|
18
|
+
export type LlmResponse<P extends Provider = Provider> = P extends Provider ? {
|
|
19
|
+
/** The provider's response ID, such as for `previous_response_id`. */
|
|
20
|
+
readonly id?: string;
|
|
21
|
+
readonly provider: P;
|
|
22
|
+
/** The model ID the request asked for. */
|
|
23
|
+
readonly model: ModelId<P>;
|
|
24
|
+
/** The model the provider says answered, when it differs. */
|
|
25
|
+
readonly responseModel?: string;
|
|
26
|
+
readonly message: AssistantMessage<P>;
|
|
27
|
+
readonly stopReason: StopReason;
|
|
28
|
+
/** The provider's own reason, as it is, when it says more than `stopReason`. */
|
|
29
|
+
readonly providerStopReason?: string;
|
|
30
|
+
readonly usage?: Usage;
|
|
31
|
+
/** The provider's response fields that say something new: not its output or echoes of the request. */
|
|
32
|
+
readonly native: NativeResponse<P>;
|
|
33
|
+
/** How long the provider took, in milliseconds. */
|
|
34
|
+
readonly durationMs: number;
|
|
35
|
+
/** When the response arrived, in milliseconds since the Unix epoch. */
|
|
36
|
+
readonly timestamp: number;
|
|
37
|
+
} : never;
|
|
38
|
+
//# sourceMappingURL=response.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../src/response.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC,MAAM,MAAM,UAAU;AACpB,2DAA2D;AACzD,MAAM;AACR,oDAAoD;GAClD,QAAQ;AACV,oDAAoD;GAClD,UAAU;AACZ,0BAA0B;GACxB,SAAS;AACX,8DAA8D;GAC5D,gBAAgB;AAClB,+FAA+F;GAC7F,YAAY,CAAC;AAEjB,wCAAwC;AACxC,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,QAAQ,GAAG,QAAQ,IAAI,CAAC,SAAS,QAAQ,GACvE;IACE,sEAAsE;IACtE,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;IACrB,0CAA0C;IAC1C,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAC3B,6DAA6D;IAC7D,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;IACtC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,gFAAgF;IAChF,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IACrC,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;IACvB,sGAAsG;IACtG,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;IACnC,mDAAmD;IACnD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,uEAAuE;IACvE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B,GACD,KAAK,CAAC"}
|
package/dist/response.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response.js","sourceRoot":"","sources":["../src/response.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,gEAAgE"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** The secret holding each provider's API key. */
|
|
2
|
+
export declare const PROVIDER_SECRETS: {
|
|
3
|
+
readonly anthropic: "ANTHROPIC_API_KEY";
|
|
4
|
+
readonly openai: "OPENAI_API_KEY";
|
|
5
|
+
readonly fireworks: "FIREWORKS_API_KEY";
|
|
6
|
+
};
|
|
7
|
+
/** The gateway's address and token, which acentric-cloud sets for agents that use its gateway. */
|
|
8
|
+
export declare const GATEWAY_SECRETS: {
|
|
9
|
+
readonly url: "ACENTRIC_LLM_URL";
|
|
10
|
+
readonly token: "ACENTRIC_LLM_TOKEN";
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* The secrets the client reads, taken from an environment where they are set:
|
|
14
|
+
* what a runner on your own machine passes to handlers, such as
|
|
15
|
+
* `createMemoryRunner({ secrets: llmSecrets(process.env) })`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function llmSecrets(env: {
|
|
18
|
+
readonly [name: string]: string | undefined;
|
|
19
|
+
}): {
|
|
20
|
+
[name: string]: string;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=secrets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets.d.ts","sourceRoot":"","sources":["../src/secrets.ts"],"names":[],"mappings":"AAWA,kDAAkD;AAClD,eAAO,MAAM,gBAAgB;;;;CAI4B,CAAC;AAE1D,kGAAkG;AAClG,eAAO,MAAM,eAAe;;;CAGlB,CAAC;AAEX;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE;IAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;CAAE,GAAG;IAChF,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;CACxB,CAQA"}
|
package/dist/secrets.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// The secrets the client reads, by name. Runners and the CLI import these
|
|
2
|
+
// names to pass the matching environment variables to handlers, so no
|
|
3
|
+
// runner names a provider itself.
|
|
4
|
+
//
|
|
5
|
+
// The client calls a provider directly when its key is set, and otherwise
|
|
6
|
+
// the gateway when both gateway secrets are set. A secret that is not set
|
|
7
|
+
// rejects with SecretNotSet on every runner (RUNNERS.md §8), which is how the
|
|
8
|
+
// client tells which are set.
|
|
9
|
+
/** The secret holding each provider's API key. */
|
|
10
|
+
export const PROVIDER_SECRETS = {
|
|
11
|
+
anthropic: 'ANTHROPIC_API_KEY',
|
|
12
|
+
openai: 'OPENAI_API_KEY',
|
|
13
|
+
fireworks: 'FIREWORKS_API_KEY',
|
|
14
|
+
};
|
|
15
|
+
/** The gateway's address and token, which acentric-cloud sets for agents that use its gateway. */
|
|
16
|
+
export const GATEWAY_SECRETS = {
|
|
17
|
+
url: 'ACENTRIC_LLM_URL',
|
|
18
|
+
token: 'ACENTRIC_LLM_TOKEN',
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The secrets the client reads, taken from an environment where they are set:
|
|
22
|
+
* what a runner on your own machine passes to handlers, such as
|
|
23
|
+
* `createMemoryRunner({ secrets: llmSecrets(process.env) })`.
|
|
24
|
+
*/
|
|
25
|
+
export function llmSecrets(env) {
|
|
26
|
+
const names = [...Object.values(PROVIDER_SECRETS), ...Object.values(GATEWAY_SECRETS)];
|
|
27
|
+
const found = {};
|
|
28
|
+
for (const name of names) {
|
|
29
|
+
const value = env[name];
|
|
30
|
+
if (value !== undefined && value !== '')
|
|
31
|
+
found[name] = value;
|
|
32
|
+
}
|
|
33
|
+
return found;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=secrets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets.js","sourceRoot":"","sources":["../src/secrets.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,sEAAsE;AACtE,kCAAkC;AAClC,EAAE;AACF,0EAA0E;AAC1E,0EAA0E;AAC1E,8EAA8E;AAC9E,8BAA8B;AAI9B,kDAAkD;AAClD,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,SAAS,EAAE,mBAAmB;IAC9B,MAAM,EAAE,gBAAgB;IACxB,SAAS,EAAE,mBAAmB;CACyB,CAAC;AAE1D,kGAAkG;AAClG,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,GAAG,EAAE,kBAAkB;IACvB,KAAK,EAAE,oBAAoB;CACnB,CAAC;AAEX;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,GAAoD;IAG7E,MAAM,KAAK,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC;IACtF,MAAM,KAAK,GAA+B,EAAE,CAAC;IAC7C,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;QACxB,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE;YAAE,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;IAC/D,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ProviderFields } from './fields.js';
|
|
2
|
+
import type { NativeOutputItem, Provider } from './providers.js';
|
|
3
|
+
export type ToolCall<P extends Provider = Provider> = P extends Provider ? {
|
|
4
|
+
/** The ID a result answers. */
|
|
5
|
+
readonly toolCallId: string;
|
|
6
|
+
/** The tool's name, or the item type for a provider-defined tool without one. */
|
|
7
|
+
readonly toolName: string;
|
|
8
|
+
/**
|
|
9
|
+
* `function` and `custom` calls are answered with a `tool_result` message,
|
|
10
|
+
* `native` ones (a provider-defined tool such as computer use, or an
|
|
11
|
+
* approval request) with a `native` message.
|
|
12
|
+
*/
|
|
13
|
+
readonly toolType: 'function' | 'custom' | 'native';
|
|
14
|
+
/** A function call's arguments as the model wrote them: a JSON string, not parsed. */
|
|
15
|
+
readonly arguments?: string;
|
|
16
|
+
/** A custom tool call's text. */
|
|
17
|
+
readonly input?: string;
|
|
18
|
+
readonly namespace?: string;
|
|
19
|
+
/** The call may stay unanswered while the conversation goes on. */
|
|
20
|
+
readonly async?: boolean;
|
|
21
|
+
/** Fields the provider requires on this call's result; `toolResult` copies them. */
|
|
22
|
+
readonly resultOptions?: ProviderFields;
|
|
23
|
+
/** The provider's item type, such as `function_call` or `tool_use`. */
|
|
24
|
+
readonly itemType: string;
|
|
25
|
+
/** The call as the provider wrote it. */
|
|
26
|
+
readonly item: NativeOutputItem<P>;
|
|
27
|
+
} : never;
|
|
28
|
+
//# sourceMappingURL=tool-calls.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-calls.d.ts","sourceRoot":"","sources":["../src/tool-calls.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAEjE,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,QAAQ,GAAG,QAAQ,IAAI,CAAC,SAAS,QAAQ,GACpE;IACE,+BAA+B;IAC/B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,iFAAiF;IACjF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,UAAU,GAAG,QAAQ,GAAG,QAAQ,CAAC;IACpD,sFAAsF;IACtF,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,iCAAiC;IACjC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,mEAAmE;IACnE,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,oFAAoF;IACpF,QAAQ,CAAC,aAAa,CAAC,EAAE,cAAc,CAAC;IACxC,uEAAuE;IACvE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,yCAAyC;IACzC,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;CACpC,GACD,KAAK,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-calls.js","sourceRoot":"","sources":["../src/tool-calls.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,wCAAwC"}
|
package/dist/tools.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { JsonObject } from '@acentric/types';
|
|
2
|
+
import type { ProviderFields } from './fields.js';
|
|
3
|
+
/** A JSON Schema object. */
|
|
4
|
+
export type JsonSchema = JsonObject;
|
|
5
|
+
type ToolBase = {
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly description: string;
|
|
8
|
+
/** Merged into the provider's tool definition, such as Anthropic's `cache_control`. */
|
|
9
|
+
readonly providerOptions?: ProviderFields;
|
|
10
|
+
};
|
|
11
|
+
/** A tool called with JSON arguments matching `parameters`. */
|
|
12
|
+
export type FunctionTool = ToolBase & {
|
|
13
|
+
readonly type: 'function';
|
|
14
|
+
readonly parameters: JsonSchema;
|
|
15
|
+
/** Asks the provider to hold the arguments to the schema, where it can. */
|
|
16
|
+
readonly strict?: boolean;
|
|
17
|
+
};
|
|
18
|
+
/** A tool called with free-form text, optionally held to a grammar. Not every provider has them. */
|
|
19
|
+
export type CustomTool = ToolBase & {
|
|
20
|
+
readonly type: 'custom';
|
|
21
|
+
readonly format?: CustomToolFormat;
|
|
22
|
+
};
|
|
23
|
+
export type CustomToolFormat = {
|
|
24
|
+
readonly type: 'text';
|
|
25
|
+
} | {
|
|
26
|
+
readonly type: 'grammar';
|
|
27
|
+
readonly syntax: 'lark' | 'regex';
|
|
28
|
+
readonly definition: string;
|
|
29
|
+
};
|
|
30
|
+
export type ToolDefinition = FunctionTool | CustomTool;
|
|
31
|
+
export type ToolType = ToolDefinition['type'];
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,4BAA4B;AAC5B,MAAM,MAAM,UAAU,GAAG,UAAU,CAAC;AAEpC,KAAK,QAAQ,GAAG;IACd,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,uFAAuF;IACvF,QAAQ,CAAC,eAAe,CAAC,EAAE,cAAc,CAAC;CAC3C,CAAC;AAEF,+DAA+D;AAC/D,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG;IACpC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,2EAA2E;IAC3E,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF,oGAAoG;AACpG,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG;IAClC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,gBAAgB,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,gBAAgB,GACxB;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACzB;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;IAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjG,MAAM,MAAM,cAAc,GAAG,YAAY,GAAG,UAAU,CAAC;AAEvD,MAAM,MAAM,QAAQ,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC"}
|
package/dist/tools.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,4EAA4E"}
|
package/dist/usage.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Token counts. A count the provider does not report is left out; zero is a known zero. */
|
|
2
|
+
export type Usage = {
|
|
3
|
+
/** Every prompt token, cached or not. */
|
|
4
|
+
readonly totalInput?: number;
|
|
5
|
+
/** Prompt tokens neither read from nor written to a cache. */
|
|
6
|
+
readonly input?: number;
|
|
7
|
+
/** Output tokens, reasoning included where the provider counts it as output. */
|
|
8
|
+
readonly output?: number;
|
|
9
|
+
/** Reasoning tokens: part of `output` unless the provider bills them apart. */
|
|
10
|
+
readonly reasoning?: number;
|
|
11
|
+
readonly cacheRead?: number;
|
|
12
|
+
/** Every token written to a cache, whatever its time to live. */
|
|
13
|
+
readonly cacheWrite?: number;
|
|
14
|
+
/**
|
|
15
|
+
* What it cost: what the provider says it charged where it says so,
|
|
16
|
+
* otherwise estimated from the model's prices when they and every count
|
|
17
|
+
* needed are known.
|
|
18
|
+
*/
|
|
19
|
+
readonly cost?: UsageCost;
|
|
20
|
+
};
|
|
21
|
+
/** US dollars. A part that is not known is left out. */
|
|
22
|
+
export type UsageCost = {
|
|
23
|
+
/** `reported`: what the provider says it charged. `estimated`: tokens at known prices. */
|
|
24
|
+
readonly source: 'reported' | 'estimated';
|
|
25
|
+
readonly input?: number;
|
|
26
|
+
readonly output?: number;
|
|
27
|
+
readonly cacheRead?: number;
|
|
28
|
+
readonly cacheWrite?: number;
|
|
29
|
+
readonly total: number;
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=usage.d.ts.map
|