@asterism-app/sdk 1.6.0 → 1.8.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/views-and-settings.md +6 -4
- package/examples/author.ts +1 -1
- package/package.json +1 -1
- package/src/contracts.ts +1 -1
- package/src/mcp.ts +4 -9
- package/src/messaging.ts +3 -0
- package/src/models.ts +0 -1
- package/src/provider-settings.ts +1 -1
- package/src/reference-urls.ts +45 -0
- package/src/renderer-island.ts +11 -11
- package/src/renderer-references.ts +22 -0
- package/src/renderer.ts +1 -0
- package/src/runtime.ts +1 -1
- package/src/resource-links.ts +0 -15
|
@@ -14,21 +14,23 @@ 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
|
-
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,
|
|
21
|
+
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
22
|
|
|
23
23
|
## Open resource locations
|
|
24
24
|
|
|
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
|
|
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. 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
26
|
|
|
27
27
|
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
28
|
|
|
29
29
|
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
30
|
|
|
31
|
-
|
|
31
|
+
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.
|
|
32
|
+
|
|
33
|
+
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
34
|
|
|
33
35
|
## Style plugin views
|
|
34
36
|
|
package/examples/author.ts
CHANGED
|
@@ -133,7 +133,7 @@ export async function modelWork(plugin: PluginContext, object: ObjectExecutor, s
|
|
|
133
133
|
const result = await plugin.execution.run({
|
|
134
134
|
access: object.ref, interactive: false, requestParentId: snapshot.position.nodeId, target: { provider: "configured-provider", model: "configured-model" },
|
|
135
135
|
system: { blocks: [{ id: research.name("instruction"), text: "Inspect linked materials and report findings." }] },
|
|
136
|
-
messages: projectOwnContext(snapshot, object.ref),
|
|
136
|
+
messages: projectOwnContext(snapshot, object.ref), signal,
|
|
137
137
|
observer: { event(event) {
|
|
138
138
|
if (event.type === "progress") return;
|
|
139
139
|
object.commit(writer => {
|
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/mcp.ts
CHANGED
|
@@ -5,11 +5,13 @@ import { jsonSchema } from "./json.ts";
|
|
|
5
5
|
|
|
6
6
|
export const SERVER_ID_PATTERN = /^[a-z0-9][a-z0-9_-]*$/u;
|
|
7
7
|
export const serverIdSchema = z.string().min(1).max(64).regex(SERVER_ID_PATTERN);
|
|
8
|
+
/** Environment variables (stdio) or request headers (http); values may be `!` credential commands. */
|
|
9
|
+
export const mcpVariablesSchema = z.record(z.string().min(1), z.string());
|
|
8
10
|
export const mcpServerSchema = z.strictObject({
|
|
9
11
|
id: serverIdSchema, name: z.string().trim().min(1), enabled: z.boolean(),
|
|
10
12
|
mode: z.enum(["eager", "lazy"]), idleSeconds: z.number().int().min(1).max(86_400),
|
|
11
13
|
transport: z.enum(["stdio", "http"]), command: z.string(), args: z.array(z.string()), cwd: z.string(),
|
|
12
|
-
url: z.string(), auth: z.enum(["none", "oauth"]),
|
|
14
|
+
url: z.string(), auth: z.enum(["none", "oauth"]), env: mcpVariablesSchema, headers: mcpVariablesSchema,
|
|
13
15
|
}).superRefine((value, ctx) => {
|
|
14
16
|
if (value.transport === "stdio" && !value.command.trim()) ctx.addIssue({ code: "custom", path: ["command"], message: "An executable is required." });
|
|
15
17
|
if (value.transport === "http") {
|
|
@@ -21,7 +23,6 @@ export type McpServerConfig = z.infer<typeof mcpServerSchema>;
|
|
|
21
23
|
export const mcpSettingsSchema = z.object({ servers: z.array(mcpServerSchema).refine(values =>
|
|
22
24
|
new Set(values.map(value => value.id)).size === values.length, "Server IDs are unique.") });
|
|
23
25
|
export const defaultMcpSettings = { servers: [] };
|
|
24
|
-
export const credentialsSchema = z.record(z.string(), z.string());
|
|
25
26
|
export const connectionPhases = ["disconnected", "connecting", "awaiting_auth", "authorizing", "connected", "error"] as const;
|
|
26
27
|
export type ConnectionPhase = typeof connectionPhases[number];
|
|
27
28
|
export const mcpServerStateSchema = z.object({
|
|
@@ -43,14 +44,8 @@ export interface McpCatalogServer { config: McpServerConfig; state: McpServerSta
|
|
|
43
44
|
|
|
44
45
|
export const McpChanged = defineEvent("core.mcp.changed", { schema: z.object({}), source: "host", semantics: { kind: "snapshot", key: [] } });
|
|
45
46
|
export const ReadMcp = defineCall("core.mcp.status", { scope: "plugin", input: z.object({}), output: z.array(mcpServerStateSchema) });
|
|
46
|
-
/** keep retains saved environment or headers; a new server with keep starts without any. */
|
|
47
|
-
export const mcpCredentialUpdateSchema = z.discriminatedUnion("action", [
|
|
48
|
-
z.strictObject({ action: z.literal("keep") }), z.strictObject({ action: z.literal("replace"), values: credentialsSchema }),
|
|
49
|
-
]);
|
|
50
|
-
export type McpCredentialUpdate = z.infer<typeof mcpCredentialUpdateSchema>;
|
|
51
47
|
export const SaveMcpServer = defineCall("core.mcp.save-server", { scope: "plugin",
|
|
52
|
-
input: z.object({ server: mcpServerSchema, create: z.boolean()
|
|
53
|
-
export const ReadMcpCredentials = defineCall("core.mcp.read-credentials", { scope: "plugin", input: z.object({ serverId: z.string() }), output: credentialsSchema });
|
|
48
|
+
input: z.object({ server: mcpServerSchema, create: z.boolean() }), output: z.null() });
|
|
54
49
|
export const mcpToolSummarySchema = z.object({ name: z.string(), title: z.string().optional(), description: z.string().optional() });
|
|
55
50
|
export type McpToolSummary = z.infer<typeof mcpToolSummarySchema>;
|
|
56
51
|
export const ReadMcpTools = defineCall("core.mcp.read-tools", { scope: "plugin", input: z.object({ serverId: z.string() }),
|
package/src/messaging.ts
CHANGED
|
@@ -41,9 +41,12 @@ export const messagingFilePartSchema = z.strictObject({
|
|
|
41
41
|
});
|
|
42
42
|
export const messagingTextPartSchema = z.strictObject({ kind: z.literal("text"), text: z.string() });
|
|
43
43
|
export const messagingPartSchema = z.discriminatedUnion("kind", [messagingTextPartSchema, messagingFilePartSchema]);
|
|
44
|
+
/** Content supplied with a reply, without asserting the original message's identity, author, or time. */
|
|
45
|
+
export const messageQuoteSchema = z.strictObject({ parts: z.array(messagingPartSchema) });
|
|
44
46
|
export const messageSchema = z.strictObject({
|
|
45
47
|
id, sender: messageSenderSchema, parts: z.array(messagingPartSchema),
|
|
46
48
|
sentAt: z.string(), replyTo: id.optional(), threadId: id.optional(), groupId: id.optional(),
|
|
49
|
+
quote: messageQuoteSchema.optional(),
|
|
47
50
|
});
|
|
48
51
|
export const messagingFileQuerySchema = conversationAddressSchema.extend({ messageId: id, fileId: id });
|
|
49
52
|
export const conversationQuerySchema = z.strictObject({ since: id.optional() });
|
package/src/models.ts
CHANGED
|
@@ -117,7 +117,6 @@ export interface ModelRunRequest extends ModelRequestIdentity {
|
|
|
117
117
|
system: SystemPrompt;
|
|
118
118
|
messages: ModelItem[];
|
|
119
119
|
tools?: ModelTools;
|
|
120
|
-
cache?: { expectHit: boolean };
|
|
121
120
|
/** Synchronously package domain data after final request preparation; delivered with the actual response's completion. */
|
|
122
121
|
completionExtensions?: (context: ModelRequestContext) => readonly Presentation[];
|
|
123
122
|
signal: AbortSignal;
|
package/src/provider-settings.ts
CHANGED
|
@@ -6,7 +6,7 @@ const base = { key: z.string().regex(/^[A-Za-z][A-Za-z0-9_]*$/u), label: uiTextS
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Provider settings use a closed set of kinds that the host renders, validates, and stores.
|
|
9
|
-
* Secret values are stored
|
|
9
|
+
* Secret values are stored with other settings and may be `!` credential commands; settings inputs mask them.
|
|
10
10
|
* Text values are saved trimmed; choices always resolve to a declared option.
|
|
11
11
|
*/
|
|
12
12
|
export const providerSettingSchema = z.discriminatedUnion("kind", [
|
|
@@ -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
|
+
}
|
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;
|
|
@@ -19,20 +19,20 @@ export interface RendererIslandSpec {
|
|
|
19
19
|
/** Close guard: returning false (or resolving to false) aborts closing; may asynchronously wait for user confirmation. */
|
|
20
20
|
export type RendererCloseGuard = () => boolean | Promise<boolean>;
|
|
21
21
|
export interface RendererIsland {
|
|
22
|
-
/**
|
|
23
|
-
|
|
24
|
-
/** Open
|
|
22
|
+
/** Whether an island with this plugin key is open in the screen. */
|
|
23
|
+
has(key: string): boolean;
|
|
24
|
+
/** 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
25
|
open(spec: RendererIslandSpec): Promise<boolean>;
|
|
26
|
-
/** Close this island and
|
|
26
|
+
/** 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
27
|
close(options?: { force?: boolean }): Promise<boolean>;
|
|
28
|
-
/** Close
|
|
29
|
-
|
|
28
|
+
/** Close the islands this island opened, transitively. */
|
|
29
|
+
closeOwned(options?: { force?: boolean }): Promise<boolean>;
|
|
30
30
|
/** Register a close guard for this island and return an unregister function. Normally used through useRendererCloseGuard. */
|
|
31
31
|
guard(guard: RendererCloseGuard): () => void;
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
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
|
|
34
|
+
* 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.
|
|
35
|
+
* 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
36
|
*/
|
|
37
37
|
export interface RendererIslandPanelProps {
|
|
38
38
|
title: string;
|
|
@@ -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
|
@@ -18,6 +18,7 @@ export * from "./renderer-records.ts";
|
|
|
18
18
|
export * from "./renderer-card.ts";
|
|
19
19
|
export * from "./renderer-island.ts";
|
|
20
20
|
export * from "./renderer-resource-open.ts";
|
|
21
|
+
export * from "./renderer-references.ts";
|
|
21
22
|
export * from "./renderer-view-state.ts";
|
|
22
23
|
import type { CardPanelDefinition, CardPanelView } from "./renderer-card.ts";
|
|
23
24
|
import type { RecordRenderer } from "./renderer-records.ts";
|
package/src/runtime.ts
CHANGED
|
@@ -36,7 +36,7 @@ export interface PluginConfig<T extends Json> {
|
|
|
36
36
|
update(next: (current: T) => T): void;
|
|
37
37
|
subscribe(listener: (value: T) => void): () => void;
|
|
38
38
|
}
|
|
39
|
-
/** Namespaced credentials
|
|
39
|
+
/** Namespaced credentials stored as given in the plugin's managed directory. */
|
|
40
40
|
export interface PluginSecrets {
|
|
41
41
|
get(key: string): Promise<string | null>;
|
|
42
42
|
set(key: string, value: string): Promise<void>;
|
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
|
-
}
|