@asterism-app/sdk 1.7.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 +61 -4
- package/package.json +1 -1
- package/src/contracts.ts +1 -1
- package/src/json.ts +2 -1
- package/src/module-contract.ts +12 -5
- package/src/reference-urls.ts +45 -0
- package/src/renderer-commands.ts +43 -0
- package/src/renderer-island.ts +26 -11
- package/src/renderer-references.ts +22 -0
- package/src/renderer.ts +6 -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
- package/src/resource-links.ts +0 -15
|
@@ -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
|
|
|
@@ -14,21 +14,25 @@ Use host presentation facilities for the surrounding card or operation. Keep dom
|
|
|
14
14
|
|
|
15
15
|
## Open expanded content
|
|
16
16
|
|
|
17
|
-
Resource card views can use the renderer island capability to open plugin content
|
|
17
|
+
Resource card views, settings pages, and islands can use the renderer island capability to open plugin content. Islands open at the right end of the screen and belong to the island that opened them; closing an island closes the islands it opened. Opening a key that is already open locates that island and keeps its content, so the key decides between one shared island and separate ones. `has(key)` reports whether a key is open, for example to mark the selected row. The host owns ordering, sizing, and the island menu.
|
|
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
|
-
|
|
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
|
+
|
|
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
|
|
24
26
|
|
|
25
|
-
A resource type can declare `open(location, context)` in its renderer resource description. The location is an opaque string interpreted by that resource. A file resource can open an editor or read-only viewer; a browser resource can navigate to a URL. The handler receives the resolved resource reference, typed calls, the opening element, and an island capability bound to the target plugin. It returns whether the open completed
|
|
27
|
+
A resource type can declare `open(location, context)` in its renderer resource description. The location is an opaque string interpreted by that resource. A file resource can open an editor or read-only viewer; a browser resource can navigate to a URL. The handler receives the resolved resource reference, typed calls, the opening element, and an island capability bound to the target plugin. It returns whether the open completed. The first island a handler opens for a navigation is restorable: the host saves the resource and location and calls the handler again to rebuild that island when the session reopens, so the handler should derive the island from the location alone.
|
|
26
28
|
|
|
27
29
|
Use `useRendererResourceNavigation().open(resource, location, { origin })` from a card, settings page, Home entry, or island. Supply the session ID and resource ID. The host resolves current resource presence and invokes its registered handler. It reports missing resources, unsupported opening, and handler failures. User and plugin navigation are independent of model-request authorization and directed resource links.
|
|
28
30
|
|
|
29
31
|
Resources own the meaning of their locations and their content surfaces. A filename remains a file location; opening it does not turn its contents into application navigation or grant embedded text another interaction contract. Directory files use editable text and image surfaces, while manual files use read-only text and image surfaces.
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
A reference URL is a string that names something to act on: `resource:<encoded resource ID>/<location>` addresses a resource location, and `skill:<encoded name>[/<package path>]` addresses a skill in the Agent skill catalog. Location segments are percent-encoded individually and keep `/` as a separator. `resourceUrl`, `skillUrl`, and their `parse*` counterparts build and read them; `referenceMarkdown(label, url)` writes the Markdown link form. A reference URL is only text: it can name a resource that is absent, removed, or not linked to anyone, and following it reports what it finds at that time. A displaying interface supplies the session identity when following a resource URL. The Agent Markdown interface recognizes both schemes.
|
|
34
|
+
|
|
35
|
+
Any view can start a reference drag. In `dragstart`, call `setReferenceDrag(event.dataTransfer, text)` with reference text, usually one or more `referenceMarkdown` links. The drag carries only the `application/vnd.asterism.reference` type, so surfaces that do not read references, including the canvas, ignore it. Targets check `hasReferenceDrag` during `dragover` and read the text with `readReferenceDrag` on `drop`. The Agent composer inserts dropped reference text at the drop point, where resource and skill links become chips.
|
|
32
36
|
|
|
33
37
|
## Style plugin views
|
|
34
38
|
|
|
@@ -50,6 +54,59 @@ Managed configuration suits schema-validated settings. Other plugin data can use
|
|
|
50
54
|
|
|
51
55
|
Closing a page releases its view subscriptions. It does not end every service the plugin uses.
|
|
52
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
|
+
|
|
53
110
|
## Start work from Home
|
|
54
111
|
|
|
55
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/contracts.ts
CHANGED
|
@@ -12,7 +12,7 @@ export * from "./calls.ts";
|
|
|
12
12
|
export * from "./channels.ts";
|
|
13
13
|
export * from "./tool-result.ts";
|
|
14
14
|
export * from "./workspace.ts";
|
|
15
|
-
export * from "./
|
|
15
|
+
export * from "./reference-urls.ts";
|
|
16
16
|
export type * from "./models.ts";
|
|
17
17
|
export { thinkingLevels } from "./models.ts";
|
|
18
18
|
export * from "./model-records.ts";
|
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,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reference URLs are plain strings that name something the model or the user can look up: `resource:` addresses a
|
|
3
|
+
* location inside a session resource, `skill:` addresses a skill package through the skill catalog. A reference may
|
|
4
|
+
* name something that does not exist; parsing checks only the format.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** `resource:<resourceId>/<location>`: the authority is the resource ID and the resource interprets the location. */
|
|
8
|
+
export interface ResourceUrl { readonly resourceId: string; readonly location: string }
|
|
9
|
+
/** `skill:<name>[/<path>]`: the skill name and an optional package-relative file; undefined means SKILL.md. */
|
|
10
|
+
export interface SkillUrl { readonly name: string; readonly path: string | undefined }
|
|
11
|
+
|
|
12
|
+
const encodePath = (path: string) => path.split("/").map(encodeURIComponent).join("/");
|
|
13
|
+
const decodePath = (path: string) => path.split("/").map(decodeURIComponent).join("/");
|
|
14
|
+
|
|
15
|
+
export function resourceUrl(resourceId: string, location: string): string {
|
|
16
|
+
return `resource:${encodeURIComponent(resourceId)}/${encodePath(location)}`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function parseResourceUrl(value: string): ResourceUrl | null {
|
|
20
|
+
const match = /^resource:([^/?#]+)\/(.*)$/u.exec(value);
|
|
21
|
+
if (!match) return null;
|
|
22
|
+
try {
|
|
23
|
+
const resourceId = decodeURIComponent(match[1]!);
|
|
24
|
+
return resourceId ? { resourceId, location: decodePath(match[2]!) } : null;
|
|
25
|
+
} catch { return null; }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function skillUrl(name: string, path?: string): string {
|
|
29
|
+
const encoded = encodeURIComponent(name);
|
|
30
|
+
return path ? `skill:${encoded}/${encodePath(path)}` : `skill:${encoded}`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function parseSkillUrl(value: string): SkillUrl | null {
|
|
34
|
+
const match = /^skill:([^/?#]+)(?:\/([^?#]+))?$/u.exec(value);
|
|
35
|
+
if (!match) return null;
|
|
36
|
+
try {
|
|
37
|
+
const name = decodeURIComponent(match[1]!);
|
|
38
|
+
return name ? { name, path: match[2] === undefined ? undefined : decodePath(match[2]) } : null;
|
|
39
|
+
} catch { return null; }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The text form of a reference: a Markdown link whose label is display text and whose destination is the URL. */
|
|
43
|
+
export function referenceMarkdown(label: string, url: string): string {
|
|
44
|
+
return `[${label}](${url})`;
|
|
45
|
+
}
|
|
@@ -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
|
@@ -2,11 +2,11 @@ import { createContext, createElement, useContext, useEffect, useRef, type Compo
|
|
|
2
2
|
import type { UiText } from "./i18n.ts";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Island: an independent surface
|
|
6
|
-
* The host
|
|
5
|
+
* Island: an independent window-like surface within the host screen. Islands open at the right end of the screen and belong to the island that opened them;
|
|
6
|
+
* closing an island also closes the islands it opened. The host manages order, width, position, motion, and focus; plugins provide identity, an accessible name, and content.
|
|
7
7
|
*/
|
|
8
8
|
export interface RendererIslandSpec {
|
|
9
|
-
/** Island identity unique within the plugin; the host isolates it by plugin identity. Opening
|
|
9
|
+
/** Island identity unique within the plugin; the host isolates it by plugin identity. Opening an identity that is already open locates that island and keeps its content. */
|
|
10
10
|
key: string;
|
|
11
11
|
/** The island's accessible name and overflow navigation hint. */
|
|
12
12
|
label: UiText;
|
|
@@ -16,23 +16,27 @@ 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 {
|
|
22
|
-
/**
|
|
23
|
-
|
|
24
|
-
/** Open
|
|
24
|
+
/** Whether an island with this plugin key is open in the screen. */
|
|
25
|
+
has(key: string): boolean;
|
|
26
|
+
/** Open an island owned by this one at the right end of the screen, or locate the open island with the same key. Resolves to whether it is shown. */
|
|
25
27
|
open(spec: RendererIslandSpec): Promise<boolean>;
|
|
26
|
-
/** Close this island and
|
|
28
|
+
/** Close this island and the islands it opened; has no effect on host-managed islands such as the one containing a plugin settings page. force skips guards. */
|
|
27
29
|
close(options?: { force?: boolean }): Promise<boolean>;
|
|
28
|
-
/** Close
|
|
29
|
-
|
|
30
|
+
/** Close the islands this island opened, transitively. */
|
|
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
|
-
* Panel island frame: the title bar stays fixed and the content scrolls independently; the primary action and close control sit on the right of the title bar.
|
|
35
|
-
* When dirty is true, the host asks for confirmation to discard changes before closing this island, including through
|
|
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.
|
|
39
|
+
* When dirty is true, the host asks for confirmation to discard changes before closing this island, including closure through the island that opened it.
|
|
36
40
|
*/
|
|
37
41
|
export interface RendererIslandPanelProps {
|
|
38
42
|
title: string;
|
|
@@ -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);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drag transfer of references. The payload is reference text: Markdown links whose destinations are reference URLs,
|
|
3
|
+
* such as `[guide.md](resource:Dir-A/docs/guide.md)`. Any plugin view can be a source and any input can be a target;
|
|
4
|
+
* the transfer carries only text, so targets that do not read this type ignore the drag.
|
|
5
|
+
*/
|
|
6
|
+
export const referenceDragType = "application/vnd.asterism.reference";
|
|
7
|
+
|
|
8
|
+
/** Start a reference drag from a `dragstart` event. */
|
|
9
|
+
export function setReferenceDrag(transfer: DataTransfer, text: string): void {
|
|
10
|
+
transfer.setData(referenceDragType, text);
|
|
11
|
+
transfer.effectAllowed = "copy";
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Whether a drag carries references; readable during `dragover`, when payload contents are not yet exposed. */
|
|
15
|
+
export function hasReferenceDrag(transfer: DataTransfer): boolean {
|
|
16
|
+
return transfer.types.includes(referenceDragType);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Reference text of a `drop` event; null when the drag carries no references. */
|
|
20
|
+
export function readReferenceDrag(transfer: DataTransfer): string | null {
|
|
21
|
+
return hasReferenceDrag(transfer) ? transfer.getData(referenceDragType) : null;
|
|
22
|
+
}
|
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,11 +13,13 @@ 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";
|
|
19
20
|
export * from "./renderer-island.ts";
|
|
20
21
|
export * from "./renderer-resource-open.ts";
|
|
22
|
+
export * from "./renderer-references.ts";
|
|
21
23
|
export * from "./renderer-view-state.ts";
|
|
22
24
|
import type { CardPanelDefinition, CardPanelView } from "./renderer-card.ts";
|
|
23
25
|
import type { RecordRenderer } from "./renderer-records.ts";
|
|
@@ -26,6 +28,7 @@ import type { RendererContentInput, RendererInputOptions } from "./renderer-cont
|
|
|
26
28
|
import type { ContentReader } from "./content-runtime.ts";
|
|
27
29
|
export type { ContentReader } from "./content-runtime.ts";
|
|
28
30
|
import type { CreationEntry } from "./renderer-creation.ts";
|
|
31
|
+
import type { RendererCommandGroup } from "./renderer-commands.ts";
|
|
29
32
|
import type { ToolRenderer } from "./renderer-tools.ts";
|
|
30
33
|
import type { EventSubscriber } from "./events.ts";
|
|
31
34
|
import type { PluginCalls } from "./calls.ts";
|
|
@@ -145,6 +148,8 @@ export interface PluginSessionEntry {
|
|
|
145
148
|
export interface RendererPlugin {
|
|
146
149
|
modules?: readonly RendererModule[];
|
|
147
150
|
settings?: readonly PluginSettingsPage[];
|
|
151
|
+
/** Application palette groups, attributed to this plugin independently of resource views. */
|
|
152
|
+
commands?: readonly RendererCommandGroup[];
|
|
148
153
|
sessionEntries?: readonly PluginSessionEntry[];
|
|
149
154
|
prepare?(context: RendererPrepareContext): Promise<void>;
|
|
150
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> {
|
package/src/resource-links.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/** A resource link addresses an instance in the displaying session and carries an opaque location. */
|
|
2
|
-
export interface ResourceLink { readonly resourceId: string; readonly location: string }
|
|
3
|
-
|
|
4
|
-
export function resourceLink(resourceId: string, location: string): string {
|
|
5
|
-
return `resource:${encodeURIComponent(resourceId)}?location=${encodeURIComponent(location)}`;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function parseResourceLink(value: string): ResourceLink | null {
|
|
9
|
-
const match = /^resource:([^/?#]+)\?location=([^&#]*)$/u.exec(value);
|
|
10
|
-
if (!match) return null;
|
|
11
|
-
try {
|
|
12
|
-
const resourceId = decodeURIComponent(match[1]!);
|
|
13
|
-
return resourceId ? { resourceId, location: decodeURIComponent(match[2]!) } : null;
|
|
14
|
-
} catch { return null; }
|
|
15
|
-
}
|