@asterism-app/sdk 2.4.0 → 2.5.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/README.md +2 -0
- package/docs/visual-language.md +12 -10
- package/examples/counter/package.json +1 -1
- package/examples/tool-renderer.ts +8 -4
- package/package.json +1 -1
- package/src/reference-urls.ts +13 -5
- package/src/renderer-island.ts +9 -2
- package/src/renderer-resource-open.ts +6 -2
- package/src/renderer-ui.ts +61 -0
- package/src/tool-validation.ts +1 -1
package/README.md
CHANGED
|
@@ -3,3 +3,5 @@
|
|
|
3
3
|
The SDK is the public hosting boundary between Asterism and plugins. Plugins own the meaning of their resources and workflows. Agent conversation and other paradigm-specific work belong to the plugin that implements them.
|
|
4
4
|
|
|
5
5
|
Start with [Design and deliver a plugin](docs/getting-started.md) for design choices and validation. Resolve interfaces from the public source and types for the target release, not from the manual. The Manual includes the counter example as a source prototype to inspect, not as an API reference.
|
|
6
|
+
|
|
7
|
+
For renderer plugins, [Fit plugin views into the workbench](docs/visual-language.md) distinguishes workbench integration from the choice of shared, third-party, or custom controls.
|
package/docs/visual-language.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# Fit plugin views into the workbench
|
|
2
2
|
|
|
3
|
-
A plugin's views appear beside the host's own and other plugins' views.
|
|
3
|
+
A plugin's views appear beside the host's own and other plugins' views. The SDK provides Asterism-specific ways to register tool and card views, open islands, and use workbench navigation. Within those views, you choose the controls.
|
|
4
|
+
|
|
5
|
+
Choose controls that meet your view's requirements. You can use a third-party library, write your own controls, or use the SDK's shared controls. When an SDK control fits and you want the same appearance and interaction as the workbench, it saves you that work. If it doesn't fit, use another control without cutting features to match the SDK. You can mix these choices in the same view.
|
|
4
6
|
|
|
5
7
|
## Start from the host's containers
|
|
6
8
|
|
|
@@ -23,7 +25,7 @@ A plugin that needs a group uses the shell tone rather than adding a border; the
|
|
|
23
25
|
|
|
24
26
|
Users learn that a line in Asterism tells them something: where focus is, what is selected, where a drop will land, or the state of a piece of work. A moving dashed outline means content is still forming, a still dashed outline means it ended incomplete, and a red line means the request that produced it failed. Hairlines between rows are the one structural line.
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
Tool views receive their state outline from the host's process block. When showing status within your own content, pair color with an icon or label rather than relying on color alone.
|
|
27
29
|
|
|
28
30
|
## Let motion explain a change
|
|
29
31
|
|
|
@@ -33,25 +35,25 @@ Plugin views should use the same motion cues and timing. Shared controls already
|
|
|
33
35
|
|
|
34
36
|
## Choose controls by the kind of choice
|
|
35
37
|
|
|
36
|
-
|
|
38
|
+
Use the same interaction for the same kind of choice, whichever library supplies the controls:
|
|
37
39
|
|
|
38
40
|
- A single choice among a few short options is a segmented toggle group.
|
|
39
41
|
- An immediate on/off setting is a switch; a choice inside a form or a multi-selection is a checkbox; an explained single choice is a radio group.
|
|
40
|
-
- A choice among many options, or one that needs search, uses
|
|
41
|
-
- Icon-only actions
|
|
42
|
+
- A choice among many options, or one that needs search, uses a searchable picker in a popover.
|
|
43
|
+
- Icon-only actions have an accessible label and a tooltip.
|
|
42
44
|
- A short name or explanation on hover is a tooltip; a preview read while hovering is a hover card; content the user opens on purpose, scrolls, or acts on is a popover behind a button.
|
|
43
45
|
- Button variants carry roles: one default button for the primary action in a region, outline for supporting actions, ghost for compact and row actions, destructive for irreversible confirmation.
|
|
44
46
|
|
|
45
|
-
Tooltips share the popover tone
|
|
47
|
+
Tooltips share the popover tone. Keep their delay, placement, and width consistent. If a tooltip explains why an action is unavailable, make the explanation reachable even when the control is disabled.
|
|
46
48
|
|
|
47
|
-
|
|
49
|
+
## Use shared readers when they fit
|
|
48
50
|
|
|
49
|
-
|
|
51
|
+
The host supplies optional presentation controls through the SDK renderer. Tool titles can use `ToolHeader` with a subject, summary, and metadata. `ToolResourceSubject` puts the resource recorded with the call in the subject slot, and `HeaderExcerpt` shortens long inputs without truncating the operation name. `ToolScrollArea` provides a default height for settled results; `StreamingScrollArea` follows growing content. A view can use its own layout when those defaults do not fit.
|
|
50
52
|
|
|
51
|
-
|
|
53
|
+
`Diff` renders a unified diff of one file. Set wrapping or word-level change highlighting as needed, and turn line numbers off when hunk positions are not real file positions. The view owns its toolbar, preferences, and scroll layout. A plugin can also use its own diff viewer or other controls without changing how it connects to islands, cards, or tool views.
|
|
52
54
|
|
|
53
55
|
## Keep custom styling local
|
|
54
56
|
|
|
55
|
-
|
|
57
|
+
For third-party or custom controls, use the workbench's semantic color tokens and type roles when you want the view to follow the user's theme in both color schemes. CSS Modules keep plugin styles local, while global styles share the document cascade with the host and every other plugin. Avoid global selectors that would restyle shared controls or another plugin's views.
|
|
56
58
|
|
|
57
59
|
Check a view in light and dark modes, at each density, and with reduced motion before release. A typecheck cannot tell whether a view belongs in the workbench; looking at it beside the host's own views can.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { createElement } from "react";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { defineData, type Json } from "@asterism-app/sdk/contracts";
|
|
5
|
-
import { HeaderExcerpt, StreamingScrollArea, toolRenderer, type ToolRenderProps } from "@asterism-app/sdk/renderer";
|
|
5
|
+
import { HeaderExcerpt, StreamingScrollArea, ToolHeader, ToolResourceSubject, toolRenderer, type ToolRenderProps } from "@asterism-app/sdk/renderer";
|
|
6
6
|
|
|
7
7
|
const Result = defineData("example.writer/write", z.object({ written: z.number() }));
|
|
8
8
|
const targetSchema = z.object({ path: z.string() });
|
|
@@ -38,10 +38,14 @@ export const writerView = toolRenderer({ ...Result, targetSchema, tool: { argsSc
|
|
|
38
38
|
const Report = defineData("example.writer/report", z.object({ text: z.string() }));
|
|
39
39
|
const reportArgs = z.object({ question: z.string() });
|
|
40
40
|
type ReportProps = ToolRenderProps<z.infer<typeof Report.schema>, Json, z.infer<typeof reportArgs>>;
|
|
41
|
-
function ReportHeader({ args }: ReportProps) {
|
|
41
|
+
function ReportHeader({ args, invocation }: ReportProps) {
|
|
42
42
|
const question = args !== null && typeof args === "object" && !Array.isArray(args) && typeof args.question === "string" ? args.question : "";
|
|
43
|
-
// The excerpt belongs in
|
|
44
|
-
return createElement(
|
|
43
|
+
// The excerpt belongs in the shrinkable summary slot, not in a tooltip containing the complete question.
|
|
44
|
+
return createElement(ToolHeader, {
|
|
45
|
+
label: "Report",
|
|
46
|
+
subject: invocation.resource && createElement(ToolResourceSubject, { resource: invocation.resource }),
|
|
47
|
+
summary: createElement(HeaderExcerpt, { text: question }),
|
|
48
|
+
});
|
|
45
49
|
}
|
|
46
50
|
function ReportBody(props: ReportProps) {
|
|
47
51
|
if (props.phase === "input") return null;
|
package/package.json
CHANGED
package/src/reference-urls.ts
CHANGED
|
@@ -7,17 +7,18 @@ import { parseModelExpression, type ModelExpression } from "./model-selection.ts
|
|
|
7
7
|
* name something that does not exist; parsing checks only the format.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
/** `resource:<resourceId>/<location
|
|
11
|
-
export interface ResourceUrl { readonly resourceId: string; readonly location: string }
|
|
10
|
+
/** `resource:<resourceId>/<location>[#<fragment>]`: the resource interprets the location and optional navigation fragment. */
|
|
11
|
+
export interface ResourceUrl { readonly resourceId: string; readonly location: string; readonly fragment?: string }
|
|
12
12
|
/** `skill:<name>[/<path>]`: the skill name and an optional package-relative file; undefined means SKILL.md. */
|
|
13
13
|
export interface SkillUrl { readonly name: string; readonly path: string | undefined }
|
|
14
14
|
|
|
15
15
|
const encodePath = (path: string) => path.split("/").map(encodeURIComponent).join("/");
|
|
16
16
|
const decodePath = (path: string) => path.split("/").map(decodeURIComponent).join("/");
|
|
17
17
|
|
|
18
|
-
export function resourceUrl(resourceId: string, location: string): string {
|
|
18
|
+
export function resourceUrl(resourceId: string, location: string, fragment?: string): string {
|
|
19
|
+
const suffix = fragment === undefined ? "" : `#${encodeURIComponent(fragment)}`;
|
|
19
20
|
// Parentheses are URI-safe but delimit the Markdown destination used by references.
|
|
20
|
-
return `resource:${encodeURIComponent(resourceId)}/${encodePath(location)}`.replaceAll("(", "%28").replaceAll(")", "%29");
|
|
21
|
+
return `resource:${encodeURIComponent(resourceId)}/${encodePath(location)}${suffix}`.replaceAll("(", "%28").replaceAll(")", "%29");
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
export function parseResourceUrl(value: string): ResourceUrl | null {
|
|
@@ -25,7 +26,14 @@ export function parseResourceUrl(value: string): ResourceUrl | null {
|
|
|
25
26
|
if (!match) return null;
|
|
26
27
|
try {
|
|
27
28
|
const resourceId = decodeURIComponent(match[1]!);
|
|
28
|
-
|
|
29
|
+
if (!resourceId) return null;
|
|
30
|
+
const address = match[2]!;
|
|
31
|
+
const hash = address.indexOf("#");
|
|
32
|
+
if (hash < 0) return { resourceId, location: decodePath(address) };
|
|
33
|
+
const location = decodePath(address.slice(0, hash));
|
|
34
|
+
// A malformed navigation hint does not invalidate the resource location.
|
|
35
|
+
try { return { resourceId, location, fragment: decodeURIComponent(address.slice(hash + 1)) }; }
|
|
36
|
+
catch { return { resourceId, location }; }
|
|
29
37
|
} catch { return null; }
|
|
30
38
|
}
|
|
31
39
|
|
package/src/renderer-island.ts
CHANGED
|
@@ -14,7 +14,14 @@ export interface RendererIslandSpec {
|
|
|
14
14
|
origin?: HTMLElement | null;
|
|
15
15
|
/** Content surfaces grow wider than the default form panel. */
|
|
16
16
|
size?: "panel" | "content";
|
|
17
|
-
|
|
17
|
+
/** Receives the latest navigation for this live instance, including when its key is reused. Consume it once per request object. */
|
|
18
|
+
render: (navigation?: RendererIslandNavigation) => ReactNode;
|
|
19
|
+
}
|
|
20
|
+
/** An in-memory navigation request. Only the owning plugin interprets its target. */
|
|
21
|
+
export interface RendererIslandNavigation { readonly target: unknown }
|
|
22
|
+
export interface RendererIslandOpenOptions {
|
|
23
|
+
/** When supplied, send a fresh request to the shown island without replacing its content. */
|
|
24
|
+
readonly navigation?: unknown;
|
|
18
25
|
}
|
|
19
26
|
/** Explicit cancellation action of an island; cancellation may close it through the usual close guards. */
|
|
20
27
|
export type RendererIslandCancel = () => void | Promise<void>;
|
|
@@ -28,7 +35,7 @@ export interface RendererIsland {
|
|
|
28
35
|
*/
|
|
29
36
|
bindKey(key: string): boolean;
|
|
30
37
|
/** 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. */
|
|
31
|
-
open(spec: RendererIslandSpec): Promise<boolean>;
|
|
38
|
+
open(spec: RendererIslandSpec, options?: RendererIslandOpenOptions): Promise<boolean>;
|
|
32
39
|
/** 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. */
|
|
33
40
|
close(options?: { force?: boolean }): Promise<boolean>;
|
|
34
41
|
/** Close the islands this island opened, transitively. */
|
|
@@ -5,7 +5,11 @@ import type { ResourceRef } from "./workspace.ts";
|
|
|
5
5
|
import type { RendererCalls } from "./renderer-calls.ts";
|
|
6
6
|
import type { RendererIsland } from "./renderer-island.ts";
|
|
7
7
|
|
|
8
|
-
export interface RendererResourceOpenOptions {
|
|
8
|
+
export interface RendererResourceOpenOptions {
|
|
9
|
+
readonly origin?: HTMLElement | null;
|
|
10
|
+
/** A decoded URL fragment for in-app navigation, separate from the resource location. */
|
|
11
|
+
readonly fragment?: string;
|
|
12
|
+
}
|
|
9
13
|
|
|
10
14
|
/** The resource interprets location and chooses its operation or view. Islands belong to the target plugin. */
|
|
11
15
|
export interface RendererResourceOpenContext extends RendererResourceOpenOptions {
|
|
@@ -38,7 +42,7 @@ export interface RendererResourceNavigation {
|
|
|
38
42
|
/** Read the resource's current identity and title at call time; null when the session or resource is absent. Other failures reject. */
|
|
39
43
|
resolve(resource: Pick<ResourceRef, "sessionId" | "id">): Promise<RendererResourceIdentity | null>;
|
|
40
44
|
/** Resolve current presence and available location actions. The host supplies "open" when an in-app opener exists; resource actions retain their declared IDs. Lookup failures reject; action execution reports failures through the host. */
|
|
41
|
-
actions(resource: Pick<ResourceRef, "sessionId" | "id">, location: string): Promise<readonly RendererResourceLocationAction[]>;
|
|
45
|
+
actions(resource: Pick<ResourceRef, "sessionId" | "id">, location: string, options?: Pick<RendererResourceOpenOptions, "fragment">): Promise<readonly RendererResourceLocationAction[]>;
|
|
42
46
|
/** Resolve current presence without model-request authorization. Failures are shown by the host; a cancelled open returns false. */
|
|
43
47
|
open(resource: Pick<ResourceRef, "sessionId" | "id">, location: string, options?: RendererResourceOpenOptions): Promise<boolean>;
|
|
44
48
|
}
|
package/src/renderer-ui.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createContext, createElement, useContext, type ComponentType, type ReactNode } from "react";
|
|
2
|
+
import type { ToolInvocationInfo } from "./tool-result.ts";
|
|
2
3
|
|
|
3
4
|
export interface HeaderExcerptProps {
|
|
4
5
|
/** Full value. Only a bounded, single-line prefix is rendered; keep the full value in the body. */
|
|
@@ -17,9 +18,49 @@ export interface StreamingScrollAreaProps {
|
|
|
17
18
|
initialScrollPosition?: "start" | "end";
|
|
18
19
|
}
|
|
19
20
|
|
|
21
|
+
/** One-line tool title: the operation name, then an optional subject badge, a summary that yields space first, and trailing metadata. */
|
|
22
|
+
export interface ToolHeaderProps {
|
|
23
|
+
/** Localized operation name. */
|
|
24
|
+
label: string;
|
|
25
|
+
/** The operation's focus, such as a `ToolResourceSubject`; omit it when there is none. */
|
|
26
|
+
subject?: ReactNode;
|
|
27
|
+
/** Muted details such as a path or query; ellipsized as the width shrinks. */
|
|
28
|
+
summary?: ReactNode;
|
|
29
|
+
/** Short trailing facts such as counts; stays visible. */
|
|
30
|
+
meta?: ReactNode;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface ToolResourceSubjectProps {
|
|
34
|
+
/** The resource recorded with the call, from `invocation.resource`. */
|
|
35
|
+
resource: NonNullable<ToolInvocationInfo["resource"]>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface ToolScrollAreaProps {
|
|
39
|
+
children: ReactNode;
|
|
40
|
+
/** Localized accessible name for the scrolling region. */
|
|
41
|
+
label: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface DiffProps {
|
|
45
|
+
/** Unified diff text of one file, with `---`/`+++` headers and `@@` hunks. */
|
|
46
|
+
diff: string;
|
|
47
|
+
/** Wrap long lines instead of scrolling horizontally. Defaults to true. */
|
|
48
|
+
wrap?: boolean;
|
|
49
|
+
/** Emphasize changed words within changed lines, in addition to marking the lines themselves. Defaults to "none". */
|
|
50
|
+
highlightChanges?: "none" | "word";
|
|
51
|
+
/** Infer syntax highlighting from the filename, or render hunk contents as plain text. Defaults to "auto". */
|
|
52
|
+
syntax?: "auto" | "plain";
|
|
53
|
+
/** Show old and new line numbers; defaults to true. Turn them off when the hunk positions are not real file positions. */
|
|
54
|
+
lineNumbers?: boolean;
|
|
55
|
+
}
|
|
56
|
+
|
|
20
57
|
interface RendererUi {
|
|
21
58
|
HeaderExcerpt: ComponentType<HeaderExcerptProps>;
|
|
22
59
|
StreamingScrollArea: ComponentType<StreamingScrollAreaProps>;
|
|
60
|
+
ToolHeader: ComponentType<ToolHeaderProps>;
|
|
61
|
+
ToolResourceSubject: ComponentType<ToolResourceSubjectProps>;
|
|
62
|
+
ToolScrollArea: ComponentType<ToolScrollAreaProps>;
|
|
63
|
+
Diff: ComponentType<DiffProps>;
|
|
23
64
|
}
|
|
24
65
|
|
|
25
66
|
const Ui = createContext<RendererUi | null>(null);
|
|
@@ -40,3 +81,23 @@ export function HeaderExcerpt(props: HeaderExcerptProps) {
|
|
|
40
81
|
export function StreamingScrollArea(props: StreamingScrollAreaProps) {
|
|
41
82
|
return createElement(useRendererUi().StreamingScrollArea, props);
|
|
42
83
|
}
|
|
84
|
+
|
|
85
|
+
/** The shared tool title layout. Use `HeaderExcerpt` in the summary for unbounded inputs. */
|
|
86
|
+
export function ToolHeader(props: ToolHeaderProps) {
|
|
87
|
+
return createElement(useRendererUi().ToolHeader, props);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The recorded name and kind icon of the resource a call operated on, for a tool header's subject slot. */
|
|
91
|
+
export function ToolResourceSubject(props: ToolResourceSubjectProps) {
|
|
92
|
+
return createElement(useRendererUi().ToolResourceSubject, props);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** The default bounded reading region for settled tool content. Use your own layout when it doesn't fit the view. */
|
|
96
|
+
export function ToolScrollArea(props: ToolScrollAreaProps) {
|
|
97
|
+
return createElement(useRendererUi().ToolScrollArea, props);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Optional single-file diff viewer. The caller owns its controls and layout. Patches without renderable hunks display as diff text. */
|
|
101
|
+
export function Diff(props: DiffProps) {
|
|
102
|
+
return createElement(useRendererUi().Diff, props);
|
|
103
|
+
}
|
package/src/tool-validation.ts
CHANGED
|
@@ -43,4 +43,4 @@ export function resourceValidationMessage(error: z.ZodError, field: "args" | "ta
|
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
export const jsonArgumentHint = 'target and args are JSON objects or null matching their schemas.
|
|
46
|
+
export const jsonArgumentHint = 'target and args are JSON objects or null matching their schemas.';
|