buckyos 0.7.205 → 0.7.208
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/cli/dist/cli.mjs +1 -1
- package/cli/dist/cli.mjs.map +1 -1
- package/cli/version.ts +1 -1
- package/dist/{aiws_write-eeea8ed3.js → aiws_write-825bb6ba.js} +3 -3
- package/dist/aiws_write-825bb6ba.js.map +1 -0
- package/dist/{aiws_write-47c90e76.mjs → aiws_write-83ddc6cc.mjs} +30 -2
- package/dist/aiws_write-83ddc6cc.mjs.map +1 -0
- package/dist/app-frame.cjs +1 -1
- package/dist/app-frame.cjs.map +1 -1
- package/dist/app-frame.d.ts +221 -2
- package/dist/app-frame.d.ts.map +1 -1
- package/dist/app-frame.mjs +531 -15
- package/dist/app-frame.mjs.map +1 -1
- package/dist/browser.cjs +1 -1
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.ts +4 -0
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.mjs +11 -6
- package/dist/browser.mjs.map +1 -1
- package/dist/content.cjs +1 -1
- package/dist/content.cjs.map +1 -1
- package/dist/content.d.ts +2 -0
- package/dist/content.d.ts.map +1 -1
- package/dist/content.mjs +14 -7
- package/dist/content.mjs.map +1 -1
- package/dist/{content_objid-0a095cbd.mjs → content_objid-76434848.mjs} +2 -2
- package/dist/{content_objid-0a095cbd.mjs.map → content_objid-76434848.mjs.map} +1 -1
- package/dist/{content_objid-4742308a.js → content_objid-addf9e2b.js} +2 -2
- package/dist/{content_objid-4742308a.js.map → content_objid-addf9e2b.js.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +11 -6
- package/dist/index.mjs.map +1 -1
- package/dist/internal/html_tokens.d.ts +13 -0
- package/dist/internal/html_tokens.d.ts.map +1 -0
- package/dist/node.cjs +1 -1
- package/dist/node.cjs.map +1 -1
- package/dist/node.d.ts +4 -0
- package/dist/node.d.ts.map +1 -1
- package/dist/node.mjs +10 -5
- package/dist/node.mjs.map +1 -1
- package/dist/sdk_core.d.ts +18 -0
- package/dist/sdk_core.d.ts.map +1 -1
- package/dist/{site_manager-91b4d899.mjs → site_manager-604ee369.mjs} +207 -141
- package/dist/site_manager-604ee369.mjs.map +1 -0
- package/dist/site_manager-70710895.js +2 -0
- package/dist/site_manager-70710895.js.map +1 -0
- package/dist/transfer.cjs +2 -0
- package/dist/transfer.cjs.map +1 -0
- package/dist/transfer.d.ts +148 -0
- package/dist/transfer.d.ts.map +1 -0
- package/dist/transfer.mjs +655 -0
- package/dist/transfer.mjs.map +1 -0
- package/dist/user_preferences-1d49850a.mjs +158 -0
- package/dist/user_preferences-1d49850a.mjs.map +1 -0
- package/dist/user_preferences-7288c989.js +2 -0
- package/dist/user_preferences-7288c989.js.map +1 -0
- package/dist/user_preferences.d.ts +50 -0
- package/dist/user_preferences.d.ts.map +1 -0
- package/dist/xllm/core/loop.d.ts.map +1 -1
- package/dist/xllm/core/types.d.ts +0 -2
- package/dist/xllm/core/types.d.ts.map +1 -1
- package/dist/xllm/hosts/deno/native_runtime.d.ts.map +1 -1
- package/dist/xllm/hosts/deno/native_tools.d.ts +2 -1
- package/dist/xllm/hosts/deno/native_tools.d.ts.map +1 -1
- package/dist/xllm/index.d.ts +3 -2
- package/dist/xllm/index.d.ts.map +1 -1
- package/dist/xllm/runtime/hints.d.ts +9 -4
- package/dist/xllm/runtime/hints.d.ts.map +1 -1
- package/dist/xllm/runtime/step_renderer.d.ts +4 -4
- package/dist/xllm/runtime/step_renderer.d.ts.map +1 -1
- package/dist/xllm/runtime/text_budget.d.ts +5 -0
- package/dist/xllm/runtime/text_budget.d.ts.map +1 -0
- package/dist/xllm/runtime/tool_result.d.ts +14 -1
- package/dist/xllm/runtime/tool_result.d.ts.map +1 -1
- package/dist/xllm.cjs +1 -1
- package/dist/xllm.cjs.map +1 -1
- package/dist/xllm.mjs +35 -29
- package/dist/xllm_deno.cjs +1 -1
- package/dist/xllm_deno.cjs.map +1 -1
- package/dist/xllm_deno.mjs +123 -42
- package/dist/xllm_deno.mjs.map +1 -1
- package/package.json +6 -1
- package/dist/aiws_write-47c90e76.mjs.map +0 -1
- package/dist/aiws_write-eeea8ed3.js.map +0 -1
- package/dist/runtime_env-39e4df98.mjs +0 -44
- package/dist/runtime_env-39e4df98.mjs.map +0 -1
- package/dist/runtime_env-6396e1eb.js +0 -2
- package/dist/runtime_env-6396e1eb.js.map +0 -1
- package/dist/site_manager-716a2cf5.js +0 -2
- package/dist/site_manager-716a2cf5.js.map +0 -1
- package/dist/site_manager-91b4d899.mjs.map +0 -1
package/dist/xllm/index.d.ts
CHANGED
|
@@ -26,13 +26,14 @@ export type { SiteRuntime, SiteRuntimeOptions } from './runtime/site';
|
|
|
26
26
|
export { unresolvedReason } from './runtime/types';
|
|
27
27
|
export type { AgentRuntime, OpenedTools, RunBinding, RunToolManager, RuntimeOpenCtx, SiteTool, SiteToolCtx, SiteToolSpec, } from './runtime/types';
|
|
28
28
|
export { SiteToolManager, envelopeObservation, isIdempotent } from './runtime/site_manager';
|
|
29
|
-
export { AGENT_TOOL_PROTOCOL_VERSION, asToolResult, observationText, toHost } from './runtime/tool_result';
|
|
29
|
+
export { AGENT_TOOL_PROTOCOL_VERSION, asToolResult, fitResultBudget, fullText, observationText, toHost } from './runtime/tool_result';
|
|
30
|
+
export { RESULT_BUDGET_TOKENS, clipToBudget, clipToDefaultBudget } from './runtime/text_budget';
|
|
30
31
|
export type { AgentToolResult, AgentToolStatus, ResultDedup, ResultHint } from './runtime/tool_result';
|
|
31
32
|
export { XmlStepRenderer, toolResultViewFromHost } from './runtime/step_renderer';
|
|
32
33
|
export type { HintView, ToolResultStatusView, ToolResultView, XmlStepRendererOptions } from './runtime/step_renderer';
|
|
33
34
|
export { LlmSummarizeCompressor, SUMMARIZE_MODEL_ALIAS, compactionTargetTokens, compress, compressHistory, compressOptions, isSummaryMessage, parseSummaryMessage, summaryMessage, summaryModel, } from './runtime/compress';
|
|
34
35
|
export type { CompressDeps, CompressOptions, CompressOutcome, CompressReport, CompressStrategy, CompressedSummary } from './runtime/compress';
|
|
35
|
-
export { HINT_NS_DEDUP, HINT_NS_ONCE, MemoryHintLedger, applyHints, renderHintBlock, renderWithHints } from './runtime/hints';
|
|
36
|
+
export { HINT_NS_DEDUP, HINT_NS_ONCE, MemoryHintLedger, applyHints, dedupText, renderHintBlock, renderWithHints } from './runtime/hints';
|
|
36
37
|
export type { HintLedger } from './runtime/hints';
|
|
37
38
|
export { followupGeneralHint, followupHint, inCallWaitMs, resultView, taskStateObservation, waitUntilMs, } from './runtime/task_model';
|
|
38
39
|
export type { RunningTaskResolver, TaskBrief, TaskFollowup, TaskResult, TaskState } from './runtime/task_model';
|
package/dist/xllm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/xllm/index.ts"],"names":[],"mappings":"AAIA,cAAc,cAAc,CAAA;AAC5B,OAAO,EACL,mBAAmB,EAAE,SAAS,EAAE,cAAc,EAAE,mBAAmB,EAAE,WAAW,EAAE,cAAc,EAAE,cAAc,EAAE,aAAa,GAChI,MAAM,eAAe,CAAA;AACtB,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AACnE,OAAO,EAAE,UAAU,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AACnF,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAA;AAC5D,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAE,WAAW,EAAE,gBAAgB,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAA;AAC/H,YAAY,EACV,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,eAAe,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,GACpI,MAAM,aAAa,CAAA;AACp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CAAA;AACvE,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AAChH,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA"}
|
|
@@ -2,21 +2,26 @@ import type { AgentToolResult } from './tool_result';
|
|
|
2
2
|
export declare const HINT_NS_ONCE = "once";
|
|
3
3
|
export declare const HINT_NS_DEDUP = "dedup";
|
|
4
4
|
export interface HintLedger {
|
|
5
|
+
/** The call that showed `key` (`''` when unknown); `undefined`: not shown. */
|
|
6
|
+
origin(ns: string, key: string): string | undefined;
|
|
5
7
|
seen(ns: string, key: string): boolean;
|
|
6
|
-
mark(ns: string, key: string): void;
|
|
8
|
+
mark(ns: string, key: string, origin: string): void;
|
|
7
9
|
clear(ns: string): void;
|
|
8
10
|
keys(ns: string): string[];
|
|
9
11
|
}
|
|
10
12
|
export declare class MemoryHintLedger implements HintLedger {
|
|
11
13
|
private readonly inner;
|
|
12
14
|
static seeded(ns: string, keys: Iterable<string>): MemoryHintLedger;
|
|
15
|
+
origin(ns: string, key: string): string | undefined;
|
|
13
16
|
seen(ns: string, key: string): boolean;
|
|
14
|
-
mark(ns: string, key: string): void;
|
|
17
|
+
mark(ns: string, key: string, origin: string): void;
|
|
15
18
|
clear(ns: string): void;
|
|
16
19
|
keys(ns: string): string[];
|
|
17
20
|
}
|
|
18
|
-
/**
|
|
19
|
-
export declare function
|
|
21
|
+
/** `dedup_text`: what replaces a result shown in full before by call `origin`. */
|
|
22
|
+
export declare function dedupText(hint: string, origin: string): string;
|
|
23
|
+
/** Apply the ledger to the result of call `callId` (mutated): dedup replacement, `once` filtering; returns the hint texts to show. */
|
|
24
|
+
export declare function applyHints(result: AgentToolResult, ledger: HintLedger, callId: string): string[];
|
|
20
25
|
export declare function renderHintBlock(hints: string[]): string;
|
|
21
26
|
/** The result text with the hints after it (`<output>` / `<runtime_hints>`). */
|
|
22
27
|
export declare function renderWithHints(text: string, hints: string[]): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hints.d.ts","sourceRoot":"","sources":["../../../src/xllm/runtime/hints.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hints.d.ts","sourceRoot":"","sources":["../../../src/xllm/runtime/hints.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAGpD,eAAO,MAAM,YAAY,SAAS,CAAA;AAClC,eAAO,MAAM,aAAa,UAAU,CAAA;AAEpC,MAAM,WAAW,UAAU;IACzB,8EAA8E;IAC9E,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IACnD,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;IACtC,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IACnD,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;CAC3B;AAED,qBAAa,gBAAiB,YAAW,UAAU;IACjD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAyC;IAE/D,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,gBAAgB;IAMnE,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAInD,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO;IAItC,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAM5C,KAAK,CAAC,EAAE,EAAE,MAAM;IAIhB,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE;CAG3B;AAED,kFAAkF;AAClF,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAG9D;AAED,sIAAsI;AACtI,wBAAgB,UAAU,CAAC,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAyBhG;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAIvD;AAED,gFAAgF;AAChF,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAGrE"}
|
|
@@ -30,16 +30,16 @@ export interface ToolResultView {
|
|
|
30
30
|
*/
|
|
31
31
|
export declare function toolResultViewFromHost(host: JsonValue | undefined): ToolResultView | undefined;
|
|
32
32
|
export interface XmlStepRendererOptions {
|
|
33
|
-
/**
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Backstop on one result body (chars, `0`: none). The dispatcher keeps
|
|
35
|
+
* results within the per-result budget, so the default never clips.
|
|
36
|
+
*/
|
|
36
37
|
maxResultChars?: number;
|
|
37
38
|
/** Render `started_at_ms` / `ended_at_ms` into history records (default true). */
|
|
38
39
|
timestamps?: boolean;
|
|
39
40
|
}
|
|
40
41
|
/** Default renderer of the XML behavior protocol (`XmlStepRenderer`). Stateless; share one across runs. */
|
|
41
42
|
export declare class XmlStepRenderer implements StepRenderer {
|
|
42
|
-
readonly summaryChars: number;
|
|
43
43
|
readonly maxResultChars: number;
|
|
44
44
|
readonly timestamps: boolean;
|
|
45
45
|
constructor(options?: XmlStepRendererOptions);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"step_renderer.d.ts","sourceRoot":"","sources":["../../../src/xllm/runtime/step_renderer.ts"],"names":[],"mappings":"AAWA,OAAO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;IACrC;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,kFAAkF;IAClF,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAED,2GAA2G;AAC3G,qBAAa,eAAgB,YAAW,YAAY;IAClD,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;IAC/B,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAA;gBAEhB,OAAO,GAAE,sBAA2B;IAKhD,gGAAgG;IAChG,iBAAiB,IAAI,eAAe;IAIpC,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC;IAIhD,eAAe,CAAC,IAAI,EAAE,UAAU,GAAG,SAAS;IAI5C,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,SAAS;IAOvD,aAAa,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE,eAAe,EAAE,MAAM,EAAE,SAAS,EAAE,oBAAoB,EAAE,GAAG,SAAS,EAAE;IAiB3G,OAAO,CAAC,UAAU;CAOnB"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const RESULT_BUDGET_TOKENS: number;
|
|
2
|
+
/** `clip_to_budget` with the 4-bytes-a-token estimate: `[text, clipped]`. */
|
|
3
|
+
export declare function clipToBudget(text: string, budget: number, more?: string): [string, boolean];
|
|
4
|
+
export declare function clipToDefaultBudget(text: string, more?: string): [string, boolean];
|
|
5
|
+
//# sourceMappingURL=text_budget.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text_budget.d.ts","sourceRoot":"","sources":["../../../src/xllm/runtime/text_budget.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,oBAAoB,QAAY,CAAA;AAuB7C,6EAA6E;AAC7E,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAW3F;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAElF"}
|
|
@@ -3,7 +3,7 @@ export declare const AGENT_TOOL_PROTOCOL_VERSION = "1";
|
|
|
3
3
|
export type AgentToolStatus = 'success' | 'error' | 'pending';
|
|
4
4
|
export interface ResultHint {
|
|
5
5
|
text: string;
|
|
6
|
-
/** Shown once
|
|
6
|
+
/** Shown once while a result that showed it is in the context (`hints_once` in run.json). */
|
|
7
7
|
once?: string;
|
|
8
8
|
}
|
|
9
9
|
export interface ResultDedup {
|
|
@@ -32,8 +32,21 @@ export interface AgentToolResult {
|
|
|
32
32
|
}
|
|
33
33
|
/** A return value that is an AgentToolResult envelope (`agent_tool_protocol: "1"`). */
|
|
34
34
|
export declare function asToolResult(value: unknown): AgentToolResult | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* `result_view::full_text`: what a result shows in full, the same in both
|
|
37
|
+
* loops: the output, else a string detail, the summary, the title; a
|
|
38
|
+
* structured detail only when none of them is there (compact JSON within the
|
|
39
|
+
* per-result budget). An error shows its summary with its output.
|
|
40
|
+
*/
|
|
41
|
+
export declare function fullText(isError: boolean, output: string | undefined, detail: JsonValue | undefined, summary: string, title: string): string;
|
|
35
42
|
/** The text the model sees (`AgentToolResult::observation_text`). */
|
|
36
43
|
export declare function observationText(r: AgentToolResult): string;
|
|
44
|
+
/**
|
|
45
|
+
* `fit_result_budget`: keep `r` (mutated) within `budget` tokens before the
|
|
46
|
+
* dispatcher maps it; the summary takes at most a quarter. A result cut here
|
|
47
|
+
* is not shown in full, so its dedup key is dropped.
|
|
48
|
+
*/
|
|
49
|
+
export declare function fitResultBudget(r: AgentToolResult, budget?: number): void;
|
|
37
50
|
/** The envelope as `Observation.host` (`to_host`). */
|
|
38
51
|
export declare function toHost(r: AgentToolResult): JsonValue;
|
|
39
52
|
//# sourceMappingURL=tool_result.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool_result.d.ts","sourceRoot":"","sources":["../../../src/xllm/runtime/tool_result.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"tool_result.d.ts","sourceRoot":"","sources":["../../../src/xllm/runtime/tool_result.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAK9C,eAAO,MAAM,2BAA2B,MAAM,CAAA;AAE9C,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAA;AAE7D,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,6FAA6F;IAC7F,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,eAAe;IAC9B,mBAAmB,EAAE,MAAM,CAAA;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,eAAe,CAAA;IACvB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,oGAAoG;IACpG,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,SAAS,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,UAAU,EAAE,CAAA;IACpB,KAAK,CAAC,EAAE,WAAW,CAAA;CACpB;AAED,uFAAuF;AACvF,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,GAAG,SAAS,CAUxE;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,EAAE,SAAS,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAkB5I;AAED,qEAAqE;AACrE,wBAAgB,eAAe,CAAC,CAAC,EAAE,eAAe,GAAG,MAAM,CAE1D;AAMD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,eAAe,EAAE,MAAM,SAAuB,GAAG,IAAI,CAWvF;AAED,sDAAsD;AACtD,wBAAgB,MAAM,CAAC,CAAC,EAAE,eAAe,GAAG,SAAS,CAEpD"}
|
package/dist/xllm.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./aicc-ccb36ef7.js"),t=require("./site_manager-716a2cf5.js"),o=require("./did_object_client-27835522.js");require("./krpc_client-26c2dc8b.js"),require("./object_url-88047ee2.js"),require("./ndn_types-5b138882.js");const r="site",n=/^[A-Za-z0-9_-]{1,64}$/;function s(o,r){return(o??[]).map((o=>{if("named"!==o.kind)throw e.XllmError.capability(`${r}: \`${t.describeToolSource(o)}\` is not available in a site runtime; only the page's tools can be named`);return o.name}))}class i extends Error{constructor(e,t){super(t),this.name="CommandArgsError",this.code=e}}function a(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function c(e){return e.property??e.name.split("-").join("_")}function l(e){const t=e.slice(2),o=t.indexOf("=");return o<0?{name:t}:{name:t.slice(0,o),inlineValue:t.slice(o+1)}}function u(e,t,o){if(void 0!==o.inlineValue){if(!o.inlineValue)throw new i("MISSING_ARGUMENT",`--${o.name} requires a value`);return{value:o.inlineValue,consumed:1}}const r=e[t+1];if(void 0===r||r.startsWith("--"))throw new i("MISSING_ARGUMENT",`--${o.name} requires a value`);return{value:r,consumed:2}}function p(e,t,o){if("string"===e)return t;const r=Number(t);if(!Number.isFinite(r)||"integer"===e&&!Number.isInteger(r))throw new i("INVALID_ARGUMENT",`--${o} requires a ${e}`);return r}function d(e,t,o,r){const n=t[o];if(!n)throw new i("TOO_MANY_ARGUMENTS",`unexpected positional argument: ${r}`);return e[n.name]=r,o+1}function m(e){const t=[];let o="",r=null,n=!1,s=!1;for(const i of e)n?(o+=i,n=!1,s=!0):"\\"!==i||"single"===r?"single"!==r?"double"!==r?"'"!==i?'"'!==i?/\s/.test(i)?s&&(t.push(o),o="",s=!1):(o+=i,s=!0):(r="double",s=!0):(r="single",s=!0):'"'===i?r=null:o+=i:"'"===i?r=null:o+=i:(n=!0,s=!0);if(n)throw new i("INVALID_COMMAND_LINE","unfinished escape sequence");if(r)throw new i("INVALID_COMMAND_LINE",`unterminated ${r} quote`);return s&&t.push(o),t}function f(e,t,o){var r;if(t.enum&&!t.enum.some((t=>Object.is(t,e))))throw new i("SCHEMA_VALIDATION_FAILED",`${o} must be one of ${t.enum.join(", ")}`);if("object"!==t.type)if("array"!==t.type)if("string"!==t.type){if("boolean"===t.type&&"boolean"!=typeof e)throw new i("SCHEMA_VALIDATION_FAILED",`${o} must be a boolean`);if("integer"===t.type&&(!Number.isInteger(e)||"number"!=typeof e))throw new i("SCHEMA_VALIDATION_FAILED",`${o} must be an integer`);if("number"===t.type&&"number"!=typeof e)throw new i("SCHEMA_VALIDATION_FAILED",`${o} must be a number`)}else{if("string"!=typeof e)throw new i("SCHEMA_VALIDATION_FAILED",`${o} must be a string`);if(void 0!==t.minLength&&e.length<t.minLength)throw new i("SCHEMA_VALIDATION_FAILED",`${o} is too short`)}else{if(!Array.isArray(e))throw new i("SCHEMA_VALIDATION_FAILED",`${o} must be an array`);const r=t.items;r&&e.forEach(((e,t)=>f(e,r,`${o}[${t}]`)))}else{if(!e||"object"!=typeof e||Array.isArray(e))throw new i("SCHEMA_VALIDATION_FAILED",`${o} must be an object`);const n=e;for(const e of t.required??[])if(!a(n,e))throw new i("SCHEMA_VALIDATION_FAILED",`${o}.${e} is required`);if(!1===t.additionalProperties)for(const e of Object.keys(n))if(!a(t.properties??{},e))throw new i("SCHEMA_VALIDATION_FAILED",`${o}.${e} is not allowed`);for(const[e,s]of Object.entries(n)){const n=null==(r=t.properties)?void 0:r[e];n&&f(s,n,`${o}.${e}`)}}}const h=["read_only","idempotent_write","write","destructive","admin"],g="xcall <object> <action> [--params <json>] [key=value ...] [--key=value ...]",_=65536,x=/[|;&><`$]/;function y(e){throw new Error(e)}function S(e,t){const o=e.trim();o||y("uri is empty");const r=/^[A-Za-z][A-Za-z0-9+.-]*:/.test(o);let n,s;try{n=r?new URL(o):new URL(o.replace(/^\/+/,""),"site://page/")}catch{y(`invalid uri \`${o}\``)}r?(s=`${n.protocol.slice(0,-1).toLowerCase()}://${n.host.toLowerCase()}`,t.has(s)||y(`uri \`${o}\` is not a resource of this page (absolute URIs are limited to the declared ones)`)):"site:"===n.protocol&&"page"===n.host||y(`uri \`${o}\` is not a resource of this page`);const i=[];for(const c of n.pathname.split("/")){if(""===c)continue;let e;try{e=decodeURIComponent(c)}catch{y(`invalid uri \`${o}\``)}(".."===e||"."===e||e.includes("/")||e.includes("\\"))&&y(`uri \`${o}\` is not a resource of this page`),i.push(e)}const a=(s?`${s}/`:"")+i.join("/")+(n.search||"");return{origin:s,segments:i,query:n.searchParams,text:a}}function T(e,t,o){if(e.origin!==t||e.segments.length!==o.length)return;const r={};for(let n=0;n<o.length;n++){const t=e.segments[n];if(t.startsWith("{")&&t.endsWith("}"))r[t.slice(1,-1)]=o[n];else if(t!==o[n])return}return r}function w(e){if(null==e)return"";if("string"==typeof e)return e;try{return JSON.stringify(e,null,2)}catch{return String(e)}}function b(t){if(e.isObject(t)&&"content"in t&&Object.keys(t).every((e=>"content"===e||"version"===e))){const e=t.version;return{text:w(t.content),version:"string"==typeof e?e:void 0===e?void 0:String(e)}}return{text:w(t)}}function E(e,o){if(t.utf8Length(e)<=o)return{text:e,clipped:!1};let r="",n=0;for(const s of e){const e=t.utf8Length(s);if(n+e>o)break;r+=s,n+=e}return{text:r,clipped:!0}}function O(e,o=1,r){const n=e.split("\n"),s=Math.max(1,Math.floor(o));if(s>n.length&&(1!==s||1!==n.length))return`[offset ${s} is past the end: ${n.length} lines]`;const i=void 0===r?n.length:Math.max(1,Math.floor(r)),a=[];let c=0,l=s-1;for(;l<n.length&&a.length<i;l++){const e=t.utf8Length(n[l])+1;if(a.length>0&&c+e>_)break;a.push(n[l]),c+=e}let u=a.join("\n");return 1===a.length&&t.utf8Length(u)>_&&(u=E(u,_).text+" …"),l<n.length&&(u+=`\n[lines ${s}–${l} of ${n.length}; read on with offset=${l+1}]`),u}function A(e){const t=e.trim();if("true"===t)return!0;if("false"===t)return!1;if("null"===t)return null;if(/^-?\d+(\.\d+)?([eE][+-]?\d+)?$/.test(t))return Number(t);if(t.startsWith("{")||t.startsWith("["))try{return JSON.parse(t)}catch{return t}return t}const R=["config","route-config","session-id","session_id","idempotency-key","idempotency_key","confirm-token","confirm_token","trace-id","trace_id"];function I(t){let o,r,n={};const s={},i=[],a=(e,t)=>{try{return JSON.parse(e)}catch(o){y(`invalid \`${t}\` JSON value \`${e}\`: ${o instanceof Error?o.message:String(o)}\nusage: ${g}`)}},c=e=>y(`unsupported flag \`${e}\` (routing and confirmation are the page's)\nusage: ${g}`);for(let e=0;e<t.length;e++){const l=t[e];if("--params"===l){const o=t[++e];void 0===o&&y(`missing value for --params\nusage: ${g}`),n=a(o,"--params")}else if(l.startsWith("--")){const e=l.indexOf("=");e<0&&c(l);const t=l.slice(2,e),o=l.slice(e+1);"params"===t?n=a(o,"--params"):!t.trim()||t.startsWith("-")||R.includes(t)?c(l):s[t]=A(o)}else if(l.includes("=")){const e=l.indexOf("="),t=l.slice(0,e),i=l.slice(e+1);"object"===t?o=i:"action"===t?r=i:"params"===t?n=a(i,"params"):R.includes(t)?c(l):s[t]=A(i)}else i.push(l)}return o=o??i[0],r=r??i[1],void 0!==i[2]&&(n=a(i[2],"params")),i.length>3&&y(`unexpected positional argument \`${i[3]}\`\nusage: ${g}`),Object.keys(s).length&&(e.isObject(n)||y(`key=value params require object params\nusage: ${g}`),n={...n,...s}),o&&r||y(`xcall needs an object and an action\nusage: ${g}`),e.isObject(n)||y(`params must be a JSON object\nusage: ${g}`),{object:o,action:r,params:n}}function $(e,t){var o;const r=[`${e} — ${t.summary}`];t.description&&r.push("",t.description);const n=(t.positionals??[]).map((e=>!1===e.required?`[${e.name}]`:`<${e.name}>`)).join(" ");r.push("",`usage: ${e}${n?` ${n}`:""}${(t.options??[]).length?" [options]":""}`);for(const s of t.positionals??[])r.push(` ${s.name} ${s.description}`);(t.options??[]).length&&r.push("options:");for(const s of t.options??[])r.push(` --${s.name}${"boolean"===s.type?"":` <${s.type}>`}${s.required?" (required)":""} ${s.description}${s.enum?` (${s.enum.join(" | ")})`:""}`);if(null==(o=t.examples)?void 0:o.length){r.push("examples:");for(const e of t.examples)r.push(` ${e}`)}return r.join("\n")}const N=(e,t)=>({type:"object",properties:e,required:t});const M="https://buckyos.org/traits/index@1";function v(t,o){return e.isObject(t)&&"string"==typeof t[o]?t[o]:""}function L(e){const t=h.indexOf(e);return t<0?h.length:t}function k(t,o,r,n){const s=[`Object: ${t}`,`Object DID: ${o.id}`],i=(o.alsoKnownAs??[]).filter((e=>e!==t));i.length&&s.push(`Also known as: ${i.join(", ")}`);for(const[e,c]of[["Title","title"],["Description","description"]]){const t=v(r,c);t&&s.push(`${e}: ${t}`)}for(const[c,l]of[["Properties","properties"],["Actions","actions"],["Events","events"]]){const t=e.isObject(r)?r[l]:void 0;if(e.isObject(t)&&0!==Object.keys(t).length){s.push(`${c}:`);for(const e of Object.keys(t).sort()){const o=t[e];let r=`- ${e}`;const n=v(o,"description");n&&(r+=`: ${n}`);const i=v(o,"x-buckyos:risk");i&&(r+=` (risk: ${i})`),s.push(r)}}}const a=Object.keys(n);if(a.length){s.push("Summary:");for(const e of a)s.push(`- ${e}:`,JSON.stringify(n[e],null,2))}return s.join("\n")}function j(t){const o=e.isObject(t)?t["x-buckyos:traits"]:void 0;return Array.isArray(o)&&o.includes(M)}const C="xllm-runs",D="records",U="snapshots";function H(e){return new Promise(((t,o)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>o(e.error)}))}function P(e){return new Promise(((t,o)=>{e.oncomplete=()=>t(),e.onerror=()=>o(e.error),e.onabort=()=>o(e.error??new Error("transaction aborted"))}))}exports.AiccLlmClient=e.AiccLlmClient,exports.LLMComputeException=e.LLMComputeException,exports.XllmError=e.XllmError,exports.aiccProviderFailure=e.aiccProviderFailure,exports.anyJsonObjectSchema=e.anyJsonObjectSchema,exports.asComputeError=e.asComputeError,exports.charCount=e.charCount,exports.computeErrorMessage=e.computeErrorMessage,exports.errorSource=e.errorSource,exports.infraRetrySafe=e.infraRetrySafe,exports.llmCorrectable=e.llmCorrectable,exports.providerError=e.providerError,exports.providerErrorFromRpc=e.providerErrorFromRpc,exports.rustTrim=e.rustTrim,exports.rustTrimEnd=e.rustTrimEnd,exports.rustTrimStart=e.rustTrimStart,exports.serdeJson=e.serdeJson,exports.AGENT_TOOL_PROTOCOL_VERSION=t.AGENT_TOOL_PROTOCOL_VERSION,exports.ByteHeuristicTokenizer=t.ByteHeuristicTokenizer,exports.DEFAULT_CONTEXT_YIELD_RATIO=t.DEFAULT_CONTEXT_YIELD_RATIO,exports.DEFAULT_LLM_TIMEOUT_SECS=t.DEFAULT_LLM_TIMEOUT_SECS,exports.DEFAULT_MAX_CONSECUTIVE_ERRORS=t.DEFAULT_MAX_CONSECUTIVE_ERRORS,exports.DEFAULT_MAX_TOOL_ITERATIONS=t.DEFAULT_MAX_TOOL_ITERATIONS,exports.DEFAULT_TASK_WAIT_MS=t.DEFAULT_TASK_WAIT_MS,exports.DEFAULT_TIMEOUT_SECS=t.DEFAULT_TIMEOUT_SECS,exports.HINT_NS_DEDUP=t.HINT_NS_DEDUP,exports.HINT_NS_ONCE=t.HINT_NS_ONCE,exports.HOST_PROMPT_SECTIONS_ALL=t.HOST_PROMPT_SECTIONS_ALL,exports.HOST_PROMPT_SECTIONS_NONE=t.HOST_PROMPT_SECTIONS_NONE,exports.LLMContext=t.LLMContext,exports.LLMContextInterruptHandle=t.LLMContextInterruptHandle,exports.LlmSummarizeCompressor=t.LlmSummarizeCompressor,exports.MAX_IMAGE_ATTACHMENT_BYTES=t.MAX_IMAGE_ATTACHMENT_BYTES,exports.MAX_INJECTIONS_PER_BOUNDARY=t.MAX_INJECTIONS_PER_BOUNDARY,exports.MAX_IN_TOOL_WAIT_MS=t.MAX_IN_TOOL_WAIT_MS,exports.MAX_TEXT_ATTACHMENT_BYTES=t.MAX_TEXT_ATTACHMENT_BYTES,exports.MemoryHintLedger=t.MemoryHintLedger,exports.MemoryRunStore=t.MemoryRunStore,exports.REFUSED_CREDENTIALS=t.REFUSED_CREDENTIALS,exports.REPORT_ARTIFACTS_KEY=t.REPORT_ARTIFACTS_KEY,exports.RUNTIME_PROTOCOL_VERSION=t.RUNTIME_PROTOCOL_VERSION,exports.RUN_RECORD_VERSION=t.RUN_RECORD_VERSION,exports.SNAPSHOT_FORMAT_VERSION=t.SNAPSHOT_FORMAT_VERSION,exports.SUMMARIZE_MODEL_ALIAS=t.SUMMARIZE_MODEL_ALIAS,exports.SiteToolManager=t.SiteToolManager,exports.TemplateEnv=t.TemplateEnv,exports.TimeoutLlmClient=t.TimeoutLlmClient,exports.ToolDispatchException=t.ToolDispatchException,exports.XllmActionParser=t.XllmActionParser,exports.XllmInterrupter=t.XllmInterrupter,exports.XllmRun=t.XllmRun,exports.XllmTask=t.XllmTask,exports.XmlStepRenderer=t.XmlStepRenderer,exports.allowAllPolicy=t.allowAllPolicy,exports.applyHints=t.applyHints,exports.asToolResult=t.asToolResult,exports.assemblePrompt=t.assemblePrompt,exports.buildCmdManualSystemText=t.buildCmdManualSystemText,exports.buildRulesSystemText=t.buildRulesSystemText,exports.buildRuntimeProtocol=t.buildRuntimeProtocol,exports.buildRuntimeProtocolFor=t.buildRuntimeProtocolFor,exports.classifyError=t.classifyError,exports.compactionTargetTokens=t.compactionTargetTokens,exports.compress=t.compress,exports.compressHistory=t.compressHistory,exports.compressOptions=t.compressOptions,exports.computeToolsConfig=t.computeToolsConfig,exports.envelopeObservation=t.envelopeObservation,exports.exportRun=t.exportRun,exports.extractResult=t.extractResult,exports.followupGeneralHint=t.followupGeneralHint,exports.followupHint=t.followupHint,exports.generateRunId=t.generateRunId,exports.importRun=t.importRun,exports.inCallWaitMs=t.inCallWaitMs,exports.inFlightCall=t.inFlightCall,exports.isIdempotent=t.isIdempotent,exports.isSummaryMessage=t.isSummaryMessage,exports.isTerminal=t.isTerminal,exports.materializeHistory=t.materializeHistory,exports.mergeConfigLayers=t.mergeConfigLayers,exports.noopWorklog=t.noopWorklog,exports.observationText=t.observationText,exports.parseLlmContextJson=t.parseLlmContextJson,exports.parseReply=t.parseReply,exports.parseSummaryMessage=t.parseSummaryMessage,exports.renderHintBlock=t.renderHintBlock,exports.renderStepHistory=t.renderStepHistory,exports.renderWithHints=t.renderWithHints,exports.reportArtifacts=t.reportArtifacts,exports.resolveToolSpecs=t.resolveToolSpecs,exports.resultView=t.resultView,exports.rewritableHistory=t.rewritableHistory,exports.runRequest=t.runRequest,exports.splitReportResult=t.splitReportResult,exports.stateFromRequest=t.stateFromRequest,exports.summaryMessage=t.summaryMessage,exports.summaryModel=t.summaryModel,exports.taskStateObservation=t.taskStateObservation,exports.toHost=t.toHost,exports.toolResultViewFromHost=t.toolResultViewFromHost,exports.unresolvedReason=t.unresolvedReason,exports.validateJson=t.validateJson,exports.waitUntilMs=t.waitUntilMs,exports.DIDObjectClient=o.DIDObjectClient,exports.DIDObjectError=o.DIDObjectError,exports.ACTION_RISKS=h,exports.INDEX_TRAIT_URI=M,exports.IndexedDbRunStore=class{constructor(e={}){this.options=e,this.persistent=!0,this.localLocks=new Set}open(){if(!this.db){const t=this.options.idb??globalThis.indexedDB;if(!t)return Promise.reject(e.XllmError.storage("IndexedDB is not available here"));const o=t.open(this.options.dbName??C,1);o.onupgradeneeded=()=>{const e=o.result;e.objectStoreNames.contains(D)||e.createObjectStore(D,{keyPath:"run_id"}),e.objectStoreNames.contains(U)||e.createObjectStore(U)},this.db=H(o)}return this.db}locks(){var e;if(null!==this.options.locks)return this.options.locks??(null==(e=globalThis.navigator)?void 0:e.locks)}runsDir(){}runDir(){}async createRun(){const o=await this.open();for(let e=0;e<8;e++){const e=t.generateRunId();if(!(await H(o.transaction(D).objectStore(D).get(e))))return e}throw e.XllmError.storage("cannot allocate a unique run id")}async writeRecord(e){const t=(await this.open()).transaction(D,"readwrite");t.objectStore(D).put(JSON.parse(JSON.stringify(e))),await P(t)}async readRecord(o){const r=await this.open(),n=await H(r.transaction(D).objectStore(D).get(o));if(!n)throw new e.XllmError({kind:"run_not_found",run_id:o,runs_dir:`indexeddb:${this.options.dbName??C}`});if(n.version!==t.RUN_RECORD_VERSION)throw e.XllmError.notResumable(o,"unsupported run record version");return n}async listRecords(){const e=await this.open();return await H(e.transaction(D).objectStore(D).getAll())}async putSnapshot(e,t){const o=(await this.open()).transaction(U,"readwrite"),r=o.objectStore(U),n=await H(r.getAllKeys(IDBKeyRange.bound([e,0],[e,Number.MAX_SAFE_INTEGER]))),s=n.length?Math.max(...n.map((e=>e[1])))+1:1;return r.put(JSON.parse(JSON.stringify(t)),[e,s]),await P(o),s}async getSnapshot(t,o){const r=await this.open(),n=await H(r.transaction(U).objectStore(U).get([t,o]));if(!n)throw new e.XllmError({kind:"corrupted_run",run_id:t,reason:`snapshot ${o} missing`});return n}async listSnapshots(e){const t=await this.open();return(await H(t.transaction(U).objectStore(U).getAllKeys(IDBKeyRange.bound([e,0],[e,Number.MAX_SAFE_INTEGER])))).map((e=>e[1])).sort(((e,t)=>e-t))}async lockRun(e){const t=`xllm-run:${e}`,o=this.locks();return o?new Promise(((e,r)=>{o.request(t,{ifAvailable:!0},(t=>t?new Promise((t=>e({release:()=>t()}))):(e(null),Promise.resolve()))).catch(r)})):this.localLocks.has(t)?null:(this.localLocks.add(t),{release:()=>{this.localLocks.delete(t)}})}async isRunLive(e){const t=`xllm-run:${e}`,o=this.locks();if(!o)return this.localLocks.has(t);return((await o.query()).held??[]).some((e=>e.name===t))}async removeRun(e){const t=(await this.open()).transaction([D,U],"readwrite");t.objectStore(D).delete(e),t.objectStore(U).delete(IDBKeyRange.bound([e,0],[e,Number.MAX_SAFE_INTEGER])),await P(t)}async importRun(e){const t=(await this.open()).transaction([D,U],"readwrite");t.objectStore(D).put(JSON.parse(JSON.stringify(e.record)));for(const[o,r]of e.snapshots)t.objectStore(U).put(JSON.parse(JSON.stringify(r)),[e.record.run_id,o]);await P(t)}},exports.MAX_RESULT_BYTES=_,exports.SITE_RUNTIME_KIND=r,exports.XCALL_USAGE=g,exports.XLLM_RUNS_DB=C,exports.createSiteRuntime=function(o){var i;const a=null==(i=o.scene)?void 0:i.trim();if(!a)throw e.XllmError.input("createSiteRuntime: `scene` is required");if(!o.origin)throw e.XllmError.input("createSiteRuntime: `origin` is required");const c=new Map;for(const[t,r]of Object.entries(o.tools??{})){if(!n.test(t))throw e.XllmError.tools(`site tool name \`${t}\` must match ${n}`);if(!r||"function"!=typeof r.call||!r.spec)throw e.XllmError.tools(`site tool \`${t}\` needs \`spec\` and \`call\``);c.set(t,r)}const l={...o.env??{}},u={runtime_id:`site:${a}`,kind:r,host:null,target:{origin:o.origin,scene:a},workdir:"/",capabilities:{tools:{},network:!0,os:"browser"}},p={kind:r,env:{}};return void 0!==o.task_wait_ms&&(p.task_wait_ms=o.task_wait_ms),{scene:a,tools:c,descriptor:()=>JSON.parse(JSON.stringify(u)),config:()=>JSON.parse(JSON.stringify(p)),async info(){let e="";try{e=Intl.DateTimeFormat().resolvedOptions().timeZone??""}catch{e=""}return{id:u.runtime_id,kind:r,os:"browser",arch:"",hostname:o.hostname,shell:"",cwd:"/",tools:[],current_time:(new Date).toISOString(),timezone:e,target:u.target,platform:"browser",shell_kind:"",baseline:""}},async open(o,r){const n=r.enabled??!1,i=r.tools2actions??!1;if("function_call"===o.loop_model&&(i||(r.actions??[]).length>0))throw e.XllmError.capability("actions / tools2actions need loop_model behavior");const l=(t,o)=>t.map((t=>{const r=c.get(t);if(!r)throw e.XllmError.capability(`${o}: \`${t}\` is not a tool of scene \`${a}\` (scene tools: ${[...c.keys()].join(", ")||"none"})`);return function(e,t,o){return{name:e,description:t.spec.description,args_schema:t.spec.args_schema,source:o}}(t,r,`name:${t}`)}));let u=[],d=[];const m=r.tools??[],f=r.actions??[];if(n){u=l(void 0===r.tools?[...c.keys()]:s(r.tools,"tools.tools"),"tools.tools"),d=l(s(r.actions,"tools.actions"),"tools.actions"),i&&(d=[...d,...u.filter((e=>!d.some((t=>t.name===e.name))))],u=[])}const h=new Map;for(const e of[...u,...d])h.set(e.name,c.get(e.name));return{tools:{enabled:n,filesystem_policy:r.filesystem_policy??"workspace",tools2actions:i,tool_sources:void 0===r.tools&&n?u.map((e=>({kind:"named",name:e.name}))):m,action_sources:f,native:u,actions:d,bash_tools:[],shell:t.shellSettings(r.shell,t.taskWaitMs(p)),exec_enabled:!1,sources:{...o.sources}},manager:new t.SiteToolManager(h,{tasks:o.tasks,taskWaitMs:o.task_wait_ms})}},async describeInterrupted(e,o){const r=c.get(o.name);if(null==r?void 0:r.describeInterrupted)try{return await r.describeInterrupted(o.args??{},{run_id:e.run_id,call_id:o.call_id,signal:(new AbortController).signal})}catch(n){return`${t.unresolvedReason(o.name)} (describing it failed: ${n instanceof Error?n.message:String(n)})`}return t.unresolvedReason(o.name)},env:e=>l[e]}},exports.didObjectResources=async function(t){const o=L(t.maxRisk??"read_only"),r={};for(const n of t.roots){const s=t.client,i=await s.profile(n),a=j(i),c={},l=e.isObject(i)&&e.isObject(i.actions)?i.actions:{};for(const[t,r]of Object.entries(l)){if(a&&("query"===t||"page"===t))continue;const i=v(r,"x-buckyos:risk");if(L(i)>o)continue;const l=e.isObject(r)?r.input:void 0;c[t]={description:v(r,"description"),risk:i,...null!=l?{input:l}:{},call:(e,o)=>s.invoke(n,t,o)}}const u=[v(i,"title"),v(i,"description")].filter(Boolean).join(" — ")||n;r[n]={description:a?`${u} (a collection: read it with a query, ?cursor=… for the next page)`:u,actions:c,async read(t){if(a&&[...t.query.keys()].length>0){const e=t.query.get("cursor"),o=t.query.get("page_size");if(e)return s.invoke(n,"page",{cursor:e,...o?{page_size:Number(o)}:{}});const r={};for(const[n,s]of t.query)"page_size"!==n&&(r[n]=s);return s.invoke(n,"query",{query:r,...o?{page_size:Number(o)}:{}})}const o=await s.card(n),r=e.isObject(i)&&e.isObject(i.properties)?Object.keys(i.properties).filter((e=>"index_schema"!==e)):[],c=e.isObject(i)&&Array.isArray(i["x-buckyos:summary_props"])?i["x-buckyos:summary_props"].filter((e=>"string"==typeof e)):r,l={};for(const e of c)l[e]=await s.readProperty(n,e);return k(n,{id:String(o.id),alsoKnownAs:o.alsoKnownAs},i,l)}}}return r},exports.normalizeUri=S,exports.pageText=O,exports.renderObjectDocument=k,exports.siteTools=function(e){const o=Object.entries(e.resources??{}).map((([e,t])=>function(e,t){const o=e.indexOf("://");if(o>=0){const r=e.slice(o+3),n=r.indexOf("/"),s=n<0?r:r.slice(0,n),i=n<0?"":r.slice(n+1);return{raw:e,origin:`${e.slice(0,o).toLowerCase()}://${s.toLowerCase()}`,segments:i?i.split("/"):[],decl:t}}const r=e.replace(/^\/+/,"").replace(/\/+$/,"");return{raw:e,segments:r?r.split("/"):[],decl:t}}(e,t))),r=new Set(o.map((e=>e.origin)).filter((e=>void 0!==e))),n=new Map(Object.entries(e.commands??{}));if(n.has("xcall"))throw new Error("siteTools: `xcall` is built in; declare actions on resources instead");const s=(e,t)=>{const n=S(e,r);for(const r of o){const e=T(r,n.origin,n.segments);if(e)return{uri:n.text,pattern:r.raw,params:e,query:n.query,ctx:t,decl:r.decl}}y(`uri \`${e}\` is not a resource of this page; read uri="/" lists them`)},h=async(e,o)=>{var r;const h=(()=>{try{return m(e)}catch(t){y(`${t instanceof Error?t.message:String(t)}; exec runs one command, it is not a shell`)}})(),S="available commands: xcall"+(n.size?`, ${[...n.keys()].join(", ")}`:""),T=e.replace(/'[^']*'|"(?:[^"\\]|\\.)*"/g,"");x.test(T)&&y(`exec runs exactly one command and is not a shell: pipes, redirects, \`;\`, \`&\`, backquotes and \`$\` are not supported (quote them to pass them as text). ${S}`);const[b,...O]=h;if(b||y(`empty command; ${S}`),"xcall"===b){if(O.includes("--help")||O.includes("-h"))return`usage: ${g}\nThe actions of each resource are listed by read uri="/".`;const{object:e,action:n,params:i}=I(O),a=s(e,o),c=null==(r=a.decl.actions)?void 0:r[n];if(!c){const e=Object.keys(a.decl.actions??{});y(`resource \`${a.pattern}\` has no action \`${n}\` (actions: ${e.length?e.join(", "):"none"})`)}if(void 0!==c.input){const e=t.validateJson(c.input,i);e&&y(`invalid params for ${n}: ${e}`)}const{decl:l,...u}=a,p=await c.call(u,i);return`[risk: ${c.risk}]\n${E(w(p)||"ok",_).text}`}const A=n.get(b);let R;A||y(`unknown command \`${b}\`; exec runs one command, it is not a shell. ${S}`);try{const e=function(e,t,o){const r={},n=e.positionals??[],s=new Map((e.options??[]).map((e=>[e.name,e])));let m=0,f=!1;for(let h=0;h<t.length;){const e=t[h];if("--help"===e||"-h"===e){f=!0,h+=1;continue}if("--"===e){for(const e of t.slice(h+1))m=d(r,n,m,e);break}if(!e.startsWith("--")){m=d(r,n,m,e),h+=1;continue}const g=l(e),_=null==o?void 0:o(g,t,h);if(void 0!==_){h+=_;continue}const x=s.get(g.name);if(!x)throw new i("UNKNOWN_OPTION",`unknown option: --${g.name}`);const y=c(x);if(a(r,y))throw new i("DUPLICATE_ARGUMENT",`argument provided more than once: ${y}`);if("boolean"===x.type){if(void 0!==g.inlineValue)throw new i("INVALID_ARGUMENT",`--${g.name} does not accept a value`);r[y]=!0,h+=1;continue}const{value:S,consumed:T}=u(t,h,g);r[y]=p(x.type,S,g.name),h+=T}return{input:r,help:f,positionalCount:m}}({positionals:A.positionals,options:A.options},O);if(e.help)return $(b,A);for(let t=e.positionalCount;t<(A.positionals??[]).length;t++)if(!1!==(A.positionals??[])[t].required)throw new i("MISSING_ARGUMENT",`missing positional argument: ${(A.positionals??[])[t].name}`);for(const t of A.options??[]){const o=t.property??t.name.split("-").join("_");if(t.required&&!(o in e.input))throw new i("MISSING_ARGUMENT",`--${t.name} is required`)}R=e.input,A.inputSchema&&f(R,A.inputSchema,"input")}catch(N){throw N instanceof i&&y(`${b}: ${N.message}\n\n${$(b,A)}`),N}return E(w(await A.call(R,o))||"ok",_).text};return{read:{spec:{description:'Read a resource of this page by URI (GET). Start with uri "/": it lists the resources, their actions (with risk) and the commands. A collection\'s read is its list; filter and page with a query (notes?tag=x). Text comes in pages of lines: offset is the first line (1-based), limit the number of lines.',args_schema:N({uri:{type:"string",description:'Resource URI, e.g. "/" or "notes/1"'},offset:{type:"integer",description:"First line, 1-based"},limit:{type:"integer",description:"Number of lines"}},["uri"])},idempotent:!0,async call(e,t){const r=String(e.uri),i="number"==typeof e.offset?e.offset:void 0,a="number"==typeof e.limit?e.limit:void 0;if("/"===r.trim()||""===r.trim())return O((()=>{const e=['Resources (read uri="<resource>"; {name} is one path segment):'];for(const t of o){const o=["read","write","edit"].filter((e=>"edit"===e?!!(t.decl.edit||t.decl.read&&t.decl.write):!!t.decl[e]));e.push(`- ${t.raw} — ${t.decl.description} [${o.join(", ")||"no methods"}]`);for(const[r,n]of Object.entries(t.decl.actions??{}))e.push(` action ${r} (risk: ${n.risk}) — ${n.description}`)}0===o.length&&e.push("(none)"),e.push("",'Commands (exec "<command> --help" for usage):'),e.push(`- xcall — call an action of a resource: ${g}`);for(const[t,o]of n)e.push(`- ${t} — ${o.summary}`);return e.join("\n")})(),i,a);return O((await(async e=>{e.decl.read||y(`resource \`${e.pattern}\` cannot be read`);const{decl:t,...o}=e;return b(await e.decl.read(o))})(s(r,t))).text,i,a)}},write:{spec:{description:'Write a resource\'s content (PUT). mode: "write" (default) replaces it, "new" only creates it and fails if it exists, "append" adds to its end. Use edit to change part of it.',args_schema:N({uri:{type:"string",description:"Resource URI"},content:{type:"string",description:"The content"},mode:{type:"string",enum:["write","new","append"],description:"write | new | append"}},["uri","content"])},async call(e,t){const o=s(String(e.uri),t);o.decl.write||y(`resource \`${o.pattern}\` is read-only`);const{decl:r,...n}=o,i="string"==typeof e.mode?e.mode:"write";return w(await r.write(n,{content:String(e.content),mode:i}))||"written"}},edit:{spec:{description:"Change part of a resource (PATCH): old_string must occur exactly once in its current content and is replaced by new_string.",args_schema:N({uri:{type:"string",description:"Resource URI"},old_string:{type:"string",description:"Text to replace; must occur exactly once"},new_string:{type:"string",description:"Replacement text"}},["uri","old_string","new_string"])},async call(e,t){const o=s(String(e.uri),t),r={old_string:String(e.old_string),new_string:String(e.new_string)},{decl:n,...i}=o;if(n.edit)return w(await n.edit(i,r))||"edited";n.read&&n.write||y(`resource \`${o.pattern}\` cannot be edited`),r.old_string||y("old_string is empty");const a=b(await n.read(i)),c=a.text.split(r.old_string).length-1;0===c&&y("old_string was not found in the current content; read it again"),c>1&&y(`old_string occurs ${c} times; give more context so it occurs exactly once`);const l={content:a.text.replace(r.old_string,(()=>r.new_string)),mode:"write"};return void 0!==a.version&&(l.ifVersion=a.version),w(await n.write(i,l))||"edited"}},exec:{spec:{description:`Run one command (not a shell: no pipes, redirects, ;, &, backquotes or $). Built in: ${g} — calls an action listed by read uri="/". The page's commands are listed there too; "<command> --help" shows a command's usage.`,args_schema:N({command:{type:"string",description:"One command line"}},["command"])},idempotent:e=>function(e,t,o,r){var n,s,i;let a;try{a=m(e)}catch{return!1}const[c,...l]=a;if("xcall"===c)try{const{object:e,action:r}=I(l),i=S(e,o),a=t.find((e=>T(e,i.origin,i.segments))),c=null==(s=null==(n=null==a?void 0:a.decl.actions)?void 0:n[r])?void 0:s.risk;return"read_only"===c||"idempotent_write"===c}catch{return!1}const u=c?r.get(c):void 0;return"read"===(null==(i=null==u?void 0:u.access)?void 0:i.level)}(String(e.command??""),o,r,n),call:(e,t)=>h(String(e.command),t)}}};
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./aicc-ccb36ef7.js"),t=require("./site_manager-70710895.js"),o=require("./did_object_client-27835522.js");require("./krpc_client-26c2dc8b.js"),require("./object_url-88047ee2.js"),require("./ndn_types-5b138882.js");const r="site",n=/^[A-Za-z0-9_-]{1,64}$/;function s(o,r){return(o??[]).map((o=>{if("named"!==o.kind)throw e.XllmError.capability(`${r}: \`${t.describeToolSource(o)}\` is not available in a site runtime; only the page's tools can be named`);return o.name}))}class i extends Error{constructor(e,t){super(t),this.name="CommandArgsError",this.code=e}}function a(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function c(e){return e.property??e.name.split("-").join("_")}function l(e){const t=e.slice(2),o=t.indexOf("=");return o<0?{name:t}:{name:t.slice(0,o),inlineValue:t.slice(o+1)}}function u(e,t,o){if(void 0!==o.inlineValue){if(!o.inlineValue)throw new i("MISSING_ARGUMENT",`--${o.name} requires a value`);return{value:o.inlineValue,consumed:1}}const r=e[t+1];if(void 0===r||r.startsWith("--"))throw new i("MISSING_ARGUMENT",`--${o.name} requires a value`);return{value:r,consumed:2}}function p(e,t,o){if("string"===e)return t;const r=Number(t);if(!Number.isFinite(r)||"integer"===e&&!Number.isInteger(r))throw new i("INVALID_ARGUMENT",`--${o} requires a ${e}`);return r}function d(e,t,o,r){const n=t[o];if(!n)throw new i("TOO_MANY_ARGUMENTS",`unexpected positional argument: ${r}`);return e[n.name]=r,o+1}function m(e){const t=[];let o="",r=null,n=!1,s=!1;for(const i of e)n?(o+=i,n=!1,s=!0):"\\"!==i||"single"===r?"single"!==r?"double"!==r?"'"!==i?'"'!==i?/\s/.test(i)?s&&(t.push(o),o="",s=!1):(o+=i,s=!0):(r="double",s=!0):(r="single",s=!0):'"'===i?r=null:o+=i:"'"===i?r=null:o+=i:(n=!0,s=!0);if(n)throw new i("INVALID_COMMAND_LINE","unfinished escape sequence");if(r)throw new i("INVALID_COMMAND_LINE",`unterminated ${r} quote`);return s&&t.push(o),t}function f(e,t,o){var r;if(t.enum&&!t.enum.some((t=>Object.is(t,e))))throw new i("SCHEMA_VALIDATION_FAILED",`${o} must be one of ${t.enum.join(", ")}`);if("object"!==t.type)if("array"!==t.type)if("string"!==t.type){if("boolean"===t.type&&"boolean"!=typeof e)throw new i("SCHEMA_VALIDATION_FAILED",`${o} must be a boolean`);if("integer"===t.type&&(!Number.isInteger(e)||"number"!=typeof e))throw new i("SCHEMA_VALIDATION_FAILED",`${o} must be an integer`);if("number"===t.type&&"number"!=typeof e)throw new i("SCHEMA_VALIDATION_FAILED",`${o} must be a number`)}else{if("string"!=typeof e)throw new i("SCHEMA_VALIDATION_FAILED",`${o} must be a string`);if(void 0!==t.minLength&&e.length<t.minLength)throw new i("SCHEMA_VALIDATION_FAILED",`${o} is too short`)}else{if(!Array.isArray(e))throw new i("SCHEMA_VALIDATION_FAILED",`${o} must be an array`);const r=t.items;r&&e.forEach(((e,t)=>f(e,r,`${o}[${t}]`)))}else{if(!e||"object"!=typeof e||Array.isArray(e))throw new i("SCHEMA_VALIDATION_FAILED",`${o} must be an object`);const n=e;for(const e of t.required??[])if(!a(n,e))throw new i("SCHEMA_VALIDATION_FAILED",`${o}.${e} is required`);if(!1===t.additionalProperties)for(const e of Object.keys(n))if(!a(t.properties??{},e))throw new i("SCHEMA_VALIDATION_FAILED",`${o}.${e} is not allowed`);for(const[e,s]of Object.entries(n)){const n=null==(r=t.properties)?void 0:r[e];n&&f(s,n,`${o}.${e}`)}}}const g=["read_only","idempotent_write","write","destructive","admin"],h="xcall <object> <action> [--params <json>] [key=value ...] [--key=value ...]",_=65536,x=/[|;&><`$]/;function y(e){throw new Error(e)}function T(e,t){const o=e.trim();o||y("uri is empty");const r=/^[A-Za-z][A-Za-z0-9+.-]*:/.test(o);let n,s;try{n=r?new URL(o):new URL(o.replace(/^\/+/,""),"site://page/")}catch{y(`invalid uri \`${o}\``)}r?(s=`${n.protocol.slice(0,-1).toLowerCase()}://${n.host.toLowerCase()}`,t.has(s)||y(`uri \`${o}\` is not a resource of this page (absolute URIs are limited to the declared ones)`)):"site:"===n.protocol&&"page"===n.host||y(`uri \`${o}\` is not a resource of this page`);const i=[];for(const c of n.pathname.split("/")){if(""===c)continue;let e;try{e=decodeURIComponent(c)}catch{y(`invalid uri \`${o}\``)}(".."===e||"."===e||e.includes("/")||e.includes("\\"))&&y(`uri \`${o}\` is not a resource of this page`),i.push(e)}const a=(s?`${s}/`:"")+i.join("/")+(n.search||"");return{origin:s,segments:i,query:n.searchParams,text:a}}function S(e,t,o){if(e.origin!==t||e.segments.length!==o.length)return;const r={};for(let n=0;n<o.length;n++){const t=e.segments[n];if(t.startsWith("{")&&t.endsWith("}"))r[t.slice(1,-1)]=o[n];else if(t!==o[n])return}return r}function E(e){if(null==e)return"";if("string"==typeof e)return e;try{return JSON.stringify(e,null,2)}catch{return String(e)}}function w(t){if(e.isObject(t)&&"content"in t&&Object.keys(t).every((e=>"content"===e||"version"===e))){const e=t.version;return{text:E(t.content),version:"string"==typeof e?e:void 0===e?void 0:String(e)}}return{text:E(t)}}function b(e,o){if(t.utf8Length(e)<=o)return{text:e,clipped:!1};let r="",n=0;for(const s of e){const e=t.utf8Length(s);if(n+e>o)break;r+=s,n+=e}return{text:r,clipped:!0}}function O(e,o=1,r){const n=e.split("\n"),s=Math.max(1,Math.floor(o));if(s>n.length&&(1!==s||1!==n.length))return`[offset ${s} is past the end: ${n.length} lines]`;const i=void 0===r?n.length:Math.max(1,Math.floor(r)),a=[];let c=0,l=s-1;for(;l<n.length&&a.length<i;l++){const e=t.utf8Length(n[l])+1;if(a.length>0&&c+e>_)break;a.push(n[l]),c+=e}let u=a.join("\n");return 1===a.length&&t.utf8Length(u)>_&&(u=b(u,_).text+" …"),l<n.length&&(u+=`\n[lines ${s}–${l} of ${n.length}; read on with offset=${l+1}]`),u}function A(e){const t=e.trim();if("true"===t)return!0;if("false"===t)return!1;if("null"===t)return null;if(/^-?\d+(\.\d+)?([eE][+-]?\d+)?$/.test(t))return Number(t);if(t.startsWith("{")||t.startsWith("["))try{return JSON.parse(t)}catch{return t}return t}const R=["config","route-config","session-id","session_id","idempotency-key","idempotency_key","confirm-token","confirm_token","trace-id","trace_id"];function I(t){let o,r,n={};const s={},i=[],a=(e,t)=>{try{return JSON.parse(e)}catch(o){y(`invalid \`${t}\` JSON value \`${e}\`: ${o instanceof Error?o.message:String(o)}\nusage: ${h}`)}},c=e=>y(`unsupported flag \`${e}\` (routing and confirmation are the page's)\nusage: ${h}`);for(let e=0;e<t.length;e++){const l=t[e];if("--params"===l){const o=t[++e];void 0===o&&y(`missing value for --params\nusage: ${h}`),n=a(o,"--params")}else if(l.startsWith("--")){const e=l.indexOf("=");e<0&&c(l);const t=l.slice(2,e),o=l.slice(e+1);"params"===t?n=a(o,"--params"):!t.trim()||t.startsWith("-")||R.includes(t)?c(l):s[t]=A(o)}else if(l.includes("=")){const e=l.indexOf("="),t=l.slice(0,e),i=l.slice(e+1);"object"===t?o=i:"action"===t?r=i:"params"===t?n=a(i,"params"):R.includes(t)?c(l):s[t]=A(i)}else i.push(l)}return o=o??i[0],r=r??i[1],void 0!==i[2]&&(n=a(i[2],"params")),i.length>3&&y(`unexpected positional argument \`${i[3]}\`\nusage: ${h}`),Object.keys(s).length&&(e.isObject(n)||y(`key=value params require object params\nusage: ${h}`),n={...n,...s}),o&&r||y(`xcall needs an object and an action\nusage: ${h}`),e.isObject(n)||y(`params must be a JSON object\nusage: ${h}`),{object:o,action:r,params:n}}function $(e,t){var o;const r=[`${e} — ${t.summary}`];t.description&&r.push("",t.description);const n=(t.positionals??[]).map((e=>!1===e.required?`[${e.name}]`:`<${e.name}>`)).join(" ");r.push("",`usage: ${e}${n?` ${n}`:""}${(t.options??[]).length?" [options]":""}`);for(const s of t.positionals??[])r.push(` ${s.name} ${s.description}`);(t.options??[]).length&&r.push("options:");for(const s of t.options??[])r.push(` --${s.name}${"boolean"===s.type?"":` <${s.type}>`}${s.required?" (required)":""} ${s.description}${s.enum?` (${s.enum.join(" | ")})`:""}`);if(null==(o=t.examples)?void 0:o.length){r.push("examples:");for(const e of t.examples)r.push(` ${e}`)}return r.join("\n")}const N=(e,t)=>({type:"object",properties:e,required:t});const M="https://buckyos.org/traits/index@1";function L(t,o){return e.isObject(t)&&"string"==typeof t[o]?t[o]:""}function v(e){const t=g.indexOf(e);return t<0?g.length:t}function k(t,o,r,n){const s=[`Object: ${t}`,`Object DID: ${o.id}`],i=(o.alsoKnownAs??[]).filter((e=>e!==t));i.length&&s.push(`Also known as: ${i.join(", ")}`);for(const[e,c]of[["Title","title"],["Description","description"]]){const t=L(r,c);t&&s.push(`${e}: ${t}`)}for(const[c,l]of[["Properties","properties"],["Actions","actions"],["Events","events"]]){const t=e.isObject(r)?r[l]:void 0;if(e.isObject(t)&&0!==Object.keys(t).length){s.push(`${c}:`);for(const e of Object.keys(t).sort()){const o=t[e];let r=`- ${e}`;const n=L(o,"description");n&&(r+=`: ${n}`);const i=L(o,"x-buckyos:risk");i&&(r+=` (risk: ${i})`),s.push(r)}}}const a=Object.keys(n);if(a.length){s.push("Summary:");for(const e of a)s.push(`- ${e}:`,JSON.stringify(n[e],null,2))}return s.join("\n")}function j(t){const o=e.isObject(t)?t["x-buckyos:traits"]:void 0;return Array.isArray(o)&&o.includes(M)}const C="xllm-runs",D="records",U="snapshots";function H(e){return new Promise(((t,o)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>o(e.error)}))}function P(e){return new Promise(((t,o)=>{e.oncomplete=()=>t(),e.onerror=()=>o(e.error),e.onabort=()=>o(e.error??new Error("transaction aborted"))}))}exports.AiccLlmClient=e.AiccLlmClient,exports.LLMComputeException=e.LLMComputeException,exports.XllmError=e.XllmError,exports.aiccProviderFailure=e.aiccProviderFailure,exports.anyJsonObjectSchema=e.anyJsonObjectSchema,exports.asComputeError=e.asComputeError,exports.charCount=e.charCount,exports.computeErrorMessage=e.computeErrorMessage,exports.errorSource=e.errorSource,exports.infraRetrySafe=e.infraRetrySafe,exports.llmCorrectable=e.llmCorrectable,exports.providerError=e.providerError,exports.providerErrorFromRpc=e.providerErrorFromRpc,exports.rustTrim=e.rustTrim,exports.rustTrimEnd=e.rustTrimEnd,exports.rustTrimStart=e.rustTrimStart,exports.serdeJson=e.serdeJson,exports.AGENT_TOOL_PROTOCOL_VERSION=t.AGENT_TOOL_PROTOCOL_VERSION,exports.ByteHeuristicTokenizer=t.ByteHeuristicTokenizer,exports.DEFAULT_CONTEXT_YIELD_RATIO=t.DEFAULT_CONTEXT_YIELD_RATIO,exports.DEFAULT_LLM_TIMEOUT_SECS=t.DEFAULT_LLM_TIMEOUT_SECS,exports.DEFAULT_MAX_CONSECUTIVE_ERRORS=t.DEFAULT_MAX_CONSECUTIVE_ERRORS,exports.DEFAULT_MAX_TOOL_ITERATIONS=t.DEFAULT_MAX_TOOL_ITERATIONS,exports.DEFAULT_TASK_WAIT_MS=t.DEFAULT_TASK_WAIT_MS,exports.DEFAULT_TIMEOUT_SECS=t.DEFAULT_TIMEOUT_SECS,exports.HINT_NS_DEDUP=t.HINT_NS_DEDUP,exports.HINT_NS_ONCE=t.HINT_NS_ONCE,exports.HOST_PROMPT_SECTIONS_ALL=t.HOST_PROMPT_SECTIONS_ALL,exports.HOST_PROMPT_SECTIONS_NONE=t.HOST_PROMPT_SECTIONS_NONE,exports.LLMContext=t.LLMContext,exports.LLMContextInterruptHandle=t.LLMContextInterruptHandle,exports.LlmSummarizeCompressor=t.LlmSummarizeCompressor,exports.MAX_IMAGE_ATTACHMENT_BYTES=t.MAX_IMAGE_ATTACHMENT_BYTES,exports.MAX_INJECTIONS_PER_BOUNDARY=t.MAX_INJECTIONS_PER_BOUNDARY,exports.MAX_IN_TOOL_WAIT_MS=t.MAX_IN_TOOL_WAIT_MS,exports.MAX_TEXT_ATTACHMENT_BYTES=t.MAX_TEXT_ATTACHMENT_BYTES,exports.MemoryHintLedger=t.MemoryHintLedger,exports.MemoryRunStore=t.MemoryRunStore,exports.REFUSED_CREDENTIALS=t.REFUSED_CREDENTIALS,exports.REPORT_ARTIFACTS_KEY=t.REPORT_ARTIFACTS_KEY,exports.RESULT_BUDGET_TOKENS=t.RESULT_BUDGET_TOKENS,exports.RUNTIME_PROTOCOL_VERSION=t.RUNTIME_PROTOCOL_VERSION,exports.RUN_RECORD_VERSION=t.RUN_RECORD_VERSION,exports.SNAPSHOT_FORMAT_VERSION=t.SNAPSHOT_FORMAT_VERSION,exports.SUMMARIZE_MODEL_ALIAS=t.SUMMARIZE_MODEL_ALIAS,exports.SiteToolManager=t.SiteToolManager,exports.TemplateEnv=t.TemplateEnv,exports.TimeoutLlmClient=t.TimeoutLlmClient,exports.ToolDispatchException=t.ToolDispatchException,exports.XllmActionParser=t.XllmActionParser,exports.XllmInterrupter=t.XllmInterrupter,exports.XllmRun=t.XllmRun,exports.XllmTask=t.XllmTask,exports.XmlStepRenderer=t.XmlStepRenderer,exports.allowAllPolicy=t.allowAllPolicy,exports.applyHints=t.applyHints,exports.asToolResult=t.asToolResult,exports.assemblePrompt=t.assemblePrompt,exports.buildCmdManualSystemText=t.buildCmdManualSystemText,exports.buildRulesSystemText=t.buildRulesSystemText,exports.buildRuntimeProtocol=t.buildRuntimeProtocol,exports.buildRuntimeProtocolFor=t.buildRuntimeProtocolFor,exports.classifyError=t.classifyError,exports.clipToBudget=t.clipToBudget,exports.clipToDefaultBudget=t.clipToDefaultBudget,exports.compactionTargetTokens=t.compactionTargetTokens,exports.compress=t.compress,exports.compressHistory=t.compressHistory,exports.compressOptions=t.compressOptions,exports.computeToolsConfig=t.computeToolsConfig,exports.dedupText=t.dedupText,exports.envelopeObservation=t.envelopeObservation,exports.exportRun=t.exportRun,exports.extractResult=t.extractResult,exports.fitResultBudget=t.fitResultBudget,exports.followupGeneralHint=t.followupGeneralHint,exports.followupHint=t.followupHint,exports.fullText=t.fullText,exports.generateRunId=t.generateRunId,exports.importRun=t.importRun,exports.inCallWaitMs=t.inCallWaitMs,exports.inFlightCall=t.inFlightCall,exports.isIdempotent=t.isIdempotent,exports.isSummaryMessage=t.isSummaryMessage,exports.isTerminal=t.isTerminal,exports.materializeHistory=t.materializeHistory,exports.mergeConfigLayers=t.mergeConfigLayers,exports.noopWorklog=t.noopWorklog,exports.observationText=t.observationText,exports.parseLlmContextJson=t.parseLlmContextJson,exports.parseReply=t.parseReply,exports.parseSummaryMessage=t.parseSummaryMessage,exports.renderHintBlock=t.renderHintBlock,exports.renderStepHistory=t.renderStepHistory,exports.renderWithHints=t.renderWithHints,exports.reportArtifacts=t.reportArtifacts,exports.resolveToolSpecs=t.resolveToolSpecs,exports.resultView=t.resultView,exports.rewritableHistory=t.rewritableHistory,exports.runRequest=t.runRequest,exports.splitReportResult=t.splitReportResult,exports.stateFromRequest=t.stateFromRequest,exports.summaryMessage=t.summaryMessage,exports.summaryModel=t.summaryModel,exports.taskStateObservation=t.taskStateObservation,exports.toHost=t.toHost,exports.toolResultViewFromHost=t.toolResultViewFromHost,exports.unresolvedReason=t.unresolvedReason,exports.validateJson=t.validateJson,exports.waitUntilMs=t.waitUntilMs,exports.DIDObjectClient=o.DIDObjectClient,exports.DIDObjectError=o.DIDObjectError,exports.ACTION_RISKS=g,exports.INDEX_TRAIT_URI=M,exports.IndexedDbRunStore=class{constructor(e={}){this.options=e,this.persistent=!0,this.localLocks=new Set}open(){if(!this.db){const t=this.options.idb??globalThis.indexedDB;if(!t)return Promise.reject(e.XllmError.storage("IndexedDB is not available here"));const o=t.open(this.options.dbName??C,1);o.onupgradeneeded=()=>{const e=o.result;e.objectStoreNames.contains(D)||e.createObjectStore(D,{keyPath:"run_id"}),e.objectStoreNames.contains(U)||e.createObjectStore(U)},this.db=H(o)}return this.db}locks(){var e;if(null!==this.options.locks)return this.options.locks??(null==(e=globalThis.navigator)?void 0:e.locks)}runsDir(){}runDir(){}async createRun(){const o=await this.open();for(let e=0;e<8;e++){const e=t.generateRunId();if(!(await H(o.transaction(D).objectStore(D).get(e))))return e}throw e.XllmError.storage("cannot allocate a unique run id")}async writeRecord(e){const t=(await this.open()).transaction(D,"readwrite");t.objectStore(D).put(JSON.parse(JSON.stringify(e))),await P(t)}async readRecord(o){const r=await this.open(),n=await H(r.transaction(D).objectStore(D).get(o));if(!n)throw new e.XllmError({kind:"run_not_found",run_id:o,runs_dir:`indexeddb:${this.options.dbName??C}`});if(n.version!==t.RUN_RECORD_VERSION)throw e.XllmError.notResumable(o,"unsupported run record version");return n}async listRecords(){const e=await this.open();return await H(e.transaction(D).objectStore(D).getAll())}async putSnapshot(e,t){const o=(await this.open()).transaction(U,"readwrite"),r=o.objectStore(U),n=await H(r.getAllKeys(IDBKeyRange.bound([e,0],[e,Number.MAX_SAFE_INTEGER]))),s=n.length?Math.max(...n.map((e=>e[1])))+1:1;return r.put(JSON.parse(JSON.stringify(t)),[e,s]),await P(o),s}async getSnapshot(t,o){const r=await this.open(),n=await H(r.transaction(U).objectStore(U).get([t,o]));if(!n)throw new e.XllmError({kind:"corrupted_run",run_id:t,reason:`snapshot ${o} missing`});return n}async listSnapshots(e){const t=await this.open();return(await H(t.transaction(U).objectStore(U).getAllKeys(IDBKeyRange.bound([e,0],[e,Number.MAX_SAFE_INTEGER])))).map((e=>e[1])).sort(((e,t)=>e-t))}async lockRun(e){const t=`xllm-run:${e}`,o=this.locks();return o?new Promise(((e,r)=>{o.request(t,{ifAvailable:!0},(t=>t?new Promise((t=>e({release:()=>t()}))):(e(null),Promise.resolve()))).catch(r)})):this.localLocks.has(t)?null:(this.localLocks.add(t),{release:()=>{this.localLocks.delete(t)}})}async isRunLive(e){const t=`xllm-run:${e}`,o=this.locks();if(!o)return this.localLocks.has(t);return((await o.query()).held??[]).some((e=>e.name===t))}async removeRun(e){const t=(await this.open()).transaction([D,U],"readwrite");t.objectStore(D).delete(e),t.objectStore(U).delete(IDBKeyRange.bound([e,0],[e,Number.MAX_SAFE_INTEGER])),await P(t)}async importRun(e){const t=(await this.open()).transaction([D,U],"readwrite");t.objectStore(D).put(JSON.parse(JSON.stringify(e.record)));for(const[o,r]of e.snapshots)t.objectStore(U).put(JSON.parse(JSON.stringify(r)),[e.record.run_id,o]);await P(t)}},exports.MAX_RESULT_BYTES=_,exports.SITE_RUNTIME_KIND=r,exports.XCALL_USAGE=h,exports.XLLM_RUNS_DB=C,exports.createSiteRuntime=function(o){var i;const a=null==(i=o.scene)?void 0:i.trim();if(!a)throw e.XllmError.input("createSiteRuntime: `scene` is required");if(!o.origin)throw e.XllmError.input("createSiteRuntime: `origin` is required");const c=new Map;for(const[t,r]of Object.entries(o.tools??{})){if(!n.test(t))throw e.XllmError.tools(`site tool name \`${t}\` must match ${n}`);if(!r||"function"!=typeof r.call||!r.spec)throw e.XllmError.tools(`site tool \`${t}\` needs \`spec\` and \`call\``);c.set(t,r)}const l={...o.env??{}},u={runtime_id:`site:${a}`,kind:r,host:null,target:{origin:o.origin,scene:a},workdir:"/",capabilities:{tools:{},network:!0,os:"browser"}},p={kind:r,env:{}};return void 0!==o.task_wait_ms&&(p.task_wait_ms=o.task_wait_ms),{scene:a,tools:c,descriptor:()=>JSON.parse(JSON.stringify(u)),config:()=>JSON.parse(JSON.stringify(p)),async info(){let e="";try{e=Intl.DateTimeFormat().resolvedOptions().timeZone??""}catch{e=""}return{id:u.runtime_id,kind:r,os:"browser",arch:"",hostname:o.hostname,shell:"",cwd:"/",tools:[],current_time:(new Date).toISOString(),timezone:e,target:u.target,platform:"browser",shell_kind:"",baseline:""}},async open(o,r){const n=r.enabled??!1,i=r.tools2actions??!1;if("function_call"===o.loop_model&&(i||(r.actions??[]).length>0))throw e.XllmError.capability("actions / tools2actions need loop_model behavior");const l=(t,o)=>t.map((t=>{const r=c.get(t);if(!r)throw e.XllmError.capability(`${o}: \`${t}\` is not a tool of scene \`${a}\` (scene tools: ${[...c.keys()].join(", ")||"none"})`);return function(e,t,o){return{name:e,description:t.spec.description,args_schema:t.spec.args_schema,source:o}}(t,r,`name:${t}`)}));let u=[],d=[];const m=r.tools??[],f=r.actions??[];if(n){u=l(void 0===r.tools?[...c.keys()]:s(r.tools,"tools.tools"),"tools.tools"),d=l(s(r.actions,"tools.actions"),"tools.actions"),i&&(d=[...d,...u.filter((e=>!d.some((t=>t.name===e.name))))],u=[])}const g=new Map;for(const e of[...u,...d])g.set(e.name,c.get(e.name));return{tools:{enabled:n,filesystem_policy:r.filesystem_policy??"workspace",tools2actions:i,tool_sources:void 0===r.tools&&n?u.map((e=>({kind:"named",name:e.name}))):m,action_sources:f,native:u,actions:d,bash_tools:[],shell:t.shellSettings(r.shell,t.taskWaitMs(p)),exec_enabled:!1,sources:{...o.sources}},manager:new t.SiteToolManager(g,{tasks:o.tasks,taskWaitMs:o.task_wait_ms})}},async describeInterrupted(e,o){const r=c.get(o.name);if(null==r?void 0:r.describeInterrupted)try{return await r.describeInterrupted(o.args??{},{run_id:e.run_id,call_id:o.call_id,signal:(new AbortController).signal})}catch(n){return`${t.unresolvedReason(o.name)} (describing it failed: ${n instanceof Error?n.message:String(n)})`}return t.unresolvedReason(o.name)},env:e=>l[e]}},exports.didObjectResources=async function(t){const o=v(t.maxRisk??"read_only"),r={};for(const n of t.roots){const s=t.client,i=await s.profile(n),a=j(i),c={},l=e.isObject(i)&&e.isObject(i.actions)?i.actions:{};for(const[t,r]of Object.entries(l)){if(a&&("query"===t||"page"===t))continue;const i=L(r,"x-buckyos:risk");if(v(i)>o)continue;const l=e.isObject(r)?r.input:void 0;c[t]={description:L(r,"description"),risk:i,...null!=l?{input:l}:{},call:(e,o)=>s.invoke(n,t,o)}}const u=[L(i,"title"),L(i,"description")].filter(Boolean).join(" — ")||n;r[n]={description:a?`${u} (a collection: read it with a query, ?cursor=… for the next page)`:u,actions:c,async read(t){if(a&&[...t.query.keys()].length>0){const e=t.query.get("cursor"),o=t.query.get("page_size");if(e)return s.invoke(n,"page",{cursor:e,...o?{page_size:Number(o)}:{}});const r={};for(const[n,s]of t.query)"page_size"!==n&&(r[n]=s);return s.invoke(n,"query",{query:r,...o?{page_size:Number(o)}:{}})}const o=await s.card(n),r=e.isObject(i)&&e.isObject(i.properties)?Object.keys(i.properties).filter((e=>"index_schema"!==e)):[],c=e.isObject(i)&&Array.isArray(i["x-buckyos:summary_props"])?i["x-buckyos:summary_props"].filter((e=>"string"==typeof e)):r,l={};for(const e of c)l[e]=await s.readProperty(n,e);return k(n,{id:String(o.id),alsoKnownAs:o.alsoKnownAs},i,l)}}}return r},exports.normalizeUri=T,exports.pageText=O,exports.renderObjectDocument=k,exports.siteTools=function(e){const o=Object.entries(e.resources??{}).map((([e,t])=>function(e,t){const o=e.indexOf("://");if(o>=0){const r=e.slice(o+3),n=r.indexOf("/"),s=n<0?r:r.slice(0,n),i=n<0?"":r.slice(n+1);return{raw:e,origin:`${e.slice(0,o).toLowerCase()}://${s.toLowerCase()}`,segments:i?i.split("/"):[],decl:t}}const r=e.replace(/^\/+/,"").replace(/\/+$/,"");return{raw:e,segments:r?r.split("/"):[],decl:t}}(e,t))),r=new Set(o.map((e=>e.origin)).filter((e=>void 0!==e))),n=new Map(Object.entries(e.commands??{}));if(n.has("xcall"))throw new Error("siteTools: `xcall` is built in; declare actions on resources instead");const s=(e,t)=>{const n=T(e,r);for(const r of o){const e=S(r,n.origin,n.segments);if(e)return{uri:n.text,pattern:r.raw,params:e,query:n.query,ctx:t,decl:r.decl}}y(`uri \`${e}\` is not a resource of this page; read uri="/" lists them`)},g=async(e,o)=>{var r;const g=(()=>{try{return m(e)}catch(t){y(`${t instanceof Error?t.message:String(t)}; exec runs one command, it is not a shell`)}})(),T="available commands: xcall"+(n.size?`, ${[...n.keys()].join(", ")}`:""),S=e.replace(/'[^']*'|"(?:[^"\\]|\\.)*"/g,"");x.test(S)&&y(`exec runs exactly one command and is not a shell: pipes, redirects, \`;\`, \`&\`, backquotes and \`$\` are not supported (quote them to pass them as text). ${T}`);const[w,...O]=g;if(w||y(`empty command; ${T}`),"xcall"===w){if(O.includes("--help")||O.includes("-h"))return`usage: ${h}\nThe actions of each resource are listed by read uri="/".`;const{object:e,action:n,params:i}=I(O),a=s(e,o),c=null==(r=a.decl.actions)?void 0:r[n];if(!c){const e=Object.keys(a.decl.actions??{});y(`resource \`${a.pattern}\` has no action \`${n}\` (actions: ${e.length?e.join(", "):"none"})`)}if(void 0!==c.input){const e=t.validateJson(c.input,i);e&&y(`invalid params for ${n}: ${e}`)}const{decl:l,...u}=a,p=await c.call(u,i);return`[risk: ${c.risk}]\n${b(E(p)||"ok",_).text}`}const A=n.get(w);let R;A||y(`unknown command \`${w}\`; exec runs one command, it is not a shell. ${T}`);try{const e=function(e,t,o){const r={},n=e.positionals??[],s=new Map((e.options??[]).map((e=>[e.name,e])));let m=0,f=!1;for(let g=0;g<t.length;){const e=t[g];if("--help"===e||"-h"===e){f=!0,g+=1;continue}if("--"===e){for(const e of t.slice(g+1))m=d(r,n,m,e);break}if(!e.startsWith("--")){m=d(r,n,m,e),g+=1;continue}const h=l(e),_=null==o?void 0:o(h,t,g);if(void 0!==_){g+=_;continue}const x=s.get(h.name);if(!x)throw new i("UNKNOWN_OPTION",`unknown option: --${h.name}`);const y=c(x);if(a(r,y))throw new i("DUPLICATE_ARGUMENT",`argument provided more than once: ${y}`);if("boolean"===x.type){if(void 0!==h.inlineValue)throw new i("INVALID_ARGUMENT",`--${h.name} does not accept a value`);r[y]=!0,g+=1;continue}const{value:T,consumed:S}=u(t,g,h);r[y]=p(x.type,T,h.name),g+=S}return{input:r,help:f,positionalCount:m}}({positionals:A.positionals,options:A.options},O);if(e.help)return $(w,A);for(let t=e.positionalCount;t<(A.positionals??[]).length;t++)if(!1!==(A.positionals??[])[t].required)throw new i("MISSING_ARGUMENT",`missing positional argument: ${(A.positionals??[])[t].name}`);for(const t of A.options??[]){const o=t.property??t.name.split("-").join("_");if(t.required&&!(o in e.input))throw new i("MISSING_ARGUMENT",`--${t.name} is required`)}R=e.input,A.inputSchema&&f(R,A.inputSchema,"input")}catch(N){throw N instanceof i&&y(`${w}: ${N.message}\n\n${$(w,A)}`),N}return b(E(await A.call(R,o))||"ok",_).text};return{read:{spec:{description:'Read a resource of this page by URI (GET). Start with uri "/": it lists the resources, their actions (with risk) and the commands. A collection\'s read is its list; filter and page with a query (notes?tag=x). Text comes in pages of lines: offset is the first line (1-based), limit the number of lines.',args_schema:N({uri:{type:"string",description:'Resource URI, e.g. "/" or "notes/1"'},offset:{type:"integer",description:"First line, 1-based"},limit:{type:"integer",description:"Number of lines"}},["uri"])},idempotent:!0,async call(e,t){const r=String(e.uri),i="number"==typeof e.offset?e.offset:void 0,a="number"==typeof e.limit?e.limit:void 0;if("/"===r.trim()||""===r.trim())return O((()=>{const e=['Resources (read uri="<resource>"; {name} is one path segment):'];for(const t of o){const o=["read","write","edit"].filter((e=>"edit"===e?!!(t.decl.edit||t.decl.read&&t.decl.write):!!t.decl[e]));e.push(`- ${t.raw} — ${t.decl.description} [${o.join(", ")||"no methods"}]`);for(const[r,n]of Object.entries(t.decl.actions??{}))e.push(` action ${r} (risk: ${n.risk}) — ${n.description}`)}0===o.length&&e.push("(none)"),e.push("",'Commands (exec "<command> --help" for usage):'),e.push(`- xcall — call an action of a resource: ${h}`);for(const[t,o]of n)e.push(`- ${t} — ${o.summary}`);return e.join("\n")})(),i,a);return O((await(async e=>{e.decl.read||y(`resource \`${e.pattern}\` cannot be read`);const{decl:t,...o}=e;return w(await e.decl.read(o))})(s(r,t))).text,i,a)}},write:{spec:{description:'Write a resource\'s content (PUT). mode: "write" (default) replaces it, "new" only creates it and fails if it exists, "append" adds to its end. Use edit to change part of it.',args_schema:N({uri:{type:"string",description:"Resource URI"},content:{type:"string",description:"The content"},mode:{type:"string",enum:["write","new","append"],description:"write | new | append"}},["uri","content"])},async call(e,t){const o=s(String(e.uri),t);o.decl.write||y(`resource \`${o.pattern}\` is read-only`);const{decl:r,...n}=o,i="string"==typeof e.mode?e.mode:"write";return E(await r.write(n,{content:String(e.content),mode:i}))||"written"}},edit:{spec:{description:"Change part of a resource (PATCH): old_string must occur exactly once in its current content and is replaced by new_string.",args_schema:N({uri:{type:"string",description:"Resource URI"},old_string:{type:"string",description:"Text to replace; must occur exactly once"},new_string:{type:"string",description:"Replacement text"}},["uri","old_string","new_string"])},async call(e,t){const o=s(String(e.uri),t),r={old_string:String(e.old_string),new_string:String(e.new_string)},{decl:n,...i}=o;if(n.edit)return E(await n.edit(i,r))||"edited";n.read&&n.write||y(`resource \`${o.pattern}\` cannot be edited`),r.old_string||y("old_string is empty");const a=w(await n.read(i)),c=a.text.split(r.old_string).length-1;0===c&&y("old_string was not found in the current content; read it again"),c>1&&y(`old_string occurs ${c} times; give more context so it occurs exactly once`);const l={content:a.text.replace(r.old_string,(()=>r.new_string)),mode:"write"};return void 0!==a.version&&(l.ifVersion=a.version),E(await n.write(i,l))||"edited"}},exec:{spec:{description:`Run one command (not a shell: no pipes, redirects, ;, &, backquotes or $). Built in: ${h} — calls an action listed by read uri="/". The page's commands are listed there too; "<command> --help" shows a command's usage.`,args_schema:N({command:{type:"string",description:"One command line"}},["command"])},idempotent:e=>function(e,t,o,r){var n,s,i;let a;try{a=m(e)}catch{return!1}const[c,...l]=a;if("xcall"===c)try{const{object:e,action:r}=I(l),i=T(e,o),a=t.find((e=>S(e,i.origin,i.segments))),c=null==(s=null==(n=null==a?void 0:a.decl.actions)?void 0:n[r])?void 0:s.risk;return"read_only"===c||"idempotent_write"===c}catch{return!1}const u=c?r.get(c):void 0;return"read"===(null==(i=null==u?void 0:u.access)?void 0:i.level)}(String(e.command??""),o,r,n),call:(e,t)=>g(String(e.command),t)}}};
|
|
2
2
|
//# sourceMappingURL=xllm.cjs.map
|