@bastani/atomic 0.9.25-alpha.2 → 0.9.25-alpha.3
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/CHANGELOG.md +27 -0
- package/dist/builtin/intercom/package.json +2 -2
- package/dist/builtin/mcp/CHANGELOG.md +13 -0
- package/dist/builtin/mcp/index.bundle.mjs +489 -208
- package/dist/builtin/mcp/package.json +2 -2
- package/dist/builtin/subagents/package.json +3 -3
- package/dist/builtin/web-access/package.json +2 -2
- package/dist/builtin/workflows/CHANGELOG.md +12 -0
- package/dist/builtin/workflows/builtin/{chunk-e1254zvd.js → chunk-kfsnh3w7.js} +40 -12
- package/dist/builtin/workflows/builtin/{chunk-cpw5gtzg.js → chunk-rqmasd3d.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-qy6g0baf.js → chunk-wz783pvd.js} +1 -1
- package/dist/builtin/workflows/builtin/goal.js +2 -2
- package/dist/builtin/workflows/builtin/index.js +3 -3
- package/dist/builtin/workflows/builtin/ralph.js +2 -2
- package/dist/builtin/workflows/package.json +2 -2
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +472 -88
- package/dist/builtin/workflows/src/index.js +65 -28
- package/dist/core/agent-session-accessors.d.ts.map +1 -1
- package/dist/core/agent-session-accessors.js +7 -0
- package/dist/core/agent-session-accessors.js.map +1 -1
- package/dist/core/agent-session-extension-bindings.d.ts.map +1 -1
- package/dist/core/agent-session-extension-bindings.js +16 -2
- package/dist/core/agent-session-extension-bindings.js.map +1 -1
- package/dist/core/agent-session-methods.d.ts +7 -1
- package/dist/core/agent-session-methods.d.ts.map +1 -1
- package/dist/core/agent-session-methods.js.map +1 -1
- package/dist/core/agent-session-state.d.ts.map +1 -1
- package/dist/core/agent-session-state.js +3 -2
- package/dist/core/agent-session-state.js.map +1 -1
- package/dist/core/agent-session-types.d.ts +1 -0
- package/dist/core/agent-session-types.d.ts.map +1 -1
- package/dist/core/agent-session-types.js.map +1 -1
- package/dist/core/agent-session.d.ts +3 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +6 -0
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/extensions/api-types.d.ts +3 -0
- package/dist/core/extensions/api-types.d.ts.map +1 -1
- package/dist/core/extensions/api-types.js.map +1 -1
- package/dist/core/extensions/index.d.ts +2 -0
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js +1 -0
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader-api.d.ts.map +1 -1
- package/dist/core/extensions/loader-api.js +11 -0
- package/dist/core/extensions/loader-api.js.map +1 -1
- package/dist/core/extensions/loader-runtime.d.ts.map +1 -1
- package/dist/core/extensions/loader-runtime.js +3 -0
- package/dist/core/extensions/loader-runtime.js.map +1 -1
- package/dist/core/extensions/mcp-server-registry.d.ts.map +1 -1
- package/dist/core/extensions/mcp-server-registry.js +4 -0
- package/dist/core/extensions/mcp-server-registry.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +3 -0
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +4 -0
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/runtime-types.d.ts +3 -0
- package/dist/core/extensions/runtime-types.d.ts.map +1 -1
- package/dist/core/extensions/runtime-types.js.map +1 -1
- package/dist/core/extensions/tool-types.d.ts +1 -0
- package/dist/core/extensions/tool-types.d.ts.map +1 -1
- package/dist/core/extensions/tool-types.js.map +1 -1
- package/dist/core/extensions/workflow-run-control-hub.d.ts +23 -0
- package/dist/core/extensions/workflow-run-control-hub.d.ts.map +1 -0
- package/dist/core/extensions/workflow-run-control-hub.js +57 -0
- package/dist/core/extensions/workflow-run-control-hub.js.map +1 -0
- package/dist/core/extensions/workflow-run-control.d.ts +163 -0
- package/dist/core/extensions/workflow-run-control.d.ts.map +1 -0
- package/dist/core/extensions/workflow-run-control.js +73 -0
- package/dist/core/extensions/workflow-run-control.js.map +1 -0
- package/dist/core/mcp-servers.d.ts +4 -1
- package/dist/core/mcp-servers.d.ts.map +1 -1
- package/dist/core/mcp-servers.js.map +1 -1
- package/dist/core/remote-catalog-provider.d.ts.map +1 -1
- package/dist/core/remote-catalog-provider.js +4 -9
- package/dist/core/remote-catalog-provider.js.map +1 -1
- package/dist/core/sdk.js +1 -0
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/tool-loadout.d.ts +1 -0
- package/dist/core/tool-loadout.d.ts.map +1 -1
- package/dist/core/tool-loadout.js +3 -0
- package/dist/core/tool-loadout.js.map +1 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +11 -30
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/extensions/codemode/execute.d.ts.map +1 -1
- package/dist/extensions/codemode/execute.js +26 -0
- package/dist/extensions/codemode/execute.js.map +1 -1
- package/dist/extensions/codemode/renderer.d.ts.map +1 -1
- package/dist/extensions/codemode/renderer.js +38 -23
- package/dist/extensions/codemode/renderer.js.map +1 -1
- package/dist/extensions/codemode/tool.d.ts.map +1 -1
- package/dist/extensions/codemode/tool.js +22 -10
- package/dist/extensions/codemode/tool.js.map +1 -1
- package/dist/extensions/tool-search/tool.d.ts +1 -1
- package/dist/extensions/tool-search/tool.d.ts.map +1 -1
- package/dist/extensions/tool-search/tool.js +3 -13
- package/dist/extensions/tool-search/tool.js.map +1 -1
- package/dist/index-extensions.d.ts +2 -1
- package/dist/index-extensions.d.ts.map +1 -1
- package/dist/index-extensions.js +1 -1
- package/dist/index-extensions.js.map +1 -1
- package/dist/modes/interactive/components/visual-truncate.d.ts +27 -3
- package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -1
- package/dist/modes/interactive/components/visual-truncate.js +39 -6
- package/dist/modes/interactive/components/visual-truncate.js.map +1 -1
- package/docs/extensions/events.md +2 -0
- package/docs/mcp-servers.md +47 -0
- package/docs/providers.md +8 -0
- package/docs/sdk/reference.md +16 -0
- package/docs/sdk.md +67 -1
- package/docs/settings.md +2 -0
- package/docs/tools.md +6 -0
- package/docs/workflows/operations.md +3 -1
- package/examples/extensions/built-in-tool-renderer.ts +16 -40
- package/examples/extensions/minimal-mode.ts +28 -108
- package/npm-shrinkwrap.json +69 -69
- package/package.json +8 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-types.js","sourceRoot":"","sources":["../../../src/core/extensions/tool-types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tool-types.js","sourceRoot":"","sources":["../../../src/core/extensions/tool-types.ts"],"names":[],"mappings":"AAiKA;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CACzB,IAA+C;IAE/C,OAAO,IAAqE,CAAC;AAC9E,CAAC","sourcesContent":["import type { ConstrainedSamplingConfig } from \"@bastani/pi-ai/compat\";\nimport type { AgentToolResult, AgentToolUpdateCallback, ToolExecutionMode } from \"@earendil-works/pi-agent-core\";\nimport type { Component } from \"@earendil-works/pi-tui\";\nimport type { Static, TSchema } from \"typebox\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.js\";\nimport type { SourceInfo } from \"../source-info.ts\";\nimport type { ToolConcurrency } from \"../tools/tool-concurrency.ts\";\n\nexport type { ToolConcurrency, ToolConcurrencyMode } from \"../tools/tool-concurrency.ts\";\n\nimport type { ExtensionToolContext } from \"./context-types.ts\";\n\n/** Rendering options for tool results */\nexport interface ToolRenderResultOptions {\n\t/** Whether the result view is expanded */\n\texpanded: boolean;\n\t/** Whether this is a partial/streaming result */\n\tisPartial: boolean;\n}\n\n/** Context passed to tool renderers. */\nexport interface ToolRenderContext<TState = unknown, TArgs = unknown> {\n\t/** Current tool call arguments. Shared across call/result renders for the same tool call. */\n\targs: TArgs;\n\t/** Unique id for this tool execution. Stable across call/result renders for the same tool call. */\n\ttoolCallId: string;\n\t/** Invalidate just this tool execution component for redraw. */\n\tinvalidate: () => void;\n\t/** Previously returned component for this render slot, if any. */\n\tlastComponent: Component | undefined;\n\t/** Shared renderer state for this tool row. Initialized by tool-execution.ts. */\n\tstate: TState;\n\t/** Working directory for this tool execution. */\n\tcwd: string;\n\t/** Whether the tool execution has started. */\n\texecutionStarted: boolean;\n\t/** Whether the tool call arguments are complete. */\n\targsComplete: boolean;\n\t/** Whether the tool result is partial/streaming. */\n\tisPartial: boolean;\n\t/** Whether the result view is expanded. */\n\texpanded: boolean;\n\t/** Whether inline images are currently shown in the TUI. */\n\tshowImages: boolean;\n\t/** Whether the current result is an error. */\n\tisError: boolean;\n}\n\ntype ToolRenderCall<TParams extends TSchema, TState> = {\n\tbivarianceHack(args: Static<TParams>, theme: Theme, context: ToolRenderContext<TState, Static<TParams>>): Component;\n}[\"bivarianceHack\"];\n\ntype ToolRenderResult<TParams extends TSchema, TDetails, TState> = {\n\tbivarianceHack(\n\t\tresult: AgentToolResult<TDetails>,\n\t\toptions: ToolRenderResultOptions,\n\t\ttheme: Theme,\n\t\tcontext: ToolRenderContext<TState, Static<TParams>>,\n\t): Component;\n}[\"bivarianceHack\"];\n\n/** How the model reaches a registered tool. */\nexport type ToolExposure = \"direct\" | \"model-only\" | \"codemode\" | \"deferred\" | \"hidden\";\n\nexport interface ToolAnnotations {\n\treadOnlyHint?: boolean;\n\tdestructiveHint?: boolean;\n\tidempotentHint?: boolean;\n\topenWorldHint?: boolean;\n}\n\nexport interface ToolNamespace {\n\tname: string;\n\tdescription?: string;\n\tinstructions?: string;\n}\n\nexport interface ToolLoadout {\n\treadonly declared: readonly import(\"@earendil-works/pi-agent-core\").AgentTool[];\n\treadonly callable: readonly import(\"@earendil-works/pi-agent-core\").AgentTool[];\n\treadonly registered: readonly import(\"@earendil-works/pi-agent-core\").AgentTool[];\n\tgetExposure(name: string): ToolExposure;\n\tgetNamespace(name: string): ToolNamespace | undefined;\n}\n\nexport interface ToolLoadoutChanges {\n\tdescriptions?: Readonly<Record<string, string>>;\n\thiddenDeclarations?: readonly string[];\n}\n\n/**\n * Tool definition for registerTool().\n */\nexport interface ToolDefinition<TParams extends TSchema = TSchema, TDetails = unknown, TState = unknown> {\n\t/** Tool name (used in LLM tool calls) */\n\tname: string;\n\t/** Human-readable label for UI */\n\tlabel: string;\n\t/** Description for LLM */\n\tdescription: string;\n\t/** Optional one-line snippet for the Available tools section in the default system prompt. Custom tools are omitted from that section when this is not provided. */\n\tpromptSnippet?: string;\n\t/** Optional guideline bullets appended to the default system prompt Guidelines section when this tool is active. */\n\tpromptGuidelines?: string[];\n\t/** Parameter schema (TypeBox) */\n\tparameters: TParams;\n\t/** Optional provider-side constrained sampling request. `false` explicitly disables it. */\n\tconstrainedSampling?: false | ConstrainedSamplingConfig;\n\t/** Optional per-tool character cap for model-visible result persistence. Use Infinity to opt out for self-bounded tools. */\n\tmaxResultSizeChars?: number;\n\t/** Marks a terminating tool created by createStructuredOutputTool() so print mode can emit custom-named final JSON without treating every terminating tool as printable. */\n\tstructuredOutput?: true;\n\t/** Controls whether ToolExecutionComponent renders the standard colored shell or the tool renders its own framing. */\n\trenderShell?: \"default\" | \"self\";\n\n\t/** Optional compatibility shim to prepare raw tool call arguments before schema validation. Must return an object conforming to TParams. */\n\tprepareArguments?: (args: unknown) => Static<TParams>;\n\t/** Schema of successful machine-readable results. */\n\toutputSchema?: TSchema;\n\t/** Direct and model-only tools activate by default; other exposures do not. */\n\texposure?: ToolExposure;\n\tnamespace?: ToolNamespace;\n\tannotations?: ToolAnnotations;\n\tdefaultActive?: boolean;\n\tprepareLoadout?: (loadout: ToolLoadout) => ToolLoadoutChanges | undefined;\n\n\t/**\n\t * Per-tool execution mode override.\n\t * - \"sequential\": this tool must execute one at a time with other tool calls.\n\t * - \"parallel\": this tool can execute concurrently with other tool calls.\n\t *\n\t * If omitted, the default execution mode applies.\n\t */\n\texecutionMode?: ToolExecutionMode;\n\n\t/**\n\t * Ordering against the other calls of the same assistant message.\n\t * - \"shared\": may overlap other shared calls, but starts after the latest earlier exclusive call (default)\n\t * - \"exclusive\": starts after every earlier call finishes; later calls start after it finishes\n\t * - function: resolved per call from its arguments; a throwing resolver means \"exclusive\"\n\t */\n\tconcurrency?: ToolConcurrency<Static<TParams>>;\n\n\t/** Execute the tool. */\n\texecute(\n\t\ttoolCallId: string,\n\t\tparams: Static<TParams>,\n\t\tsignal: AbortSignal | undefined,\n\t\tonUpdate: AgentToolUpdateCallback<TDetails> | undefined,\n\t\tctx: ExtensionToolContext,\n\t): Promise<AgentToolResult<TDetails>>;\n\n\t/** Custom rendering for tool call display */\n\trenderCall?: ToolRenderCall<TParams, TState>;\n\n\t/** Custom rendering for tool result display */\n\trenderResult?: ToolRenderResult<TParams, TDetails, TState>;\n}\n\ntype AnyToolDefinition = ToolDefinition<TSchema, unknown, unknown>;\n\n/**\n * Preserve parameter inference for standalone tool definitions.\n *\n * Use this when assigning a tool to a variable or passing it through arrays such\n * as `customTools`, where contextual typing would otherwise widen params to\n * `unknown`.\n */\nexport function defineTool<TParams extends TSchema, TDetails = unknown, TState = unknown>(\n\ttool: ToolDefinition<TParams, TDetails, TState>,\n): ToolDefinition<TParams, TDetails, TState> & AnyToolDefinition {\n\treturn tool as ToolDefinition<TParams, TDetails, TState> & AnyToolDefinition;\n}\n\n/** Public constrained-sampling shape inherited from pi-ai. */\nexport type { ConstrainedSamplingConfig } from \"@bastani/pi-ai/compat\";\n\n/** Tool info with name, description, parameter schema, constraint, and source metadata */\nexport type ToolInfo = Pick<\n\tToolDefinition,\n\t| \"name\"\n\t| \"description\"\n\t| \"parameters\"\n\t| \"constrainedSampling\"\n\t| \"promptGuidelines\"\n\t| \"exposure\"\n\t| \"namespace\"\n\t| \"annotations\"\n> & {\n\tsourceInfo: SourceInfo;\n};\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type SessionWorkflows, type WorkflowRunAllTarget, type WorkflowRunControlOutcome, type WorkflowRunControlRegistration, type WorkflowRunDetail, type WorkflowRunListFilter, type WorkflowRunPauseOptions, type WorkflowRunResumeOptions, type WorkflowRunStageSummary, type WorkflowRunSummary, type WorkflowStageListFilter } from "./workflow-run-control.js";
|
|
2
|
+
/** Holds the run-control implementation that the workflows extension registers for one extension generation. */
|
|
3
|
+
export declare class WorkflowRunControlHub {
|
|
4
|
+
private control;
|
|
5
|
+
private disposed;
|
|
6
|
+
register(control: SessionWorkflows): WorkflowRunControlRegistration;
|
|
7
|
+
current(): SessionWorkflows | undefined;
|
|
8
|
+
dispose(): void;
|
|
9
|
+
}
|
|
10
|
+
/** Stable per-session handle that follows the current extension generation across reloads. */
|
|
11
|
+
export declare class SessionWorkflowsHandle implements SessionWorkflows {
|
|
12
|
+
private readonly resolve;
|
|
13
|
+
constructor(resolve: () => SessionWorkflows | undefined);
|
|
14
|
+
private control;
|
|
15
|
+
listRuns(filter?: WorkflowRunListFilter): Promise<readonly WorkflowRunSummary[]>;
|
|
16
|
+
getRun(runId: string): Promise<WorkflowRunDetail>;
|
|
17
|
+
getStages(runId: string, filter?: WorkflowStageListFilter): Promise<readonly WorkflowRunStageSummary[]>;
|
|
18
|
+
pause(runId: string, options?: WorkflowRunPauseOptions): Promise<WorkflowRunControlOutcome>;
|
|
19
|
+
pause(target: WorkflowRunAllTarget): Promise<WorkflowRunControlOutcome>;
|
|
20
|
+
quit(target: string | WorkflowRunAllTarget): Promise<WorkflowRunControlOutcome>;
|
|
21
|
+
resume(runId: string, options?: WorkflowRunResumeOptions): Promise<WorkflowRunControlOutcome>;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=workflow-run-control-hub.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-run-control-hub.d.ts","sourceRoot":"","sources":["../../../src/core/extensions/workflow-run-control-hub.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,KAAK,yBAAyB,EAC9B,KAAK,8BAA8B,EAEnC,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,uBAAuB,EAC5B,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC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workflow-run-control.js";
|
|
2
|
+
/** Holds the run-control implementation that the workflows extension registers for one extension generation. */
|
|
3
|
+
export class WorkflowRunControlHub {
|
|
4
|
+
control;
|
|
5
|
+
disposed = false;
|
|
6
|
+
register(control) {
|
|
7
|
+
if (this.disposed)
|
|
8
|
+
return { dispose: () => { } };
|
|
9
|
+
this.control = control;
|
|
10
|
+
return {
|
|
11
|
+
dispose: () => {
|
|
12
|
+
if (this.control === control)
|
|
13
|
+
this.control = undefined;
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
current() {
|
|
18
|
+
return this.control;
|
|
19
|
+
}
|
|
20
|
+
dispose() {
|
|
21
|
+
this.disposed = true;
|
|
22
|
+
this.control = undefined;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/** Stable per-session handle that follows the current extension generation across reloads. */
|
|
26
|
+
export class SessionWorkflowsHandle {
|
|
27
|
+
resolve;
|
|
28
|
+
constructor(resolve) {
|
|
29
|
+
this.resolve = resolve;
|
|
30
|
+
}
|
|
31
|
+
control() {
|
|
32
|
+
const control = this.resolve();
|
|
33
|
+
if (control === undefined)
|
|
34
|
+
throw new WorkflowRunControlUnavailableError();
|
|
35
|
+
return control;
|
|
36
|
+
}
|
|
37
|
+
async listRuns(filter) {
|
|
38
|
+
return this.control().listRuns(filter);
|
|
39
|
+
}
|
|
40
|
+
async getRun(runId) {
|
|
41
|
+
return this.control().getRun(runId);
|
|
42
|
+
}
|
|
43
|
+
async getStages(runId, filter) {
|
|
44
|
+
return this.control().getStages(runId, filter);
|
|
45
|
+
}
|
|
46
|
+
async pause(target, options) {
|
|
47
|
+
const control = this.control();
|
|
48
|
+
return typeof target === "string" ? control.pause(target, options) : control.pause(target);
|
|
49
|
+
}
|
|
50
|
+
async quit(target) {
|
|
51
|
+
return this.control().quit(target);
|
|
52
|
+
}
|
|
53
|
+
async resume(runId, options) {
|
|
54
|
+
return this.control().resume(runId, options);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=workflow-run-control-hub.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-run-control-hub.js","sourceRoot":"","sources":["../../../src/core/extensions/workflow-run-control-hub.ts"],"names":[],"mappings":"AAAA,OAAO,EAKN,kCAAkC,GAQlC,MAAM,2BAA2B,CAAC;AAEnC,gHAAgH;AAChH,MAAM,OAAO,qBAAqB;IACzB,OAAO,CAA+B;IACtC,QAAQ,GAAG,KAAK,CAAC;IAEzB,QAAQ,CAAC,OAAyB;QACjC,IAAI,IAAI,CAAC,QAAQ;YAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,CAAC;QAChD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,OAAO;YACN,OAAO,EAAE,GAAG,EAAE;gBACb,IAAI,IAAI,CAAC,OAAO,KAAK,OAAO;oBAAE,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;YACxD,CAAC;SACD,CAAC;IACH,CAAC;IAED,OAAO;QACN,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IAED,OAAO;QACN,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;IAC1B,CAAC;CACD;AAED,8FAA8F;AAC9F,MAAM,OAAO,sBAAsB;IACjB,OAAO,CAAqC;IAE7D,YAAY,OAA2C;QACtD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;IAEO,OAAO;QACd,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QAC/B,IAAI,OAAO,KAAK,SAAS;YAAE,MAAM,IAAI,kCAAkC,EAAE,CAAC;QAC1E,OAAO,OAAO,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,MAA8B;QAC5C,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACxC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,KAAa;QACzB,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,KAAa,EAAE,MAAgC;QAC9D,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAChD,CAAC;IAID,KAAK,CAAC,KAAK,CACV,MAAqC,EACrC,OAAiC;QAEjC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QAC/B,OAAO,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAC5F,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,MAAqC;QAC/C,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,KAAa,EAAE,OAAkC;QAC7D,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;CACD","sourcesContent":["import {\n\ttype SessionWorkflows,\n\ttype WorkflowRunAllTarget,\n\ttype WorkflowRunControlOutcome,\n\ttype WorkflowRunControlRegistration,\n\tWorkflowRunControlUnavailableError,\n\ttype WorkflowRunDetail,\n\ttype WorkflowRunListFilter,\n\ttype WorkflowRunPauseOptions,\n\ttype WorkflowRunResumeOptions,\n\ttype WorkflowRunStageSummary,\n\ttype WorkflowRunSummary,\n\ttype WorkflowStageListFilter,\n} from \"./workflow-run-control.js\";\n\n/** Holds the run-control implementation that the workflows extension registers for one extension generation. */\nexport class WorkflowRunControlHub {\n\tprivate control: SessionWorkflows | undefined;\n\tprivate disposed = false;\n\n\tregister(control: SessionWorkflows): WorkflowRunControlRegistration {\n\t\tif (this.disposed) return { dispose: () => {} };\n\t\tthis.control = control;\n\t\treturn {\n\t\t\tdispose: () => {\n\t\t\t\tif (this.control === control) this.control = undefined;\n\t\t\t},\n\t\t};\n\t}\n\n\tcurrent(): SessionWorkflows | undefined {\n\t\treturn this.control;\n\t}\n\n\tdispose(): void {\n\t\tthis.disposed = true;\n\t\tthis.control = undefined;\n\t}\n}\n\n/** Stable per-session handle that follows the current extension generation across reloads. */\nexport class SessionWorkflowsHandle implements SessionWorkflows {\n\tprivate readonly resolve: () => SessionWorkflows | undefined;\n\n\tconstructor(resolve: () => SessionWorkflows | undefined) {\n\t\tthis.resolve = resolve;\n\t}\n\n\tprivate control(): SessionWorkflows {\n\t\tconst control = this.resolve();\n\t\tif (control === undefined) throw new WorkflowRunControlUnavailableError();\n\t\treturn control;\n\t}\n\n\tasync listRuns(filter?: WorkflowRunListFilter): Promise<readonly WorkflowRunSummary[]> {\n\t\treturn this.control().listRuns(filter);\n\t}\n\n\tasync getRun(runId: string): Promise<WorkflowRunDetail> {\n\t\treturn this.control().getRun(runId);\n\t}\n\n\tasync getStages(runId: string, filter?: WorkflowStageListFilter): Promise<readonly WorkflowRunStageSummary[]> {\n\t\treturn this.control().getStages(runId, filter);\n\t}\n\n\tpause(runId: string, options?: WorkflowRunPauseOptions): Promise<WorkflowRunControlOutcome>;\n\tpause(target: WorkflowRunAllTarget): Promise<WorkflowRunControlOutcome>;\n\tasync pause(\n\t\ttarget: string | WorkflowRunAllTarget,\n\t\toptions?: WorkflowRunPauseOptions,\n\t): Promise<WorkflowRunControlOutcome> {\n\t\tconst control = this.control();\n\t\treturn typeof target === \"string\" ? control.pause(target, options) : control.pause(target);\n\t}\n\n\tasync quit(target: string | WorkflowRunAllTarget): Promise<WorkflowRunControlOutcome> {\n\t\treturn this.control().quit(target);\n\t}\n\n\tasync resume(runId: string, options?: WorkflowRunResumeOptions): Promise<WorkflowRunControlOutcome> {\n\t\treturn this.control().resume(runId, options);\n\t}\n}\n"]}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import type { WorkflowRunStatus, WorkflowStageStatus } from "./workflow-events.js";
|
|
2
|
+
export type WorkflowRunJsonValue = string | number | boolean | null | readonly WorkflowRunJsonValue[] | WorkflowRunJsonObject;
|
|
3
|
+
export interface WorkflowRunJsonObject {
|
|
4
|
+
readonly [key: string]: WorkflowRunJsonValue | undefined;
|
|
5
|
+
}
|
|
6
|
+
export type WorkflowRunFilterStatus = WorkflowRunStatus | WorkflowStageStatus | "awaiting_input";
|
|
7
|
+
export interface WorkflowRunListFilter {
|
|
8
|
+
/** Run statuses match directly; `awaiting_input` selects runs with an unanswered prompt. */
|
|
9
|
+
readonly status?: WorkflowRunFilterStatus;
|
|
10
|
+
}
|
|
11
|
+
export interface WorkflowStageListFilter {
|
|
12
|
+
readonly status?: WorkflowStageStatus;
|
|
13
|
+
}
|
|
14
|
+
export interface WorkflowRunActiveStage {
|
|
15
|
+
readonly stageId: string;
|
|
16
|
+
readonly name: string;
|
|
17
|
+
readonly status: WorkflowStageStatus;
|
|
18
|
+
}
|
|
19
|
+
export interface WorkflowRunAwaitingInput {
|
|
20
|
+
readonly stageId?: string;
|
|
21
|
+
readonly stageName?: string;
|
|
22
|
+
readonly promptId?: string;
|
|
23
|
+
readonly promptKind?: string;
|
|
24
|
+
readonly message?: string;
|
|
25
|
+
}
|
|
26
|
+
/** The concise per-run data that the `workflow` tool's `status` action lists. */
|
|
27
|
+
export interface WorkflowRunSummary {
|
|
28
|
+
readonly runId: string;
|
|
29
|
+
readonly name: string;
|
|
30
|
+
readonly status: WorkflowRunStatus;
|
|
31
|
+
readonly startedAt: number;
|
|
32
|
+
readonly endedAt?: number;
|
|
33
|
+
readonly elapsedMs: number;
|
|
34
|
+
readonly activeStages: readonly WorkflowRunActiveStage[];
|
|
35
|
+
readonly awaitingInputCount: number;
|
|
36
|
+
readonly awaitingInput: readonly WorkflowRunAwaitingInput[];
|
|
37
|
+
readonly exitReason?: string;
|
|
38
|
+
readonly error?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface WorkflowRunStageSummary {
|
|
41
|
+
readonly id: string;
|
|
42
|
+
readonly name: string;
|
|
43
|
+
readonly status: WorkflowStageStatus;
|
|
44
|
+
readonly sessionId?: string;
|
|
45
|
+
readonly error?: string;
|
|
46
|
+
readonly skippedReason?: string;
|
|
47
|
+
readonly awaitingInputSince?: number;
|
|
48
|
+
}
|
|
49
|
+
/** The per-run detail that the `workflow` tool's `status` action returns for one run id. */
|
|
50
|
+
export interface WorkflowRunDetail {
|
|
51
|
+
readonly runId: string;
|
|
52
|
+
readonly rootRunId?: string;
|
|
53
|
+
readonly name: string;
|
|
54
|
+
readonly status: WorkflowRunStatus | "crashed";
|
|
55
|
+
readonly startedAt: number;
|
|
56
|
+
readonly endedAt?: number;
|
|
57
|
+
readonly durationMs?: number;
|
|
58
|
+
readonly inputs: WorkflowRunJsonObject;
|
|
59
|
+
readonly stages: readonly WorkflowRunStageSummary[];
|
|
60
|
+
readonly result?: WorkflowRunJsonObject;
|
|
61
|
+
readonly error?: string;
|
|
62
|
+
readonly exitReason?: string;
|
|
63
|
+
readonly resumable?: boolean;
|
|
64
|
+
readonly resumeGuidance?: string;
|
|
65
|
+
readonly ownerActiveElsewhere?: boolean;
|
|
66
|
+
}
|
|
67
|
+
export interface WorkflowRunAllTarget {
|
|
68
|
+
readonly all: true;
|
|
69
|
+
}
|
|
70
|
+
export interface WorkflowRunPauseOptions {
|
|
71
|
+
/** Pause one stage instead of the whole run. */
|
|
72
|
+
readonly stageId?: string;
|
|
73
|
+
}
|
|
74
|
+
export interface WorkflowRunResumeOptions {
|
|
75
|
+
/** Resume one paused stage instead of the whole run. */
|
|
76
|
+
readonly stageId?: string;
|
|
77
|
+
/** Message delivered to each resumed stage. */
|
|
78
|
+
readonly message?: string;
|
|
79
|
+
}
|
|
80
|
+
export type WorkflowRunControlStatus = "ok" | "running" | "paused" | "partial" | "noop" | "cancelled";
|
|
81
|
+
/** A run that a batch pause or quit could not stop; it may still be active. */
|
|
82
|
+
export interface WorkflowRunControlFailedRun {
|
|
83
|
+
readonly runId: string;
|
|
84
|
+
/** Machine-readable refusal, such as `not_found`, `no_active_stages` or `pause_failed`. */
|
|
85
|
+
readonly reason: string;
|
|
86
|
+
readonly message?: string;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* The acknowledged result of a pause, quit or resume request, as the `workflow`
|
|
90
|
+
* tool reports it. `runId` is `--all` for a batch request. `noop` means the request was
|
|
91
|
+
* understood and found nothing to change; `partial` means only part of the
|
|
92
|
+
* request took effect. For a batch pause or quit, `failedRuns` names every run that
|
|
93
|
+
* could not be stopped, so a `partial` outcome is never a complete stop.
|
|
94
|
+
*/
|
|
95
|
+
export interface WorkflowRunControlOutcome {
|
|
96
|
+
readonly action: "pause" | "quit" | "resume";
|
|
97
|
+
readonly runId: string;
|
|
98
|
+
readonly status: WorkflowRunControlStatus;
|
|
99
|
+
readonly message: string;
|
|
100
|
+
readonly stageId?: string;
|
|
101
|
+
readonly workflowStatus?: WorkflowRunStatus;
|
|
102
|
+
readonly abandoned?: boolean;
|
|
103
|
+
readonly failedRuns?: readonly WorkflowRunControlFailedRun[];
|
|
104
|
+
}
|
|
105
|
+
/** Typed run management for the workflow runs owned by one session. */
|
|
106
|
+
export interface SessionWorkflows {
|
|
107
|
+
listRuns(filter?: WorkflowRunListFilter): Promise<readonly WorkflowRunSummary[]>;
|
|
108
|
+
getRun(runId: string): Promise<WorkflowRunDetail>;
|
|
109
|
+
getStages(runId: string, filter?: WorkflowStageListFilter): Promise<readonly WorkflowRunStageSummary[]>;
|
|
110
|
+
pause(runId: string, options?: WorkflowRunPauseOptions): Promise<WorkflowRunControlOutcome>;
|
|
111
|
+
pause(target: WorkflowRunAllTarget): Promise<WorkflowRunControlOutcome>;
|
|
112
|
+
quit(target: string | WorkflowRunAllTarget): Promise<WorkflowRunControlOutcome>;
|
|
113
|
+
resume(runId: string, options?: WorkflowRunResumeOptions): Promise<WorkflowRunControlOutcome>;
|
|
114
|
+
}
|
|
115
|
+
export interface WorkflowRunControlRegistration {
|
|
116
|
+
dispose(): void;
|
|
117
|
+
}
|
|
118
|
+
export type WorkflowRunControlErrorCode = "WORKFLOW_RUN_NOT_FOUND" | "WORKFLOW_RUN_OWNED_ELSEWHERE" | "WORKFLOW_RUN_NOT_RESUMABLE" | "WORKFLOW_STAGE_NOT_FOUND" | "WORKFLOW_STAGE_AMBIGUOUS" | "WORKFLOW_STAGE_RESUME_UNSUPPORTED" | "WORKFLOW_RUN_DATABASE" | "WORKFLOW_RUN_CONTROL_FAILED" | "WORKFLOW_RUN_CONTROL_UNAVAILABLE";
|
|
119
|
+
export interface WorkflowRunControlErrorOptions extends ErrorOptions {
|
|
120
|
+
readonly runId?: string;
|
|
121
|
+
readonly failedRuns?: readonly WorkflowRunControlFailedRun[];
|
|
122
|
+
}
|
|
123
|
+
/** Base class for every failure reported by {@link SessionWorkflows}; branch on `code`. */
|
|
124
|
+
export declare class WorkflowRunControlError extends Error {
|
|
125
|
+
readonly code: WorkflowRunControlErrorCode;
|
|
126
|
+
readonly runId?: string;
|
|
127
|
+
/** Runs a batch pause or quit could not stop, when the whole batch was refused. */
|
|
128
|
+
readonly failedRuns?: readonly WorkflowRunControlFailedRun[];
|
|
129
|
+
constructor(code: WorkflowRunControlErrorCode, message: string, options?: WorkflowRunControlErrorOptions);
|
|
130
|
+
}
|
|
131
|
+
/** The run id is unknown, malformed, or an ambiguous prefix. */
|
|
132
|
+
export declare class WorkflowRunNotFoundError extends WorkflowRunControlError {
|
|
133
|
+
constructor(message: string, options?: WorkflowRunControlErrorOptions);
|
|
134
|
+
}
|
|
135
|
+
/** The run belongs to another session or is executing in another live Atomic process. */
|
|
136
|
+
export declare class WorkflowRunOwnershipError extends WorkflowRunControlError {
|
|
137
|
+
constructor(message: string, options?: WorkflowRunControlErrorOptions);
|
|
138
|
+
}
|
|
139
|
+
/** The run has no continuation to resume: it completed, was killed, or has no durable progress. */
|
|
140
|
+
export declare class WorkflowRunNotResumableError extends WorkflowRunControlError {
|
|
141
|
+
constructor(message: string, options?: WorkflowRunControlErrorOptions);
|
|
142
|
+
}
|
|
143
|
+
/** The stage identifier matches no stage or tool node of the run. */
|
|
144
|
+
export declare class WorkflowStageNotFoundError extends WorkflowRunControlError {
|
|
145
|
+
constructor(message: string, options?: WorkflowRunControlErrorOptions);
|
|
146
|
+
}
|
|
147
|
+
/** The stage identifier matches more than one stage or tool node; pass a more specific identifier. */
|
|
148
|
+
export declare class WorkflowStageAmbiguousError extends WorkflowRunControlError {
|
|
149
|
+
constructor(message: string, options?: WorkflowRunControlErrorOptions);
|
|
150
|
+
}
|
|
151
|
+
/** A durable run can only be resumed whole; resume it without a stage identifier. */
|
|
152
|
+
export declare class WorkflowStageResumeUnsupportedError extends WorkflowRunControlError {
|
|
153
|
+
constructor(message: string, options?: WorkflowRunControlErrorOptions);
|
|
154
|
+
}
|
|
155
|
+
/** Workflow durability (the run database) is unavailable, shut down, or failed. */
|
|
156
|
+
export declare class WorkflowRunDatabaseError extends WorkflowRunControlError {
|
|
157
|
+
constructor(message: string, options?: WorkflowRunControlErrorOptions);
|
|
158
|
+
}
|
|
159
|
+
/** The workflows extension is not loaded for this session, or the session was disposed. */
|
|
160
|
+
export declare class WorkflowRunControlUnavailableError extends WorkflowRunControlError {
|
|
161
|
+
constructor(message?: string, options?: WorkflowRunControlErrorOptions);
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=workflow-run-control.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-run-control.d.ts","sourceRoot":"","sources":["../../../src/core/extensions/workflow-run-control.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAEnF,MAAM,MAAM,oBAAoB,GAC7B,MAAM,GACN,MAAM,GACN,OAAO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@ -0,0 +1,73 @@
|
|
|
1
|
+
/** Base class for every failure reported by {@link SessionWorkflows}; branch on `code`. */
|
|
2
|
+
export class WorkflowRunControlError extends Error {
|
|
3
|
+
code;
|
|
4
|
+
runId;
|
|
5
|
+
/** Runs a batch pause or quit could not stop, when the whole batch was refused. */
|
|
6
|
+
failedRuns;
|
|
7
|
+
constructor(code, message, options = {}) {
|
|
8
|
+
super(message, options);
|
|
9
|
+
this.name = "WorkflowRunControlError";
|
|
10
|
+
this.code = code;
|
|
11
|
+
if (options.runId !== undefined)
|
|
12
|
+
this.runId = options.runId;
|
|
13
|
+
if (options.failedRuns !== undefined)
|
|
14
|
+
this.failedRuns = options.failedRuns;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** The run id is unknown, malformed, or an ambiguous prefix. */
|
|
18
|
+
export class WorkflowRunNotFoundError extends WorkflowRunControlError {
|
|
19
|
+
constructor(message, options) {
|
|
20
|
+
super("WORKFLOW_RUN_NOT_FOUND", message, options);
|
|
21
|
+
this.name = "WorkflowRunNotFoundError";
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** The run belongs to another session or is executing in another live Atomic process. */
|
|
25
|
+
export class WorkflowRunOwnershipError extends WorkflowRunControlError {
|
|
26
|
+
constructor(message, options) {
|
|
27
|
+
super("WORKFLOW_RUN_OWNED_ELSEWHERE", message, options);
|
|
28
|
+
this.name = "WorkflowRunOwnershipError";
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** The run has no continuation to resume: it completed, was killed, or has no durable progress. */
|
|
32
|
+
export class WorkflowRunNotResumableError extends WorkflowRunControlError {
|
|
33
|
+
constructor(message, options) {
|
|
34
|
+
super("WORKFLOW_RUN_NOT_RESUMABLE", message, options);
|
|
35
|
+
this.name = "WorkflowRunNotResumableError";
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** The stage identifier matches no stage or tool node of the run. */
|
|
39
|
+
export class WorkflowStageNotFoundError extends WorkflowRunControlError {
|
|
40
|
+
constructor(message, options) {
|
|
41
|
+
super("WORKFLOW_STAGE_NOT_FOUND", message, options);
|
|
42
|
+
this.name = "WorkflowStageNotFoundError";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** The stage identifier matches more than one stage or tool node; pass a more specific identifier. */
|
|
46
|
+
export class WorkflowStageAmbiguousError extends WorkflowRunControlError {
|
|
47
|
+
constructor(message, options) {
|
|
48
|
+
super("WORKFLOW_STAGE_AMBIGUOUS", message, options);
|
|
49
|
+
this.name = "WorkflowStageAmbiguousError";
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/** A durable run can only be resumed whole; resume it without a stage identifier. */
|
|
53
|
+
export class WorkflowStageResumeUnsupportedError extends WorkflowRunControlError {
|
|
54
|
+
constructor(message, options) {
|
|
55
|
+
super("WORKFLOW_STAGE_RESUME_UNSUPPORTED", message, options);
|
|
56
|
+
this.name = "WorkflowStageResumeUnsupportedError";
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/** Workflow durability (the run database) is unavailable, shut down, or failed. */
|
|
60
|
+
export class WorkflowRunDatabaseError extends WorkflowRunControlError {
|
|
61
|
+
constructor(message, options) {
|
|
62
|
+
super("WORKFLOW_RUN_DATABASE", message, options);
|
|
63
|
+
this.name = "WorkflowRunDatabaseError";
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** The workflows extension is not loaded for this session, or the session was disposed. */
|
|
67
|
+
export class WorkflowRunControlUnavailableError extends WorkflowRunControlError {
|
|
68
|
+
constructor(message = "Workflow run control is unavailable for this session.", options) {
|
|
69
|
+
super("WORKFLOW_RUN_CONTROL_UNAVAILABLE", message, options);
|
|
70
|
+
this.name = "WorkflowRunControlUnavailableError";
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=workflow-run-control.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-run-control.js","sourceRoot":"","sources":["../../../src/core/extens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A2B,SAAQ,uBAAuB;IACtE,YAAY,OAAe,EAAE,OAAwC;QACpE,KAAK,CAAC,0BAA0B,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QACpD,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;IAC1C,CAAC;CACD;AAED,sGAAsG;AACtG,MAAM,OAAO,2BAA4B,SAAQ,uBAAuB;IACvE,YAAY,OAAe,EAAE,OAAwC;QACpE,KAAK,CAAC,0BAA0B,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QACpD,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;IAC3C,CAAC;CACD;AAED,qFAAqF;AACrF,MAAM,OAAO,mCAAoC,SAAQ,uBAAuB;IAC/E,YAAY,OAAe,EAAE,OAAwC;QACpE,KAAK,CAAC,mCAAmC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QAC7D,IAAI,CAAC,IAAI,GAAG,qCAAqC,CAAC;IACnD,CAAC;CACD;AAED,mFAAmF;AACnF,MAAM,OAAO,wBAAyB,SAAQ,uBAAuB;IACpE,YAAY,OAAe,EAAE,OAAwC;QACpE,KAAK,CAAC,uBAAuB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QACjD,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IACxC,CAAC;CACD;AAED,2FAA2F;AAC3F,MAAM,OAAO,kCAAmC,SAAQ,uBAAuB;IAC9E,YACC,OAAO,GAAG,uDAAuD,EACjE,OAAwC;QAExC,KAAK,CAAC,kCAAkC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QAC5D,IAAI,CAAC,IAAI,GAAG,oCAAoC,CAAC;IAClD,CAAC;CACD","sourcesContent":["import type { WorkflowRunStatus, WorkflowStageStatus } from \"./workflow-events.js\";\n\nexport type WorkflowRunJsonValue =\n\t| string\n\t| number\n\t| boolean\n\t| null\n\t| readonly WorkflowRunJsonValue[]\n\t| WorkflowRunJsonObject;\n\nexport interface WorkflowRunJsonObject {\n\treadonly [key: string]: WorkflowRunJsonValue | undefined;\n}\n\nexport type WorkflowRunFilterStatus = WorkflowRunStatus | WorkflowStageStatus | \"awaiting_input\";\n\nexport interface WorkflowRunListFilter {\n\t/** Run statuses match directly; `awaiting_input` selects runs with an unanswered prompt. */\n\treadonly status?: WorkflowRunFilterStatus;\n}\n\nexport interface WorkflowStageListFilter {\n\treadonly status?: WorkflowStageStatus;\n}\n\nexport interface WorkflowRunActiveStage {\n\treadonly stageId: string;\n\treadonly name: string;\n\treadonly status: WorkflowStageStatus;\n}\n\nexport interface WorkflowRunAwaitingInput {\n\treadonly stageId?: string;\n\treadonly stageName?: string;\n\treadonly promptId?: string;\n\treadonly promptKind?: string;\n\treadonly message?: string;\n}\n\n/** The concise per-run data that the `workflow` tool's `status` action lists. */\nexport interface WorkflowRunSummary {\n\treadonly runId: string;\n\treadonly name: string;\n\treadonly status: WorkflowRunStatus;\n\treadonly startedAt: number;\n\treadonly endedAt?: number;\n\treadonly elapsedMs: number;\n\treadonly activeStages: readonly WorkflowRunActiveStage[];\n\treadonly awaitingInputCount: number;\n\treadonly awaitingInput: readonly WorkflowRunAwaitingInput[];\n\treadonly exitReason?: string;\n\treadonly error?: string;\n}\n\nexport interface WorkflowRunStageSummary {\n\treadonly id: string;\n\treadonly name: string;\n\treadonly status: WorkflowStageStatus;\n\treadonly sessionId?: string;\n\treadonly error?: string;\n\treadonly skippedReason?: string;\n\treadonly awaitingInputSince?: number;\n}\n\n/** The per-run detail that the `workflow` tool's `status` action returns for one run id. */\nexport interface WorkflowRunDetail {\n\treadonly runId: string;\n\treadonly rootRunId?: string;\n\treadonly name: string;\n\treadonly status: WorkflowRunStatus | \"crashed\";\n\treadonly startedAt: number;\n\treadonly endedAt?: number;\n\treadonly durationMs?: number;\n\treadonly inputs: WorkflowRunJsonObject;\n\treadonly stages: readonly WorkflowRunStageSummary[];\n\treadonly result?: WorkflowRunJsonObject;\n\treadonly error?: string;\n\treadonly exitReason?: string;\n\treadonly resumable?: boolean;\n\treadonly resumeGuidance?: string;\n\treadonly ownerActiveElsewhere?: boolean;\n}\n\nexport interface WorkflowRunAllTarget {\n\treadonly all: true;\n}\n\nexport interface WorkflowRunPauseOptions {\n\t/** Pause one stage instead of the whole run. */\n\treadonly stageId?: string;\n}\n\nexport interface WorkflowRunResumeOptions {\n\t/** Resume one paused stage instead of the whole run. */\n\treadonly stageId?: string;\n\t/** Message delivered to each resumed stage. */\n\treadonly message?: string;\n}\n\nexport type WorkflowRunControlStatus = \"ok\" | \"running\" | \"paused\" | \"partial\" | \"noop\" | \"cancelled\";\n\n/** A run that a batch pause or quit could not stop; it may still be active. */\nexport interface WorkflowRunControlFailedRun {\n\treadonly runId: string;\n\t/** Machine-readable refusal, such as `not_found`, `no_active_stages` or `pause_failed`. */\n\treadonly reason: string;\n\treadonly message?: string;\n}\n\n/**\n * The acknowledged result of a pause, quit or resume request, as the `workflow`\n * tool reports it. `runId` is `--all` for a batch request. `noop` means the request was\n * understood and found nothing to change; `partial` means only part of the\n * request took effect. For a batch pause or quit, `failedRuns` names every run that\n * could not be stopped, so a `partial` outcome is never a complete stop.\n */\nexport interface WorkflowRunControlOutcome {\n\treadonly action: \"pause\" | \"quit\" | \"resume\";\n\treadonly runId: string;\n\treadonly status: WorkflowRunControlStatus;\n\treadonly message: string;\n\treadonly stageId?: string;\n\treadonly workflowStatus?: WorkflowRunStatus;\n\treadonly abandoned?: boolean;\n\treadonly failedRuns?: readonly WorkflowRunControlFailedRun[];\n}\n\n/** Typed run management for the workflow runs owned by one session. */\nexport interface SessionWorkflows {\n\tlistRuns(filter?: WorkflowRunListFilter): Promise<readonly WorkflowRunSummary[]>;\n\tgetRun(runId: string): Promise<WorkflowRunDetail>;\n\tgetStages(runId: string, filter?: WorkflowStageListFilter): Promise<readonly WorkflowRunStageSummary[]>;\n\tpause(runId: string, options?: WorkflowRunPauseOptions): Promise<WorkflowRunControlOutcome>;\n\tpause(target: WorkflowRunAllTarget): Promise<WorkflowRunControlOutcome>;\n\tquit(target: string | WorkflowRunAllTarget): Promise<WorkflowRunControlOutcome>;\n\tresume(runId: string, options?: WorkflowRunResumeOptions): Promise<WorkflowRunControlOutcome>;\n}\n\nexport interface WorkflowRunControlRegistration {\n\tdispose(): void;\n}\n\nexport type WorkflowRunControlErrorCode =\n\t| \"WORKFLOW_RUN_NOT_FOUND\"\n\t| \"WORKFLOW_RUN_OWNED_ELSEWHERE\"\n\t| \"WORKFLOW_RUN_NOT_RESUMABLE\"\n\t| \"WORKFLOW_STAGE_NOT_FOUND\"\n\t| \"WORKFLOW_STAGE_AMBIGUOUS\"\n\t| \"WORKFLOW_STAGE_RESUME_UNSUPPORTED\"\n\t| \"WORKFLOW_RUN_DATABASE\"\n\t| \"WORKFLOW_RUN_CONTROL_FAILED\"\n\t| \"WORKFLOW_RUN_CONTROL_UNAVAILABLE\";\n\nexport interface WorkflowRunControlErrorOptions extends ErrorOptions {\n\treadonly runId?: string;\n\treadonly failedRuns?: readonly WorkflowRunControlFailedRun[];\n}\n\n/** Base class for every failure reported by {@link SessionWorkflows}; branch on `code`. */\nexport class WorkflowRunControlError extends Error {\n\treadonly code: WorkflowRunControlErrorCode;\n\treadonly runId?: string;\n\t/** Runs a batch pause or quit could not stop, when the whole batch was refused. */\n\treadonly failedRuns?: readonly WorkflowRunControlFailedRun[];\n\n\tconstructor(code: WorkflowRunControlErrorCode, message: string, options: WorkflowRunControlErrorOptions = {}) {\n\t\tsuper(message, options);\n\t\tthis.name = \"WorkflowRunControlError\";\n\t\tthis.code = code;\n\t\tif (options.runId !== undefined) this.runId = options.runId;\n\t\tif (options.failedRuns !== undefined) this.failedRuns = options.failedRuns;\n\t}\n}\n\n/** The run id is unknown, malformed, or an ambiguous prefix. */\nexport class WorkflowRunNotFoundError extends WorkflowRunControlError {\n\tconstructor(message: string, options?: WorkflowRunControlErrorOptions) {\n\t\tsuper(\"WORKFLOW_RUN_NOT_FOUND\", message, options);\n\t\tthis.name = \"WorkflowRunNotFoundError\";\n\t}\n}\n\n/** The run belongs to another session or is executing in another live Atomic process. */\nexport class WorkflowRunOwnershipError extends WorkflowRunControlError {\n\tconstructor(message: string, options?: WorkflowRunControlErrorOptions) {\n\t\tsuper(\"WORKFLOW_RUN_OWNED_ELSEWHERE\", message, options);\n\t\tthis.name = \"WorkflowRunOwnershipError\";\n\t}\n}\n\n/** The run has no continuation to resume: it completed, was killed, or has no durable progress. */\nexport class WorkflowRunNotResumableError extends WorkflowRunControlError {\n\tconstructor(message: string, options?: WorkflowRunControlErrorOptions) {\n\t\tsuper(\"WORKFLOW_RUN_NOT_RESUMABLE\", message, options);\n\t\tthis.name = \"WorkflowRunNotResumableError\";\n\t}\n}\n\n/** The stage identifier matches no stage or tool node of the run. */\nexport class WorkflowStageNotFoundError extends WorkflowRunControlError {\n\tconstructor(message: string, options?: WorkflowRunControlErrorOptions) {\n\t\tsuper(\"WORKFLOW_STAGE_NOT_FOUND\", message, options);\n\t\tthis.name = \"WorkflowStageNotFoundError\";\n\t}\n}\n\n/** The stage identifier matches more than one stage or tool node; pass a more specific identifier. */\nexport class WorkflowStageAmbiguousError extends WorkflowRunControlError {\n\tconstructor(message: string, options?: WorkflowRunControlErrorOptions) {\n\t\tsuper(\"WORKFLOW_STAGE_AMBIGUOUS\", message, options);\n\t\tthis.name = \"WorkflowStageAmbiguousError\";\n\t}\n}\n\n/** A durable run can only be resumed whole; resume it without a stage identifier. */\nexport class WorkflowStageResumeUnsupportedError extends WorkflowRunControlError {\n\tconstructor(message: string, options?: WorkflowRunControlErrorOptions) {\n\t\tsuper(\"WORKFLOW_STAGE_RESUME_UNSUPPORTED\", message, options);\n\t\tthis.name = \"WorkflowStageResumeUnsupportedError\";\n\t}\n}\n\n/** Workflow durability (the run database) is unavailable, shut down, or failed. */\nexport class WorkflowRunDatabaseError extends WorkflowRunControlError {\n\tconstructor(message: string, options?: WorkflowRunControlErrorOptions) {\n\t\tsuper(\"WORKFLOW_RUN_DATABASE\", message, options);\n\t\tthis.name = \"WorkflowRunDatabaseError\";\n\t}\n}\n\n/** The workflows extension is not loaded for this session, or the session was disposed. */\nexport class WorkflowRunControlUnavailableError extends WorkflowRunControlError {\n\tconstructor(\n\t\tmessage = \"Workflow run control is unavailable for this session.\",\n\t\toptions?: WorkflowRunControlErrorOptions,\n\t) {\n\t\tsuper(\"WORKFLOW_RUN_CONTROL_UNAVAILABLE\", message, options);\n\t\tthis.name = \"WorkflowRunControlUnavailableError\";\n\t}\n}\n"]}
|
|
@@ -4,6 +4,7 @@ export interface McpServerOAuthConfig {
|
|
|
4
4
|
clientId?: string;
|
|
5
5
|
clientSecret?: string;
|
|
6
6
|
scope?: string;
|
|
7
|
+
clientName?: string;
|
|
7
8
|
}
|
|
8
9
|
/** One MCP server definition; the same schema as an `mcpServers` entry in `mcp.json`. */
|
|
9
10
|
export interface McpServerConfig {
|
|
@@ -13,7 +14,9 @@ export interface McpServerConfig {
|
|
|
13
14
|
cwd?: string;
|
|
14
15
|
url?: string;
|
|
15
16
|
headers?: Record<string, string>;
|
|
16
|
-
auth?: "oauth" | "bearer" | false
|
|
17
|
+
auth?: "oauth" | "bearer" | false | {
|
|
18
|
+
provider: string;
|
|
19
|
+
};
|
|
17
20
|
bearerToken?: string;
|
|
18
21
|
bearerTokenEnv?: string;
|
|
19
22
|
oauth?: McpServerOAuthConfig | false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-servers.d.ts","sourceRoot":"","sources":["../../src/core/mcp-servers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,MAAM,WAAW,oBAAoB;IACpC,SAAS,CAAC,EAAE,oBAAoB,GAAG,oBAAoB,CAAC;IACxD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"mcp-servers.d.ts","sourceRoot":"","sources":["../../src/core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AAuG;AACvG,MAAM,WAAW,qBAAqB;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,eAAe,CAAC;IACxB,kFAAkF;IAClF,MAAM,EAAE,SAAS,GAAG,WAAW,CAAC;IAChC,8GAA8G;IAC9G,UAAU,EAAE,UAAU,CAAC;CACvB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-servers.js","sourceRoot":"","sources":["../../src/core/mcp-servers.ts"],"names":[],"mappings":"","sourcesContent":["import type { SourceInfo } from \"./source-info.ts\";\n\nexport interface McpServerOAuthConfig {\n\tgrantType?: \"authorization_code\" | \"client_credentials\";\n\tclientId?: string;\n\tclientSecret?: string;\n\tscope?: string;\n}\n\n/** One MCP server definition; the same schema as an `mcpServers` entry in `mcp.json`. */\nexport interface McpServerConfig {\n\tcommand?: string;\n\targs?: string[];\n\tenv?: Record<string, string>;\n\tcwd?: string;\n\turl?: string;\n\theaders?: Record<string, string>;\n\tauth?: \"oauth\" | \"bearer\" | false;\n\tbearerToken?: string;\n\tbearerTokenEnv?: string;\n\toauth?: McpServerOAuthConfig | false;\n\tlifecycle?: \"keep-alive\" | \"lazy\" | \"eager\";\n\tidleTimeout?: number;\n\texposeResources?: boolean;\n\tdirectTools?: boolean | string[];\n\texcludeTools?: string[];\n\tdebug?: boolean;\n\ttimeoutMs?: number;\n\t/** Drop the server from the effective MCP configuration. */\n\tdisabled?: boolean;\n}\n\n/** An MCP server contributed by a package manifest or an extension's `pi.registerMcpServer()` call. */\nexport interface McpServerContribution {\n\tname: string;\n\tconfig: McpServerConfig;\n\t/** `package` for manifest `mcpServers`; `extension` for runtime registrations. */\n\torigin: \"package\" | \"extension\";\n\t/** Declaring manifest file for packages; registering extension path and its package source for extensions. */\n\tsourceInfo: SourceInfo;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"mcp-servers.js","sourceRoot":"","sources":["../../src/core/mcp-servers.ts"],"names":[],"mappings":"","sourcesContent":["import type { SourceInfo } from \"./source-info.ts\";\n\nexport interface McpServerOAuthConfig {\n\tgrantType?: \"authorization_code\" | \"client_credentials\";\n\tclientId?: string;\n\tclientSecret?: string;\n\tscope?: string;\n\tclientName?: string;\n}\n\n/** One MCP server definition; the same schema as an `mcpServers` entry in `mcp.json`. */\nexport interface McpServerConfig {\n\tcommand?: string;\n\targs?: string[];\n\tenv?: Record<string, string>;\n\tcwd?: string;\n\turl?: string;\n\theaders?: Record<string, string>;\n\tauth?: \"oauth\" | \"bearer\" | false | { provider: string };\n\tbearerToken?: string;\n\tbearerTokenEnv?: string;\n\toauth?: McpServerOAuthConfig | false;\n\tlifecycle?: \"keep-alive\" | \"lazy\" | \"eager\";\n\tidleTimeout?: number;\n\texposeResources?: boolean;\n\tdirectTools?: boolean | string[];\n\texcludeTools?: string[];\n\tdebug?: boolean;\n\ttimeoutMs?: number;\n\t/** Drop the server from the effective MCP configuration. */\n\tdisabled?: boolean;\n}\n\n/** An MCP server contributed by a package manifest or an extension's `pi.registerMcpServer()` call. */\nexport interface McpServerContribution {\n\tname: string;\n\tconfig: McpServerConfig;\n\t/** `package` for manifest `mcpServers`; `extension` for runtime registrations. */\n\torigin: \"package\" | \"extension\";\n\t/** Declaring manifest file for packages; registering extension path and its package source for extensions. */\n\tsourceInfo: SourceInfo;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote-catalog-provider.d.ts","sourceRoot":"","sources":["../../src/core/remote-catalog-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAKN,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,MAAM,gBAAgB,CAAC;AAOxB,eAAO,MAAM,kCAAkC,QAAqB,CAAC;AACrE;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,EAAE,SAAS,SAAS,EAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"remote-catalog-provider.d.ts","sourceRoot":"","sources":["../../src/core/remote-catalog-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAKN,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,MAAM,gBAAgB,CAAC;AAOxB,eAAO,MAAM,kCAAkC,QAAqB,CAAC;AACrE;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,EAAE,SAAS,SAAS,EAAoC,CAAC;AAmEhG,4EAA4E;AAC5E,wBAAgB,iBAAiB,CAChC,QAAQ,EAAE,QAAQ,EAClB,cAAc,GAAE,MAAiC,EACjD,gBAAgB,CAAC,EAAE,MAAM,GACvB,QAAQ,CAmGV"}
|
|
@@ -43,15 +43,10 @@ function hasOperationShape(model) {
|
|
|
43
43
|
: "contextWindow" in model && typeof model.contextWindow === "number" && model.contextWindow > 0));
|
|
44
44
|
}
|
|
45
45
|
function mergeModels(baseline, dynamic) {
|
|
46
|
-
const merged =
|
|
47
|
-
for (const model of dynamic)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
merged[index] = model;
|
|
51
|
-
else
|
|
52
|
-
merged.push(model);
|
|
53
|
-
}
|
|
54
|
-
return merged;
|
|
46
|
+
const merged = new Map();
|
|
47
|
+
for (const model of [...baseline, ...dynamic])
|
|
48
|
+
merged.set(`${getModelType(model)}\0${model.id}`, model);
|
|
49
|
+
return [...merged.values()];
|
|
55
50
|
}
|
|
56
51
|
function parseCatalog(providerId, value) {
|
|
57
52
|
const entries = Array.isArray(value)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote-catalog-provider.js","sourceRoot":"","sources":["../../src/core/remote-catalog-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,YAAY,EACZ,WAAW,GAIX,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,MAAM,wBAAwB,GAAG,gBAAgB,CAAC;AAClD,MAAM,iCAAiC,GAAG,KAAK,CAAC;AAChD,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ype AnyModel,\n\tgetModelType,\n\tisModelType,\n\ttype ModelsStoreEntry,\n\ttype ModelType,\n\ttype Provider,\n} from \"@bastani/pi-ai\";\nimport { VERSION } from \"../config.js\";\nimport { fetchWithRetry } from \"../utils/management-http.ts\";\nimport { getPiUserAgent } from \"../utils/pi-user-agent.ts\";\n\nconst DEFAULT_CATALOG_BASE_URL = \"https://pi.dev\";\nconst REMOTE_CATALOG_ATTEMPT_TIMEOUT_MS = 4_000;\nexport const REMOTE_CATALOG_REFRESH_INTERVAL_MS = 4 * 60 * 60 * 1000;\n/**\n * Model types this client can consume. Sent as `?types=` so the catalog server\n * returns the full-type shard instead of the chat-only one served to clients\n * that predate model types. A server that ignores the parameter still returns\n * the chat-only shard, which this client handles unchanged.\n */\nexport const REMOTE_CATALOG_MODEL_TYPES: readonly ModelType[] = [\"chat\", \"image\", \"classifier\"];\n\nfunction isSupportedModelType(model: { type?: unknown }): boolean {\n\treturn (\n\t\tmodel.type === undefined ||\n\t\t(typeof model.type === \"string\" && REMOTE_CATALOG_MODEL_TYPES.includes(model.type as ModelType))\n\t);\n}\n\nfunction hasOperationShape(model: unknown): boolean {\n\tif (typeof model !== \"object\" || model === null) return false;\n\tif (!(\"type\" in model) || (model.type !== \"image\" && model.type !== \"classifier\")) return true;\n\tif (!(\"cost\" in model)) return false;\n\tconst cost = model.cost;\n\treturn (\n\t\t\"id\" in model &&\n\t\ttypeof model.id === \"string\" &&\n\t\tmodel.id.length > 0 &&\n\t\t\"name\" in model &&\n\t\ttypeof model.name === \"string\" &&\n\t\t\"api\" in model &&\n\t\ttypeof model.api === \"string\" &&\n\t\t\"baseUrl\" in model &&\n\t\ttypeof model.baseUrl === \"string\" &&\n\t\t\"input\" in model &&\n\t\tArray.isArray(model.input) &&\n\t\tcost !== null &&\n\t\ttypeof cost === \"object\" &&\n\t\t[\"input\", \"output\", \"cacheRead\", \"cacheWrite\"].every(\n\t\t\t(key) => key in cost && typeof (cost as Record<string, unknown>)[key] === \"number\",\n\t\t) &&\n\t\t(model.type === \"image\"\n\t\t\t? \"output\" in model && Array.isArray(model.output) && model.output.includes(\"image\")\n\t\t\t: \"contextWindow\" in model && typeof model.contextWindow === \"number\" && model.contextWindow > 0)\n\t);\n}\n\nfunction mergeModels<TModel extends AnyModel>(baseline: readonly TModel[], dynamic: readonly TModel[]): TModel[] {\n\tconst merged = [...baseline];\n\tfor (const model of dynamic) {\n\t\tconst index = merged.findIndex((entry) => getModelType(entry) === getModelType(model) && entry.id === model.id);\n\t\tif (index >= 0) merged[index] = model;\n\t\telse merged.push(model);\n\t}\n\treturn merged;\n}\n\nfunction parseCatalog(providerId: string, value: unknown): AnyModel[] {\n\tconst entries = Array.isArray(value)\n\t\t? value\n\t\t: typeof value === \"object\" && value !== null && \"models\" in value && Array.isArray(value.models)\n\t\t\t? value.models\n\t\t\t: typeof value === \"object\" && value !== null\n\t\t\t\t? Object.values(value)\n\t\t\t\t: undefined;\n\tif (!entries) throw new Error(`Invalid model catalog for provider \"${providerId}\"`);\n\treturn entries\n\t\t.filter((entry): entry is Record<string, unknown> => typeof entry === \"object\" && entry !== null && \"id\" in entry)\n\t\t.filter(isSupportedModelType)\n\t\t.filter(hasOperationShape)\n\t\t.map((model) => ({ ...model, provider: providerId }) as AnyModel);\n}\n\nfunction remoteModels(entry: ModelsStoreEntry | undefined, localGeneratedAt: number | undefined): readonly AnyModel[] {\n\tif (!entry) return [];\n\tif (localGeneratedAt !== undefined && (entry.lastModified === undefined || entry.lastModified <= localGeneratedAt)) {\n\t\treturn [];\n\t}\n\treturn entry.models;\n}\n\n/** Add a persisted pi.dev catalog overlay to a static built-in provider. */\nexport function withRemoteCatalog(\n\tprovider: Provider,\n\tcatalogBaseUrl: string = DEFAULT_CATALOG_BASE_URL,\n\tlocalGeneratedAt?: number,\n): Provider {\n\tlet dynamicModels: readonly AnyModel[] = [];\n\n\treturn {\n\t\t...provider,\n\t\tgetModels: () =>\n\t\t\tmergeModels(\n\t\t\t\tprovider.getModels(),\n\t\t\t\tdynamicModels.filter((model) => isModelType(model, \"chat\")),\n\t\t\t),\n\t\tgetAllModels: () => mergeModels(provider.getAllModels?.() ?? provider.getModels(), dynamicModels),\n\t\trefreshModels: async (context) => {\n\t\t\t// 0.84.1 hands the snapshot in directly and coalesces concurrent refreshes\n\t\t\t// itself, so the old inflight-promise dedup is gone. Every mutation of\n\t\t\t// dynamicModels now runs inside a generation-checked publish; a false return\n\t\t\t// means a newer refresh already superseded this pass, so it must not continue.\n\t\t\tconst stored = context.stored;\n\t\t\tconst restored = remoteModels(stored, localGeneratedAt).filter(\n\t\t\t\t(model) => model.provider === provider.id && hasOperationShape(model),\n\t\t\t);\n\t\t\tif (\n\t\t\t\t!(await context.publish({\n\t\t\t\t\tupdate: () => {\n\t\t\t\t\t\tdynamicModels = restored;\n\t\t\t\t\t},\n\t\t\t\t}))\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!context.allowNetwork || context.signal.aborted) return;\n\t\t\tif (\n\t\t\t\t!context.force &&\n\t\t\t\tstored?.checkedAt !== undefined &&\n\t\t\t\tstored.lastModified !== undefined &&\n\t\t\t\tDate.now() - stored.checkedAt < REMOTE_CATALOG_REFRESH_INTERVAL_MS\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Only revalidate when a cached body backs the validator, so a 304 can never\n\t\t\t// leave the overlay empty.\n\t\t\tconst validator = stored && stored.models.length > 0 ? stored.etag : undefined;\n\t\t\tconst url = new URL(`/api/models/providers/${encodeURIComponent(provider.id)}`, catalogBaseUrl);\n\t\t\turl.searchParams.set(\"types\", REMOTE_CATALOG_MODEL_TYPES.join(\",\"));\n\t\t\tconst response = await fetchWithRetry(\n\t\t\t\turl,\n\t\t\t\t{\n\t\t\t\t\theaders: {\n\t\t\t\t\t\taccept: \"application/json\",\n\t\t\t\t\t\t\"User-Agent\": getPiUserAgent(VERSION),\n\t\t\t\t\t\t...(validator ? { \"if-none-match\": validator } : {}),\n\t\t\t\t\t},\n\t\t\t\t\tsignal: context.signal,\n\t\t\t\t},\n\t\t\t\t{ attemptTimeoutMs: REMOTE_CATALOG_ATTEMPT_TIMEOUT_MS },\n\t\t\t);\n\t\t\tif (context.signal.aborted) return;\n\t\t\tconst checkedAt = Date.now();\n\t\t\t// Unchanged: dynamicModels already holds the stored overlay, so only the\n\t\t\t// freshness window moves.\n\t\t\tif (response.status === 304 && stored) {\n\t\t\t\tawait context.publish({ persist: { ...stored, checkedAt } });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (response.status === 404 || response.status === 501) {\n\t\t\t\tawait context.publish({\n\t\t\t\t\tpersist: {\n\t\t\t\t\t\t...(stored ?? { models: [] }),\n\t\t\t\t\t\tcheckedAt,\n\t\t\t\t\t\tlastModified: 0,\n\t\t\t\t\t\tetag: undefined,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!response.ok) {\n\t\t\t\t// Transient failure: the cached body and its validator stay valid, so keep the\n\t\t\t\t// etag and let the next refresh revalidate instead of downloading the catalog.\n\t\t\t\tawait context.publish({ persist: { ...(stored ?? { models: [] }), checkedAt } });\n\t\t\t\tthrow new Error(`Model catalog request failed for ${provider.id}: ${response.status}`);\n\t\t\t}\n\t\t\tconst refreshed = parseCatalog(provider.id, await response.json());\n\t\t\tconst lastModified = Date.parse(response.headers.get(\"last-modified\") ?? \"\");\n\t\t\tif (context.signal.aborted) return;\n\t\t\tconst entry: ModelsStoreEntry = {\n\t\t\t\tmodels: refreshed,\n\t\t\t\tcheckedAt,\n\t\t\t\tlastModified: Number.isNaN(lastModified) ? 0 : lastModified,\n\t\t\t\tetag: response.headers.get(\"etag\") ?? undefined,\n\t\t\t};\n\t\t\tconst published = remoteModels(entry, localGeneratedAt);\n\t\t\tawait context.publish({\n\t\t\t\tpersist: entry,\n\t\t\t\tupdate: () => {\n\t\t\t\t\tdynamicModels = published;\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t};\n}\n"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,EAAE,gBAAgB,CAAC,CAAC;YACxD,MAAM,OAAO,CAAC,OAAO,CAAC;gBACrB,OAAO,EAAE,KAAK;gBACd,MAAM,EAAE,GAAG,EAAE;oBACZ,aAAa,GAAG,SAAS,CAAC;gBAC3B,CAAC;aACD,CAAC,CAAC;QACJ,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import {\n\ttype AnyModel,\n\tgetModelType,\n\tisModelType,\n\ttype ModelsStoreEntry,\n\ttype ModelType,\n\ttype Provider,\n} from \"@bastani/pi-ai\";\nimport { VERSION } from \"../config.js\";\nimport { fetchWithRetry } from \"../utils/management-http.ts\";\nimport { getPiUserAgent } from \"../utils/pi-user-agent.ts\";\n\nconst DEFAULT_CATALOG_BASE_URL = \"https://pi.dev\";\nconst REMOTE_CATALOG_ATTEMPT_TIMEOUT_MS = 4_000;\nexport const REMOTE_CATALOG_REFRESH_INTERVAL_MS = 4 * 60 * 60 * 1000;\n/**\n * Model types this client can consume. Sent as `?types=` so the catalog server\n * returns the full-type shard instead of the chat-only one served to clients\n * that predate model types. A server that ignores the parameter still returns\n * the chat-only shard, which this client handles unchanged.\n */\nexport const REMOTE_CATALOG_MODEL_TYPES: readonly ModelType[] = [\"chat\", \"image\", \"classifier\"];\n\nfunction isSupportedModelType(model: { type?: unknown }): boolean {\n\treturn (\n\t\tmodel.type === undefined ||\n\t\t(typeof model.type === \"string\" && REMOTE_CATALOG_MODEL_TYPES.includes(model.type as ModelType))\n\t);\n}\n\nfunction hasOperationShape(model: unknown): boolean {\n\tif (typeof model !== \"object\" || model === null) return false;\n\tif (!(\"type\" in model) || (model.type !== \"image\" && model.type !== \"classifier\")) return true;\n\tif (!(\"cost\" in model)) return false;\n\tconst cost = model.cost;\n\treturn (\n\t\t\"id\" in model &&\n\t\ttypeof model.id === \"string\" &&\n\t\tmodel.id.length > 0 &&\n\t\t\"name\" in model &&\n\t\ttypeof model.name === \"string\" &&\n\t\t\"api\" in model &&\n\t\ttypeof model.api === \"string\" &&\n\t\t\"baseUrl\" in model &&\n\t\ttypeof model.baseUrl === \"string\" &&\n\t\t\"input\" in model &&\n\t\tArray.isArray(model.input) &&\n\t\tcost !== null &&\n\t\ttypeof cost === \"object\" &&\n\t\t[\"input\", \"output\", \"cacheRead\", \"cacheWrite\"].every(\n\t\t\t(key) => key in cost && typeof (cost as Record<string, unknown>)[key] === \"number\",\n\t\t) &&\n\t\t(model.type === \"image\"\n\t\t\t? \"output\" in model && Array.isArray(model.output) && model.output.includes(\"image\")\n\t\t\t: \"contextWindow\" in model && typeof model.contextWindow === \"number\" && model.contextWindow > 0)\n\t);\n}\n\nfunction mergeModels<TModel extends AnyModel>(baseline: readonly TModel[], dynamic: readonly TModel[]): TModel[] {\n\tconst merged = new Map<string, TModel>();\n\tfor (const model of [...baseline, ...dynamic]) merged.set(`${getModelType(model)}\\0${model.id}`, model);\n\treturn [...merged.values()];\n}\n\nfunction parseCatalog(providerId: string, value: unknown): AnyModel[] {\n\tconst entries = Array.isArray(value)\n\t\t? value\n\t\t: typeof value === \"object\" && value !== null && \"models\" in value && Array.isArray(value.models)\n\t\t\t? value.models\n\t\t\t: typeof value === \"object\" && value !== null\n\t\t\t\t? Object.values(value)\n\t\t\t\t: undefined;\n\tif (!entries) throw new Error(`Invalid model catalog for provider \"${providerId}\"`);\n\treturn entries\n\t\t.filter((entry): entry is Record<string, unknown> => typeof entry === \"object\" && entry !== null && \"id\" in entry)\n\t\t.filter(isSupportedModelType)\n\t\t.filter(hasOperationShape)\n\t\t.map((model) => ({ ...model, provider: providerId }) as AnyModel);\n}\n\nfunction remoteModels(entry: ModelsStoreEntry | undefined, localGeneratedAt: number | undefined): readonly AnyModel[] {\n\tif (!entry) return [];\n\tif (localGeneratedAt !== undefined && (entry.lastModified === undefined || entry.lastModified <= localGeneratedAt)) {\n\t\treturn [];\n\t}\n\treturn entry.models;\n}\n\n/** Add a persisted pi.dev catalog overlay to a static built-in provider. */\nexport function withRemoteCatalog(\n\tprovider: Provider,\n\tcatalogBaseUrl: string = DEFAULT_CATALOG_BASE_URL,\n\tlocalGeneratedAt?: number,\n): Provider {\n\tlet dynamicModels: readonly AnyModel[] = [];\n\n\treturn {\n\t\t...provider,\n\t\tgetModels: () =>\n\t\t\tmergeModels(\n\t\t\t\tprovider.getModels(),\n\t\t\t\tdynamicModels.filter((model) => isModelType(model, \"chat\")),\n\t\t\t),\n\t\tgetAllModels: () => mergeModels(provider.getAllModels?.() ?? provider.getModels(), dynamicModels),\n\t\trefreshModels: async (context) => {\n\t\t\t// 0.84.1 hands the snapshot in directly and coalesces concurrent refreshes\n\t\t\t// itself, so the old inflight-promise dedup is gone. Every mutation of\n\t\t\t// dynamicModels now runs inside a generation-checked publish; a false return\n\t\t\t// means a newer refresh already superseded this pass, so it must not continue.\n\t\t\tconst stored = context.stored;\n\t\t\tconst restored = remoteModels(stored, localGeneratedAt).filter(\n\t\t\t\t(model) => model.provider === provider.id && hasOperationShape(model),\n\t\t\t);\n\t\t\tif (\n\t\t\t\t!(await context.publish({\n\t\t\t\t\tupdate: () => {\n\t\t\t\t\t\tdynamicModels = restored;\n\t\t\t\t\t},\n\t\t\t\t}))\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!context.allowNetwork || context.signal.aborted) return;\n\t\t\tif (\n\t\t\t\t!context.force &&\n\t\t\t\tstored?.checkedAt !== undefined &&\n\t\t\t\tstored.lastModified !== undefined &&\n\t\t\t\tDate.now() - stored.checkedAt < REMOTE_CATALOG_REFRESH_INTERVAL_MS\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Only revalidate when a cached body backs the validator, so a 304 can never\n\t\t\t// leave the overlay empty.\n\t\t\tconst validator = stored && stored.models.length > 0 ? stored.etag : undefined;\n\t\t\tconst url = new URL(`/api/models/providers/${encodeURIComponent(provider.id)}`, catalogBaseUrl);\n\t\t\turl.searchParams.set(\"types\", REMOTE_CATALOG_MODEL_TYPES.join(\",\"));\n\t\t\tconst response = await fetchWithRetry(\n\t\t\t\turl,\n\t\t\t\t{\n\t\t\t\t\theaders: {\n\t\t\t\t\t\taccept: \"application/json\",\n\t\t\t\t\t\t\"User-Agent\": getPiUserAgent(VERSION),\n\t\t\t\t\t\t...(validator ? { \"if-none-match\": validator } : {}),\n\t\t\t\t\t},\n\t\t\t\t\tsignal: context.signal,\n\t\t\t\t},\n\t\t\t\t{ attemptTimeoutMs: REMOTE_CATALOG_ATTEMPT_TIMEOUT_MS },\n\t\t\t);\n\t\t\tif (context.signal.aborted) return;\n\t\t\tconst checkedAt = Date.now();\n\t\t\t// Unchanged: dynamicModels already holds the stored overlay, so only the\n\t\t\t// freshness window moves.\n\t\t\tif (response.status === 304 && stored) {\n\t\t\t\tawait context.publish({ persist: { ...stored, checkedAt } });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (response.status === 404 || response.status === 501) {\n\t\t\t\tawait context.publish({\n\t\t\t\t\tpersist: {\n\t\t\t\t\t\t...(stored ?? { models: [] }),\n\t\t\t\t\t\tcheckedAt,\n\t\t\t\t\t\tlastModified: 0,\n\t\t\t\t\t\tetag: undefined,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!response.ok) {\n\t\t\t\t// Transient failure: the cached body and its validator stay valid, so keep the\n\t\t\t\t// etag and let the next refresh revalidate instead of downloading the catalog.\n\t\t\t\tawait context.publish({ persist: { ...(stored ?? { models: [] }), checkedAt } });\n\t\t\t\tthrow new Error(`Model catalog request failed for ${provider.id}: ${response.status}`);\n\t\t\t}\n\t\t\tconst refreshed = parseCatalog(provider.id, await response.json());\n\t\t\tconst lastModified = Date.parse(response.headers.get(\"last-modified\") ?? \"\");\n\t\t\tif (context.signal.aborted) return;\n\t\t\tconst entry: ModelsStoreEntry = {\n\t\t\t\tmodels: refreshed,\n\t\t\t\tcheckedAt,\n\t\t\t\tlastModified: Number.isNaN(lastModified) ? 0 : lastModified,\n\t\t\t\tetag: response.headers.get(\"etag\") ?? undefined,\n\t\t\t};\n\t\t\tconst published = remoteModels(entry, localGeneratedAt);\n\t\t\tawait context.publish({\n\t\t\t\tpersist: entry,\n\t\t\t\tupdate: () => {\n\t\t\t\t\tdynamicModels = published;\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t};\n}\n"]}
|
package/dist/core/sdk.js
CHANGED
|
@@ -509,6 +509,7 @@ async function constructAgentSession(options, deferStart) {
|
|
|
509
509
|
modelRuntime,
|
|
510
510
|
cacheWarmer,
|
|
511
511
|
initialActiveToolNames,
|
|
512
|
+
usesDefaultTools: options.tools === undefined && !options.noTools,
|
|
512
513
|
allowedToolNames,
|
|
513
514
|
excludedToolNames: options.excludedTools,
|
|
514
515
|
extensionRunnerRef,
|