@nexface/agent 0.1.1-alpha.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/THIRD_PARTY_LICENSES.txt +245 -0
- package/dist/agent.d.ts +19 -0
- package/dist/agent.js +1509 -0
- package/dist/agent.js.map +1 -0
- package/dist/browser-prompt.d.ts +5 -0
- package/dist/browser-prompt.generated.d.ts +1 -0
- package/dist/browser-prompt.generated.js +50 -0
- package/dist/browser-prompt.generated.js.map +1 -0
- package/dist/browser-prompt.js +9 -0
- package/dist/browser-prompt.js.map +1 -0
- package/dist/errors.d.ts +21 -0
- package/dist/errors.js +55 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/model/binding.d.ts +22 -0
- package/dist/model/binding.js +31 -0
- package/dist/model/binding.js.map +1 -0
- package/dist/model/error.d.ts +6 -0
- package/dist/model/error.js +10 -0
- package/dist/model/error.js.map +1 -0
- package/dist/model/internal-adapter.d.ts +8 -0
- package/dist/model/internal-adapter.js +13 -0
- package/dist/model/internal-adapter.js.map +1 -0
- package/dist/model/types.d.ts +9 -0
- package/dist/model/types.js +2 -0
- package/dist/model/types.js.map +1 -0
- package/dist/models/885.js +630 -0
- package/dist/models/956.js +5 -0
- package/dist/models/_chunks/35-e1813138.js +8304 -0
- package/dist/models/_chunks/879-7e580bb2.js +1189 -0
- package/dist/models/_chunks/958-bedced75.js +453 -0
- package/dist/models/_chunks/anthropic-messages~1-a4b25b48.js +8057 -0
- package/dist/models/_chunks/deferred-tools-90f3c977.js +37 -0
- package/dist/models/_chunks/error-body-8bee35c2.js +134 -0
- package/dist/models/_chunks/google-generative-ai~1-78bb2822.js +22104 -0
- package/dist/models/_chunks/openai-completions~1-7677fb83.js +1285 -0
- package/dist/models/_chunks/openai-responses~1-cc0a71cd.js +958 -0
- package/dist/models/anthropic-messages.d.ts +4 -0
- package/dist/models/anthropic-messages.js +32 -0
- package/dist/models/google-generative-ai.d.ts +4 -0
- package/dist/models/google-generative-ai.js +32 -0
- package/dist/models/openai-completions.d.ts +5 -0
- package/dist/models/openai-completions.js +16 -0
- package/dist/models/openai-responses.d.ts +5 -0
- package/dist/models/openai-responses.js +16 -0
- package/dist/models/rslib-runtime.js +59 -0
- package/dist/models/types.d.ts +26 -0
- package/dist/tool-bridge.d.ts +36 -0
- package/dist/tool-bridge.js +299 -0
- package/dist/tool-bridge.js.map +1 -0
- package/dist/types.d.ts +129 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const identityToolName = (name) => name;
|
|
2
|
+
/** Split current tools into prefix and transcript-loaded definitions. */
|
|
3
|
+
function splitDeferredTools(context, enabled, normalizeName = identityToolName) {
|
|
4
|
+
const uniqueTools = new Map();
|
|
5
|
+
for (const tool of context.tools ?? [])
|
|
6
|
+
uniqueTools.set(normalizeName(tool.name), tool);
|
|
7
|
+
if (!enabled)
|
|
8
|
+
return { immediate: [...uniqueTools.values()], deferred: new Map() };
|
|
9
|
+
const deferredNames = new Set();
|
|
10
|
+
const usedNames = new Set();
|
|
11
|
+
for (const message of context.messages) {
|
|
12
|
+
if (message.role === "assistant") {
|
|
13
|
+
for (const block of message.content) {
|
|
14
|
+
if (block.type === "toolCall")
|
|
15
|
+
usedNames.add(normalizeName(block.name));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
else if (message.role === "toolResult") {
|
|
19
|
+
for (const name of message.addedToolNames ?? []) {
|
|
20
|
+
const normalizedName = normalizeName(name);
|
|
21
|
+
if (!usedNames.has(normalizedName))
|
|
22
|
+
deferredNames.add(normalizedName);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const immediate = [];
|
|
27
|
+
const deferred = new Map();
|
|
28
|
+
for (const [name, tool] of uniqueTools) {
|
|
29
|
+
if (deferredNames.has(name))
|
|
30
|
+
deferred.set(name, tool);
|
|
31
|
+
else
|
|
32
|
+
immediate.push(tool);
|
|
33
|
+
}
|
|
34
|
+
return { immediate, deferred };
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=deferred-tools.js.map
|
|
37
|
+
export { splitDeferredTools };
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// Shared normalization for provider HTTP error objects.
|
|
2
|
+
//
|
|
3
|
+
// Endpoints behind a proxy / gateway may return a non-2xx response whose body
|
|
4
|
+
// the provider SDK cannot fold into `error.message`. The SDK error object still
|
|
5
|
+
// carries the HTTP status and the raw/parsed body, but under SDK-specific field
|
|
6
|
+
// names. Provider catch blocks that read only `error.message` therefore drop
|
|
7
|
+
// the body and surface opaque messages like `"403 status code (no body)"` or
|
|
8
|
+
// collapse to `"Unknown: UnknownError"`.
|
|
9
|
+
//
|
|
10
|
+
// `normalizeProviderError` probes the known SDK field shapes (Mistral,
|
|
11
|
+
// `openai`, `@google/genai`, AWS Bedrock) and returns a struct each provider
|
|
12
|
+
// composes into its display string. The `messageCarriesBody` flag captures the
|
|
13
|
+
// Anthropic / `@google/genai` happy path where the SDK already folded the body
|
|
14
|
+
// into the message, so providers can preserve it without double-printing.
|
|
15
|
+
const MAX_PROVIDER_ERROR_BODY_CHARS = 4000;
|
|
16
|
+
function normalizeProviderError(error) {
|
|
17
|
+
if (!(error instanceof Error)) {
|
|
18
|
+
return { message: safeJsonStringify(error), messageCarriesBody: false };
|
|
19
|
+
}
|
|
20
|
+
const sdkError = error;
|
|
21
|
+
const status = extractStatus(sdkError);
|
|
22
|
+
const body = extractBody(sdkError);
|
|
23
|
+
const messageCarriesBody = body === undefined || error.message.includes(body);
|
|
24
|
+
return {
|
|
25
|
+
status,
|
|
26
|
+
body,
|
|
27
|
+
message: error.message,
|
|
28
|
+
messageCarriesBody,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Probe the HTTP status, first numeric hit wins, in SDK-field order:
|
|
33
|
+
* `statusCode` (Mistral) → `status` (`openai`, `@google/genai`) →
|
|
34
|
+
* `$metadata.httpStatusCode` (Bedrock) → `$response.statusCode` (Bedrock).
|
|
35
|
+
*/
|
|
36
|
+
function extractStatus(error) {
|
|
37
|
+
if (typeof error.statusCode === "number")
|
|
38
|
+
return error.statusCode;
|
|
39
|
+
if (typeof error.status === "number")
|
|
40
|
+
return error.status;
|
|
41
|
+
if (typeof error.$metadata?.httpStatusCode === "number")
|
|
42
|
+
return error.$metadata.httpStatusCode;
|
|
43
|
+
if (typeof error.$response?.statusCode === "number")
|
|
44
|
+
return error.$response.statusCode;
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Probe the raw body reason, first usable hit wins, in SDK-field order:
|
|
49
|
+
* `body` string (Mistral) → `error` parsed JSON body object (`openai` SDK's
|
|
50
|
+
* `this.error`) → `$response.body` (Bedrock). Empty objects and unread response
|
|
51
|
+
* streams are treated as no body so they do not surface as `"{}"` or serialized
|
|
52
|
+
* stream internals. The chosen body is truncated to the cap.
|
|
53
|
+
*/
|
|
54
|
+
function extractBody(error) {
|
|
55
|
+
const bodyText = pickBodyText(error);
|
|
56
|
+
if (bodyText === undefined)
|
|
57
|
+
return undefined;
|
|
58
|
+
const trimmed = bodyText.trim();
|
|
59
|
+
if (trimmed.length === 0)
|
|
60
|
+
return undefined;
|
|
61
|
+
return truncateErrorText(trimmed, MAX_PROVIDER_ERROR_BODY_CHARS);
|
|
62
|
+
}
|
|
63
|
+
function pickBodyText(error) {
|
|
64
|
+
if (typeof error.body === "string")
|
|
65
|
+
return error.body;
|
|
66
|
+
if (isPlainNonEmptyObject(error.error))
|
|
67
|
+
return safeJsonStringify(error.error);
|
|
68
|
+
const responseBody = error.$response?.body;
|
|
69
|
+
if (typeof responseBody === "string")
|
|
70
|
+
return responseBody;
|
|
71
|
+
if (isReadableStreamLike(responseBody))
|
|
72
|
+
return undefined;
|
|
73
|
+
if (isPlainNonEmptyObject(responseBody))
|
|
74
|
+
return safeJsonStringify(responseBody);
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
function isReadableStreamLike(value) {
|
|
78
|
+
return typeof value === "object" && value !== null && "pipe" in value && typeof value.pipe === "function";
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Only a PLAIN object counts as an HTTP body. SDK error fields can hold class
|
|
82
|
+
* instances instead of parsed bodies — AWS SDK v3's `$response.body` is an
|
|
83
|
+
* HTTP stream/response wrapper object, and stringifying one produced garbage
|
|
84
|
+
* like `{"_events":...}` as the "body", which then REPLACED `error.message`
|
|
85
|
+
* in the composed display string. `error.message` is where the SDK puts the
|
|
86
|
+
* real deserialized exception text ("Input is too long...", schema validation
|
|
87
|
+
* details, ...), so the one useful string was discarded for noise. A class
|
|
88
|
+
* instance yields no body, `messageCarriesBody` stays true, and the real
|
|
89
|
+
* message survives. Complements the `pipe` sniffing above: web
|
|
90
|
+
* ReadableStreams (pipeTo/pipeThrough, no `pipe`) and non-stream SDK wrapper
|
|
91
|
+
* classes fail the prototype check, while parsed JSON bodies (plain objects
|
|
92
|
+
* by construction) still pass.
|
|
93
|
+
*/
|
|
94
|
+
function isPlainNonEmptyObject(value) {
|
|
95
|
+
if (typeof value !== "object" || value === null)
|
|
96
|
+
return false;
|
|
97
|
+
const proto = Object.getPrototypeOf(value);
|
|
98
|
+
if (proto !== Object.prototype && proto !== null)
|
|
99
|
+
return false;
|
|
100
|
+
return Object.keys(value).length > 0;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Compose a display string from a normalized error. When the message already
|
|
104
|
+
* carries the body (Anthropic / `@google/genai` happy path) or no body/status
|
|
105
|
+
* was extracted, the message is returned unchanged. Otherwise the status and
|
|
106
|
+
* body are surfaced, with an optional provider prefix.
|
|
107
|
+
*
|
|
108
|
+
* - no prefix: `"<status>: <body>"`
|
|
109
|
+
* - prefix: `"<prefix> (<status>): <body>"`
|
|
110
|
+
*/
|
|
111
|
+
function formatProviderError(norm, prefix) {
|
|
112
|
+
if (norm.messageCarriesBody || norm.status === undefined || norm.body === undefined) {
|
|
113
|
+
return prefix !== undefined && norm.status !== undefined
|
|
114
|
+
? `${prefix} (${norm.status}): ${norm.message}`
|
|
115
|
+
: norm.message;
|
|
116
|
+
}
|
|
117
|
+
return prefix !== undefined ? `${prefix} (${norm.status}): ${norm.body}` : `${norm.status}: ${norm.body}`;
|
|
118
|
+
}
|
|
119
|
+
function truncateErrorText(text, maxChars) {
|
|
120
|
+
if (text.length <= maxChars)
|
|
121
|
+
return text;
|
|
122
|
+
return `${text.slice(0, maxChars)}... [truncated ${text.length - maxChars} chars]`;
|
|
123
|
+
}
|
|
124
|
+
function safeJsonStringify(value) {
|
|
125
|
+
try {
|
|
126
|
+
const serialized = JSON.stringify(value);
|
|
127
|
+
return serialized === undefined ? String(value) : serialized;
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
return String(value);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=error-body.js.map
|
|
134
|
+
export { formatProviderError, normalizeProviderError };
|