@asterism-app/sdk 1.8.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/resources-and-tools.md +3 -1
- package/docs/views-and-settings.md +55 -0
- package/package.json +1 -1
- package/src/json.ts +2 -1
- package/src/module-contract.ts +12 -5
- package/src/renderer-commands.ts +43 -0
- package/src/renderer-island.ts +15 -0
- package/src/renderer.ts +5 -1
- package/src/runtime-contracts.ts +4 -2
- package/src/runtime-deadlines.ts +10 -0
- package/src/runtime-resources.ts +2 -2
- package/src/runtime-tools.ts +5 -3
- package/src/runtime.ts +1 -0
- package/src/tool-validation.ts +1 -1
- package/src/workspace.ts +2 -2
|
@@ -28,6 +28,8 @@ Choose a tool name for the operation's meaning. Reuse an existing tool declarati
|
|
|
28
28
|
|
|
29
29
|
For model calls, `resource_id` selects the resource, `args` supplies the operation's shared parameters, and `target` selects content, scope, or a resource-specific view. A reading target can select a file, a line range, and whether its text includes edit anchors. Each implementation declares the selections it supports. The same tool preserves its meaning and `args` schema across resources. Inspection exposes the tools available on the selected resource with their argument and target schemas. A result schema defines how output is encoded for storage and transport, so it is not published to models; an actual outcome shows what an operation returns.
|
|
30
30
|
|
|
31
|
+
Tool arguments and resource targets are JSON objects or null. Declare a named field for a scalar or collection, such as `{ title: string }` or `{ ids: string[] }`. Object members may contain any JSON value; each tool determines its fields and whether it accepts null. Resource calls default an omitted target to null and omitted arguments to `{}`. Direct calls and resource scripts use the same input shapes.
|
|
32
|
+
|
|
31
33
|
Use a top-level tool for operations on the execution context or shared resource lifecycle, such as creation and renaming. The host supplies caller identity and execution scope.
|
|
32
34
|
|
|
33
35
|
Both resource tools and top-level tools receive `caller`, containing the access owner's resource reference and title. When the executing paradigm supplies an Agent role name, it is available as `caller.agent`. The role identifies the executing configuration independently of the access owner; several roles can execute through one shared resource. Role identity carries no configuration object or additional resource access.
|
|
@@ -44,7 +46,7 @@ Resource inspection includes the interaction requirement. Resource scripts are n
|
|
|
44
46
|
|
|
45
47
|
Use `plugin.execution.run` to execute one model request with tools bound to a resource's current links and the real session. Supply that resource as the access owner and select the interaction capability. The execution holds captured relationships through the tool batch; subsequent calls capture current links again. Calls sharing an access owner keep independent message inputs and can run concurrently.
|
|
46
48
|
|
|
47
|
-
Supply the executing role's name through `agent` and any resource type allowlist or denylist through `resources`. The host captures these inputs with the request. Resource policy is enforced by the shared dispatcher
|
|
49
|
+
Supply the executing role's name through `agent` and any resource type allowlist or denylist through `resources`. The host captures these inputs with the request. Resource policy is enforced by the shared dispatcher. Resource listings retain state, inspection retains state and tool schemas, and both include a tool-call restriction notice naming the role when supplied. Calls on restricted types are rejected before the implementation runs. Creation and linked context remain available. Top-level tools can query the captured tool-call restriction by resource type to annotate discovery results, including creation catalogs, without re-reading role configuration. Individual resource tools need no role-policy checks.
|
|
48
50
|
|
|
49
51
|
Resource holds do not block history movement. Use an object busy scope for work that depends on the timeline, such as a conversation writing its responses there. Object-bound managed tasks protect history by default; use `affectsHistory: false` for external runtime tasks that should still stop when their owning resource leaves the session.
|
|
50
52
|
|
|
@@ -18,6 +18,8 @@ Resource card views, settings pages, and islands can use the renderer island cap
|
|
|
18
18
|
|
|
19
19
|
Supply a plugin-local identity, accessible label, opening element, and content renderer. Choose a content surface for an editor or another view that needs more width. The host manages layout and focus. The opened view has an independent plugin region; pass its resource reference and other domain inputs explicitly rather than relying on the source component's React context or mount lifetime.
|
|
20
20
|
|
|
21
|
+
Escape is not a general island close shortcut. For a cancellable task, its island owner declares one action with `useRendererIslandCancel`; pass null when the task has no cancellation action. Local controls handle Escape first, and an island without an action does not pass cancellation to its opening island. The callback owns the outcome: to dismiss the task, call the island's normal close operation so unsaved-change guards still apply. Functional windows and the shared panel frame do not declare cancellation automatically.
|
|
22
|
+
|
|
21
23
|
Use the island panel for its title, actions, and close control. Its fill layout lets an editor own scrolling. Mark unsaved content as dirty so closing, closure through the opening island, session navigation, and application exit ask before discarding it. A close guard can also retain a view while a save is pending. Closing the island releases its view calls without ending independent backend services.
|
|
22
24
|
|
|
23
25
|
## Open resource locations
|
|
@@ -52,6 +54,59 @@ Managed configuration suits schema-validated settings. Other plugin data can use
|
|
|
52
54
|
|
|
53
55
|
Closing a page releases its view subscriptions. It does not end every service the plugin uses.
|
|
54
56
|
|
|
57
|
+
## Contribute application commands
|
|
58
|
+
|
|
59
|
+
Declare command groups in the renderer plugin's `commands` field. The application palette displays each group as **Plugin name · Group**, keeping groups separate even when different plugins use the same label. Group IDs are local to the plugin; command IDs are local to the group.
|
|
60
|
+
|
|
61
|
+
Each group's `useCommands(context)` is a React hook, mounted in that plugin's calls and preferences scope while the palette is open. Call hooks unconditionally, then use `when: false` to hide commands that do not apply. `disabled: true` keeps an unavailable command visible. The context supplies the current session snapshot, or null outside a session, and whether that session is ready for operations. A session command can hide when no session exists and disable while it is not ready.
|
|
62
|
+
|
|
63
|
+
An action uses `onAction`; it decides when to dismiss the palette through `context.close()`. For asynchronous work, retain pending and failure state in the hook, disable reentry, show feedback in `detail`, and close after success. Invoke backend work through ordinary typed plugin calls, passing session identity explicitly when needed. Renderer commands need no separate backend registry.
|
|
64
|
+
|
|
65
|
+
A control uses `control` instead of `onAction`. It is a real interactive child, such as an input, switch, or select, rather than an action row that activates around it. Its component owns its interaction and may use plugin-scoped hooks. Compose controls from the plugin's own UI components; the command contract does not require a UI library.
|
|
66
|
+
|
|
67
|
+
For example, a plugin can combine a persistent preference control with a reset action:
|
|
68
|
+
|
|
69
|
+
```tsx
|
|
70
|
+
import { useState } from "react";
|
|
71
|
+
import { z } from "zod";
|
|
72
|
+
import {
|
|
73
|
+
defineRendererPlugin, useRendererPreferences,
|
|
74
|
+
type RendererCommandGroup,
|
|
75
|
+
} from "@asterism-app/sdk/renderer";
|
|
76
|
+
|
|
77
|
+
function CompactRows() {
|
|
78
|
+
const preferences = useRendererPreferences();
|
|
79
|
+
const [compact, setCompact] = useState(
|
|
80
|
+
() => preferences.get("compactRows", z.boolean()) ?? false,
|
|
81
|
+
);
|
|
82
|
+
return <input type="checkbox" aria-label="Compact rows" checked={compact}
|
|
83
|
+
onChange={event => {
|
|
84
|
+
const next = event.currentTarget.checked;
|
|
85
|
+
preferences.set("compactRows", next);
|
|
86
|
+
setCompact(next);
|
|
87
|
+
}} />;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const appearance: RendererCommandGroup = {
|
|
91
|
+
id: "appearance", label: "Appearance",
|
|
92
|
+
useCommands({ close }) {
|
|
93
|
+
const preferences = useRendererPreferences();
|
|
94
|
+
return [
|
|
95
|
+
{ id: "compact", label: "Compact rows", control: <CompactRows /> },
|
|
96
|
+
{
|
|
97
|
+
id: "reset", label: "Reset row spacing",
|
|
98
|
+
onAction() {
|
|
99
|
+
preferences.set("compactRows", null);
|
|
100
|
+
close();
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
];
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export default defineRendererPlugin({ commands: [appearance] });
|
|
108
|
+
```
|
|
109
|
+
|
|
55
110
|
## Start work from Home
|
|
56
111
|
|
|
57
112
|
A session entry supplies the complete starting interface for a plugin's workflow. It owns drafts, validation feedback, submission, and the initial title. Submit through a typed plugin call, prepare resources in the backend, and initialize the session atomically. Open the resulting session using the entry's host-provided callback.
|
package/package.json
CHANGED
package/src/json.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
|
|
3
|
-
export type
|
|
3
|
+
export type JsonObject = { [key: string]: Json };
|
|
4
|
+
export type Json = null | boolean | number | string | Json[] | JsonObject;
|
|
4
5
|
|
|
5
6
|
function isPlainObject(value: object): boolean {
|
|
6
7
|
const prototype = Object.getPrototypeOf(value);
|
package/src/module-contract.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import type { Json } from "./json.ts";
|
|
2
|
+
import type { Json, JsonObject } from "./json.ts";
|
|
3
3
|
import { contractReferenceSchema, type ContractReference, type DataContract } from "./presentation.ts";
|
|
4
4
|
|
|
5
5
|
export interface ResourceContract<S extends Json = Json> {
|
|
@@ -7,18 +7,25 @@ export interface ResourceContract<S extends Json = Json> {
|
|
|
7
7
|
/** Decodes saved state; creation callbacks return S for encoding before persistence. State is arbitrary JSON, stored separately from host identity and title. */
|
|
8
8
|
stateSchema: z.ZodType<S>;
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
/** Tool inputs are structured parameter objects or null; object members may contain any JSON value. */
|
|
11
|
+
export type ToolInput = JsonObject | null;
|
|
12
|
+
/** The transport supplies JSON values; this schema constrains only their root shape. */
|
|
13
|
+
export const toolInputSchema = z.looseObject({}).nullable() as z.ZodType<ToolInput>;
|
|
14
|
+
|
|
15
|
+
export interface ToolContract<A extends ToolInput = ToolInput> extends ContractReference {
|
|
11
16
|
name: string;
|
|
12
17
|
description: string;
|
|
13
18
|
guidelines: readonly string[];
|
|
19
|
+
/** Structured parameters; a tool determines its fields and whether null is accepted. */
|
|
14
20
|
argsSchema: z.ZodType<A>;
|
|
15
21
|
/** Execution requires an endpoint that can receive user interaction. Output rendering alone does not require it. */
|
|
16
22
|
requiresInteraction?: boolean;
|
|
17
23
|
}
|
|
18
24
|
/** Tool definitions fix selection descriptions, usage guidance, and args; implementations add only target/result and execution information. */
|
|
19
|
-
export interface ImplementationContract<S extends Json, T extends
|
|
25
|
+
export interface ImplementationContract<S extends Json, T extends ToolInput, A extends ToolInput, O extends Json> extends DataContract<O> {
|
|
20
26
|
resource: ResourceContract<S>;
|
|
21
27
|
tool: ToolContract<A>;
|
|
28
|
+
/** Structured selection within the resource; each implementation determines whether null is accepted. */
|
|
22
29
|
targetSchema: z.ZodType<T>;
|
|
23
30
|
effect: "read" | "write";
|
|
24
31
|
/** Sequential operations share submission order; parallel operations can overlap either lane. */
|
|
@@ -32,13 +39,13 @@ function requireDescription(schema: z.ZodType, subject: string): void {
|
|
|
32
39
|
if (!schema.description?.trim()) throw new Error(`Missing schema description: ${subject}`);
|
|
33
40
|
try { z.toJSONSchema(schema); } catch (error) { throw new Error(`Schema is not representable as JSON Schema: ${subject}`, { cause: error }); }
|
|
34
41
|
}
|
|
35
|
-
export function defineTool<A extends
|
|
42
|
+
export function defineTool<A extends ToolInput>(definition: ToolContract<A>): ToolContract<A> {
|
|
36
43
|
if (!definition.name.trim() || !definition.description.trim()) throw new Error("Tool name and description must not be empty.");
|
|
37
44
|
if (definition.guidelines.some(guideline => !guideline.trim())) throw new Error(`Empty tool guideline: ${definition.name}`);
|
|
38
45
|
requireDescription(definition.argsSchema, `${definition.name}.args`);
|
|
39
46
|
return { ...definition, ...contractReferenceSchema.parse({ id: definition.id }), guidelines: [...definition.guidelines] };
|
|
40
47
|
}
|
|
41
|
-
export function defineImplementation<S extends Json, T extends
|
|
48
|
+
export function defineImplementation<S extends Json, T extends ToolInput, A extends ToolInput, O extends Json>(
|
|
42
49
|
definition: ImplementationContract<S, T, A, O>,
|
|
43
50
|
): ImplementationContract<S, T, A, O> {
|
|
44
51
|
requireDescription(definition.targetSchema, `${definition.id}.target`);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { UiText } from "./i18n.ts";
|
|
3
|
+
import type { RendererSessionSnapshot } from "./renderer-session.ts";
|
|
4
|
+
|
|
5
|
+
/** Application command context, independent of any resource or Agent view. */
|
|
6
|
+
export interface RendererCommandContext {
|
|
7
|
+
/** The session being viewed; null on Home or in application settings. */
|
|
8
|
+
readonly session: RendererSessionSnapshot | null;
|
|
9
|
+
/** Whether that session can accept operations; false outside a session. */
|
|
10
|
+
readonly ready: boolean;
|
|
11
|
+
/** Dismiss the palette, for example after a successful action. */
|
|
12
|
+
close(): void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface RendererCommandBase {
|
|
16
|
+
/** Stable non-empty trimmed identity, unique among siblings. */
|
|
17
|
+
id: string;
|
|
18
|
+
label: UiText;
|
|
19
|
+
keywords?: readonly string[];
|
|
20
|
+
icon?: ReactNode;
|
|
21
|
+
/** False hides the command; omitted means visible. */
|
|
22
|
+
when?: boolean;
|
|
23
|
+
/** Disabled commands remain visible; a disabled page also disables its descendants. */
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
/** Read-only supplementary content, including action feedback; contains no interactive controls. */
|
|
26
|
+
detail?: ReactNode;
|
|
27
|
+
/** Marks the saved/current choice independently of keyboard navigation highlight. */
|
|
28
|
+
current?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** An entry executes an action or opens a nested command page. Actions own dismissal through context.close. */
|
|
32
|
+
export type RendererCommand = RendererCommandBase & (
|
|
33
|
+
| { onAction(): void; children?: never }
|
|
34
|
+
| { children: readonly RendererCommand[]; onAction?: never }
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
export interface RendererCommandGroup {
|
|
38
|
+
/** Stable group identity within the contributing plugin. */
|
|
39
|
+
id: string;
|
|
40
|
+
label: UiText;
|
|
41
|
+
/** Runs as a hook in the plugin's calls and preferences scope while the application palette is open, including nested pages. */
|
|
42
|
+
useCommands(context: RendererCommandContext): readonly RendererCommand[];
|
|
43
|
+
}
|
package/src/renderer-island.ts
CHANGED
|
@@ -16,6 +16,8 @@ export interface RendererIslandSpec {
|
|
|
16
16
|
size?: "panel" | "content";
|
|
17
17
|
render: () => ReactNode;
|
|
18
18
|
}
|
|
19
|
+
/** Explicit cancellation action of an island; cancellation may close it through the usual close guards. */
|
|
20
|
+
export type RendererIslandCancel = () => void | Promise<void>;
|
|
19
21
|
/** Close guard: returning false (or resolving to false) aborts closing; may asynchronously wait for user confirmation. */
|
|
20
22
|
export type RendererCloseGuard = () => boolean | Promise<boolean>;
|
|
21
23
|
export interface RendererIsland {
|
|
@@ -29,6 +31,8 @@ export interface RendererIsland {
|
|
|
29
31
|
closeOwned(options?: { force?: boolean }): Promise<boolean>;
|
|
30
32
|
/** Register a close guard for this island and return an unregister function. Normally used through useRendererCloseGuard. */
|
|
31
33
|
guard(guard: RendererCloseGuard): () => void;
|
|
34
|
+
/** Register the containing island's cancellation action. One owner declares this action; unregister on cleanup. */
|
|
35
|
+
onCancel(action: RendererIslandCancel): () => void;
|
|
32
36
|
}
|
|
33
37
|
/**
|
|
34
38
|
* Panel island frame: the title bar stays fixed and the content scrolls independently; the primary action, island menu, and close control sit on the right of the title bar.
|
|
@@ -64,6 +68,17 @@ export function useRendererCloseGuard(guard: RendererCloseGuard | null) {
|
|
|
64
68
|
latest.current = guard;
|
|
65
69
|
useEffect(() => island.guard(() => latest.current ? latest.current() : true), [island]);
|
|
66
70
|
}
|
|
71
|
+
/** Declare cancellation for an island owned by this content; null leaves it without an island-level Escape action.
|
|
72
|
+
* Escape targets only the focused island, after local controls; it does not fall back to the opening island.
|
|
73
|
+
* Declare one action per island. Closing capability and the panel frame do not imply cancellation.
|
|
74
|
+
*/
|
|
75
|
+
export function useRendererIslandCancel(action: RendererIslandCancel | null) {
|
|
76
|
+
const island = useRendererIsland();
|
|
77
|
+
const latest = useRef(action);
|
|
78
|
+
latest.current = action;
|
|
79
|
+
const enabled = action !== null;
|
|
80
|
+
useEffect(() => enabled ? island.onCancel(() => latest.current?.()) : undefined, [island, enabled]);
|
|
81
|
+
}
|
|
67
82
|
/** Host-rendered panel frame for use within islands opened by plugins. */
|
|
68
83
|
export function IslandPanel(props: RendererIslandPanelProps) {
|
|
69
84
|
return createElement(required(useContext(Panel), "island panel"), props);
|
package/src/renderer.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** SDK renderer entry point:
|
|
1
|
+
/** SDK renderer entry point: plugin views, application commands, and frontend capabilities; React is shared by the host. */
|
|
2
2
|
import { createContext, createElement, useContext, type ComponentType, type ReactNode } from "react";
|
|
3
3
|
import type { UiText } from "./i18n.ts";
|
|
4
4
|
import type { CardAppearance } from "./card.ts";
|
|
@@ -13,6 +13,7 @@ export * from "./renderer-session.ts";
|
|
|
13
13
|
export * from "./renderer-services.ts";
|
|
14
14
|
export * from "./renderer-calls.ts";
|
|
15
15
|
export * from "./renderer-creation.ts";
|
|
16
|
+
export type * from "./renderer-commands.ts";
|
|
16
17
|
export * from "./renderer-tools.ts";
|
|
17
18
|
export * from "./renderer-records.ts";
|
|
18
19
|
export * from "./renderer-card.ts";
|
|
@@ -27,6 +28,7 @@ import type { RendererContentInput, RendererInputOptions } from "./renderer-cont
|
|
|
27
28
|
import type { ContentReader } from "./content-runtime.ts";
|
|
28
29
|
export type { ContentReader } from "./content-runtime.ts";
|
|
29
30
|
import type { CreationEntry } from "./renderer-creation.ts";
|
|
31
|
+
import type { RendererCommandGroup } from "./renderer-commands.ts";
|
|
30
32
|
import type { ToolRenderer } from "./renderer-tools.ts";
|
|
31
33
|
import type { EventSubscriber } from "./events.ts";
|
|
32
34
|
import type { PluginCalls } from "./calls.ts";
|
|
@@ -146,6 +148,8 @@ export interface PluginSessionEntry {
|
|
|
146
148
|
export interface RendererPlugin {
|
|
147
149
|
modules?: readonly RendererModule[];
|
|
148
150
|
settings?: readonly PluginSettingsPage[];
|
|
151
|
+
/** Application palette groups, attributed to this plugin independently of resource views. */
|
|
152
|
+
commands?: readonly RendererCommandGroup[];
|
|
149
153
|
sessionEntries?: readonly PluginSessionEntry[];
|
|
150
154
|
prepare?(context: RendererPrepareContext): Promise<void>;
|
|
151
155
|
closing?(): void | Promise<void>;
|
package/src/runtime-contracts.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { ConfigContract } from "./config.ts";
|
|
|
5
5
|
import type { DatabaseSync } from "node:sqlite";
|
|
6
6
|
import type { Json } from "./json.ts";
|
|
7
7
|
import type { PluginNamespace } from "./plugin.ts";
|
|
8
|
-
import type { ResourceContract, ImplementationContract } from "./module-contract.ts";
|
|
8
|
+
import type { ResourceContract, ImplementationContract, ToolInput } from "./module-contract.ts";
|
|
9
9
|
import type { DataContract, Presentation } from "./presentation.ts";
|
|
10
10
|
import type { RecordContract, SessionRecord } from "./records.ts";
|
|
11
11
|
import type { EventContract, PluginEvents } from "./events.ts";
|
|
@@ -59,6 +59,7 @@ export interface PluginContext {
|
|
|
59
59
|
readonly secrets: PluginSecrets;
|
|
60
60
|
db(): DatabaseSync;
|
|
61
61
|
readonly tasks: PluginTasks;
|
|
62
|
+
readonly deadlines: import("./runtime-deadlines.ts").DeadlineServices;
|
|
62
63
|
readonly models: ModelServices;
|
|
63
64
|
readonly execution: import("./runtime-execution.ts").ExecutionServices;
|
|
64
65
|
readonly content: import("./content-runtime.ts").ContentServices;
|
|
@@ -161,9 +162,10 @@ export interface ToolInvocation extends ToolInvocationInfo {
|
|
|
161
162
|
toModel?(data: Json): ToolModelOutput;
|
|
162
163
|
}
|
|
163
164
|
export interface ToolContribution {
|
|
164
|
-
readonly contract: ImplementationContract<Json,
|
|
165
|
+
readonly contract: ImplementationContract<Json, ToolInput, ToolInput, Json>;
|
|
165
166
|
/** Bind resource-specific access and configuration at the model request boundary. The returned contribution handles that request's calls. */
|
|
166
167
|
capture?(resource: ResourceSnapshot, object: ObjectReader, caller: ToolCaller): ToolContribution;
|
|
168
|
+
/** Raw model inputs are validated against the target and argument contracts before execution. */
|
|
167
169
|
prepare(resource: ResourceSnapshot, object: ObjectExecutor, target: Json, args: Json, caller: ToolCaller, interactive: boolean): ToolInvocation | PreparedResult;
|
|
168
170
|
}
|
|
169
171
|
export interface ModuleContribution {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** In-memory absolute deadlines; consumers own durable state and missed-occurrence behavior. */
|
|
2
|
+
export interface DeadlineServices {
|
|
3
|
+
/**
|
|
4
|
+
* Schedule one callback at a finite Unix timestamp in milliseconds. Overdue callbacks run asynchronously.
|
|
5
|
+
* Wakeups recheck wall-clock time, including after system resume. Callback failures are logged.
|
|
6
|
+
* Cancellation (the returned function or signal) removes a pending callback; it does not interrupt one already running.
|
|
7
|
+
* Plugin callbacks are cancelled when the plugin lifetime ends. Pass an attachment lifetime's signal for resource-owned deadlines.
|
|
8
|
+
*/
|
|
9
|
+
schedule(at: number, callback: () => void | Promise<void>, options?: { signal?: AbortSignal }): () => void;
|
|
10
|
+
}
|
package/src/runtime-resources.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { ActionContract, CreationContract } from "./commands.ts";
|
|
|
2
2
|
import type { z } from "zod";
|
|
3
3
|
import { jsonSchema, type Json } from "./json.ts";
|
|
4
4
|
import { defaultToolModel, type ToolModelOutput } from "./tool-result.ts";
|
|
5
|
-
import type { ResourceContract, ImplementationContract } from "./module-contract.ts";
|
|
5
|
+
import type { ResourceContract, ImplementationContract, ToolInput } from "./module-contract.ts";
|
|
6
6
|
import type { RecordContract } from "./records.ts";
|
|
7
7
|
import { reference, present, type DataContract } from "./presentation.ts";
|
|
8
8
|
import { PluginApiError } from "./runtime.ts";
|
|
@@ -67,7 +67,7 @@ export function implementResource<S extends Json, V extends Json>(
|
|
|
67
67
|
attach(parse(resource.stateSchema, snapshot.data, "resource"), object, lifetime) } : {}),
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
|
-
export function implementTool<S extends Json, T extends
|
|
70
|
+
export function implementTool<S extends Json, T extends ToolInput, A extends ToolInput, D extends Json>(
|
|
71
71
|
contract: ImplementationContract<S, T, A, D>, definition: {
|
|
72
72
|
call(data: S, target: T, args: A, context: {
|
|
73
73
|
object: ObjectExecutor; caller: ToolCaller; signal: AbortSignal; interactive: boolean; publish(data: NoInfer<D>): void;
|
package/src/runtime-tools.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineTool, type ToolContract } from "./module-contract.ts";
|
|
1
|
+
import { defineTool, type ToolContract, type ToolInput } from "./module-contract.ts";
|
|
2
2
|
import type { Json } from "./json.ts";
|
|
3
3
|
import type { ObjectReader, ToolSession } from "./objects.ts";
|
|
4
4
|
import type { CallResult, ToolCaller } from "./runtime-contracts.ts";
|
|
@@ -12,10 +12,12 @@ export interface TopLevelToolContext<D extends Json = Json> {
|
|
|
12
12
|
readonly callId: string;
|
|
13
13
|
readonly signal: AbortSignal;
|
|
14
14
|
readonly interactive: boolean;
|
|
15
|
+
/** Captured resource-type tool-call restriction, or null when calls are allowed; creation and discovery remain available. */
|
|
16
|
+
resourceToolRestriction(kind: string): string | null;
|
|
15
17
|
publish(data: D): void;
|
|
16
18
|
}
|
|
17
19
|
/** Top-level tools declare their definition and implementation together, independently of resource support relationships. */
|
|
18
|
-
export interface TopLevelTool<A extends
|
|
20
|
+
export interface TopLevelTool<A extends ToolInput = ToolInput, D extends Json = Json> extends ToolContract<A> {
|
|
19
21
|
/** Encodes D for progress/history and decodes it for views and model projection. */
|
|
20
22
|
readonly resultSchema: z.ZodType<D>;
|
|
21
23
|
readonly effect: "read" | "write";
|
|
@@ -24,7 +26,7 @@ export interface TopLevelTool<A extends Json = Json, D extends Json = Json> exte
|
|
|
24
26
|
execute(args: A, context: TopLevelToolContext<D>): Promise<CallResult<D>>;
|
|
25
27
|
toModel?(data: D): ToolModelOutput;
|
|
26
28
|
}
|
|
27
|
-
export function defineTopLevelTool<A extends
|
|
29
|
+
export function defineTopLevelTool<A extends ToolInput, D extends Json>(definition: TopLevelTool<A, D>): TopLevelTool {
|
|
28
30
|
if (!definition.resultSchema.description?.trim()) throw new Error(`Missing result schema description: ${definition.id}`);
|
|
29
31
|
const tool = defineTool(definition);
|
|
30
32
|
return { ...definition, ...tool,
|
package/src/runtime.ts
CHANGED
|
@@ -17,6 +17,7 @@ export type * from "./content-runtime.ts";
|
|
|
17
17
|
export type * from "./runtime-files.ts";
|
|
18
18
|
export type * from "./models.ts";
|
|
19
19
|
export type * from "./runtime-execution.ts";
|
|
20
|
+
export type * from "./runtime-deadlines.ts";
|
|
20
21
|
export { validationMessage, jsonArgumentHint } from "./tool-validation.ts";
|
|
21
22
|
|
|
22
23
|
/** Stable plugin API error: code supports plugin branching, and message is used for logs. */
|
package/src/tool-validation.ts
CHANGED
|
@@ -11,4 +11,4 @@ export function validationMessage(error: z.ZodError, field: string): string {
|
|
|
11
11
|
return format(error.issues);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export const jsonArgumentHint =
|
|
14
|
+
export const jsonArgumentHint = 'target and args are JSON objects or null matching their schemas. Example: target: {"path":"README.md"}, args: {}.';
|
package/src/workspace.ts
CHANGED
|
@@ -14,9 +14,9 @@ export interface SessionSummary { readonly id: string; readonly title: string; r
|
|
|
14
14
|
export interface ArchivedSessionSummary extends SessionSummary { readonly archivedAt: string }
|
|
15
15
|
/**
|
|
16
16
|
* Read-only session catalog shared within the same host runtime instance; each read returns current summaries.
|
|
17
|
-
* list contains only
|
|
17
|
+
* list contains only running sessions; sleeping lists saved sessions whose runtime objects are unloaded, and archived lists sessions in the recycle bin. Session IDs absent from all three have been deleted, allowing plugins to clean up their own per-session data.
|
|
18
18
|
*/
|
|
19
|
-
export interface SessionDirectory { list(): readonly SessionSummary[]; archived(): readonly ArchivedSessionSummary[] }
|
|
19
|
+
export interface SessionDirectory { list(): readonly SessionSummary[]; sleeping(): readonly SessionSummary[]; archived(): readonly ArchivedSessionSummary[] }
|
|
20
20
|
/** Source: null means the application itself; plugin-originated sources always include plugin identity, and resource sources always belong to that plugin. Shared by records, events, and others. */
|
|
21
21
|
export type Source = { readonly plugin: string; readonly resource: ResourceRef | null } | null;
|
|
22
22
|
export interface ResourceSnapshot<S extends Json = Json> {
|