@asterism-app/sdk 1.4.1 → 1.6.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/data-and-lifecycle.md +2 -0
- package/docs/messaging.md +3 -1
- package/docs/resources-and-tools.md +6 -2
- package/docs/views-and-settings.md +10 -0
- package/package.json +1 -1
- package/src/contracts.ts +1 -0
- package/src/events.ts +7 -0
- package/src/json.ts +15 -1
- package/src/messaging.ts +10 -5
- package/src/model-provider.ts +6 -3
- package/src/models.ts +2 -2
- package/src/module-contract.ts +1 -0
- package/src/provider-settings.ts +1 -1
- package/src/renderer-resource-open.ts +30 -0
- package/src/renderer-services.ts +4 -2
- package/src/renderer-tools.ts +8 -3
- package/src/renderer.ts +5 -1
- package/src/resource-links.ts +15 -0
- package/src/runtime-contracts.ts +1 -0
- package/src/runtime-tools.ts +1 -0
|
@@ -48,6 +48,8 @@ An object writer can complete that object's pending records. A session writer ca
|
|
|
48
48
|
|
|
49
49
|
Transient events announce change. A consumer needing current state establishes its subscription and reads the current value; later notifications prompt another read.
|
|
50
50
|
|
|
51
|
+
The host publishes `SystemResumed` when the operating system resumes from sleep. Subscribe through `plugin.ipc.events` with the plugin lifetime signal when maintaining absolute deadlines or other state affected by elapsed sleep time. Re-evaluate against the current wall clock when handling the event. It is a transient occurrence and is not replayed after application startup.
|
|
52
|
+
|
|
51
53
|
Typed calls describe request and response values with ordinary Zod schemas. The caller supplies the input schema's input; the implementation receives its parsed output, including defaults. The implementation returns JSON accepted by the output schema, and the caller receives that schema's parsed output. These types are inferred from the shared declaration, so a conversion such as string to number does not require separate type annotations.
|
|
52
54
|
|
|
53
55
|
## Read typed history
|
package/docs/messaging.md
CHANGED
|
@@ -4,10 +4,12 @@ Messaging connects plugins to external conversation services through configured
|
|
|
4
4
|
|
|
5
5
|
Settings use the shared provider setting kinds: text, choice, and secret. Secret values are supplied to the backend factory and remain absent from configuration snapshots. Required values are always present in the resolved settings, choices hold a declared option, and unset optional values are absent. A provider type may have several independently configured connections. The plugin owns any platform-specific state or persistent data used by those connections; declare `forget` to release a removed connection's data, which the host calls after that connection's receiver has ended.
|
|
6
6
|
|
|
7
|
-
An instance supplies its external identity, an ongoing receive operation, conversation listing, message reading, and sending. Receive accepts a cancellation signal and connection-state callbacks, and publishes typed conversation-discovered and
|
|
7
|
+
An instance supplies its external identity, an ongoing receive operation, conversation listing, message reading, and sending. Receive accepts a cancellation signal and connection-state callbacks, and publishes typed conversation-discovered and messages-received events. A messages-received event contains an ordered, nonempty batch from one conversation; a single message uses a one-element batch. Call `ready` once the platform has accepted the receiver; the connection then reports connected and its retry backoff resets. A transport that restores its own protocol session calls `reconnecting(error)` during the interruption and `ready()` after recovery, preserving its active receiver. Queries and sends have their own signals. A send carries ordered text and file-reference parts plus an optional reply target. Platforms with a caption field combine the text and deliver the files in order. Resolve each reference with `plugin.files` before contacting the platform, so an unreadable source fails as invalid input without sending anything.
|
|
8
8
|
|
|
9
9
|
Received messages also have ordered text and file parts. File parts identify a platform attachment and describe its MIME type, filename, and known size. An instance's optional `openFile` operation streams the bytes selected by conversation, message, and file IDs. Verify that the selected file belongs to that address, refresh temporary platform URLs as needed, and preserve cancellation and download errors. Resource consumers create FileRefs with their own source identity; provider messages do not depend on a particular card or session.
|
|
10
10
|
|
|
11
|
+
Keep each platform message's own identity and body. Messages sent together may share a `groupId`; providers can deliver them in one batch while keeping reads, replies, and attachments addressable by their individual message IDs. A read selects either recent messages and cursor continuation or a `messageIds` array. ID queries return found messages in requested order, once per resolved message, and identify unavailable requested IDs in `missingIds`, without returning a cursor. Both query forms respect the conversation and optional topic.
|
|
12
|
+
|
|
11
13
|
The host retries failed creation and receive calls. Throw `MessagingError` with `request_failed` for transient conditions such as network failures, rate limits, and server errors, and set `retryAfterMs` when the platform reports a delay. Errors other than `MessagingError` are also treated as transient. Use `unavailable` for conditions that retrying cannot fix, such as rejected credentials or a conflicting receiver; the connection then stays failed until the user changes its configuration or reconnects. Reject unsupported operations explicitly with `unsupported`.
|
|
12
14
|
|
|
13
15
|
Use opaque strings for platform conversation, topic, and message identities. Give every sender a role relative to the connection: `self` for the connection's own identity, `participant` for another party, and `system` for content the platform produced rather than a party authored. Cursors are opaque, reusable query positions scoped by the provider. A query may compare changes with an earlier cursor, but it must not advance a shared read position. Cursor rejection should explain that the supplied position cannot be used.
|
|
@@ -24,9 +24,9 @@ Use a session snapshot to query the resources directly linked to a receiver. Res
|
|
|
24
24
|
|
|
25
25
|
Use a resource tool when an operation targets a linked object. A shared tool can have implementations for different resource types, each with an appropriate internal target and result.
|
|
26
26
|
|
|
27
|
-
Choose a tool name for the operation's meaning. Reuse an existing tool declaration when its semantics and operation arguments fit another resource; supply that resource's target and result schemas in its implementation. A distinct operation contract needs a distinct name. Domain qualifiers can clarify scope, such as `terminal_input` for terminal interaction, and remain useful when multiple resource types support that operation. Choose qualifiers according to the operation's meaning, independently of whether its declaration is public or where its code lives.
|
|
27
|
+
Choose a tool name for the operation's meaning. Reuse an existing tool declaration when its semantics and operation arguments fit another resource; supply that resource's target and result schemas in its implementation. The result schema decodes and encodes that implementation's output. A distinct operation contract needs a distinct name. Domain qualifiers can clarify scope, such as `terminal_input` for terminal interaction, and remain useful when multiple resource types support that operation. Choose qualifiers according to the operation's meaning, independently of whether its declaration is public or where its code lives.
|
|
28
28
|
|
|
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
|
|
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
31
|
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
32
|
|
|
@@ -34,10 +34,14 @@ Both resource tools and top-level tools receive `caller`, containing the access
|
|
|
34
34
|
|
|
35
35
|
Describe the operation's purpose and observable behavior. Parameters should explain business meaning that names and types alone do not express. Results should distinguish known success, failure, cancellation, partial output, and uncertain effects.
|
|
36
36
|
|
|
37
|
+
Declare `execution: "sequential"` when an operation must preserve submission order relative to other sequential operations in the request. Parallel operations can overlap either category. This execution policy is independent of the operation's read/write effect. Direct model calls and resource script calls share validation, scheduling, and completion, so tools require no separate script implementation.
|
|
38
|
+
|
|
37
39
|
A tool contribution can capture resource-specific configuration and access at the start of each model request. Return a bound contribution using the same implementation contract; the host uses it for that request's tool batch. This is useful for a resource whose selected network or reachable objects can change while a model is responding. Capture addressing and authorization facts, while reading ordinary mutable content when the operation runs.
|
|
38
40
|
|
|
39
41
|
Declare `requiresInteraction: true` when a tool cannot complete without user interaction. The host excludes it from noninteractive requests and rejects unsupported calls before entering the implementation. Tools supporting both modes can inspect `interactive` in their execution context. A renderer that only displays progress or results does not make a tool interactive.
|
|
40
42
|
|
|
43
|
+
Resource inspection includes the interaction requirement. Resource scripts are noninteractive surfaces, including within an interactive model request; interaction-required operations use direct model calls. Their other execution and authorization contracts remain shared.
|
|
44
|
+
|
|
41
45
|
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.
|
|
42
46
|
|
|
43
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: inspection retains resource state and tool schemas with a notice naming a denied role, and calls on restricted types are rejected before the implementation runs. Listing and linked context remain available. Individual resource tools need no role-policy checks.
|
|
@@ -20,6 +20,16 @@ Supply a plugin-local identity, accessible label, opening element, and content r
|
|
|
20
20
|
|
|
21
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, replacement, 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
|
+
## Open resource locations
|
|
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; declining an island close guard returns false.
|
|
26
|
+
|
|
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
|
+
|
|
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
|
+
|
|
31
|
+
The SDK's `resourceLink(resourceId, location)` creates a Markdown address of the form `resource:<encoded resource ID>?location=<encoded location>`. Encode the resource ID and location independently with percent encoding. A displaying interface supplies the session identity when following the link. The Agent Markdown interface recognizes these addresses; plugins can use `parseResourceLink` when providing their own link interface.
|
|
32
|
+
|
|
23
33
|
## Style plugin views
|
|
24
34
|
|
|
25
35
|
Import CSS from the renderer entry or its components. Asterism builds the imported styles and loads them before frontend preparation and view registration. CSS references to bundled images and fonts keep their relative paths. Style loading failures appear as frontend plugin failures.
|
package/package.json
CHANGED
package/src/contracts.ts
CHANGED
|
@@ -12,6 +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 "./resource-links.ts";
|
|
15
16
|
export type * from "./models.ts";
|
|
16
17
|
export { thinkingLevels } from "./models.ts";
|
|
17
18
|
export * from "./model-records.ts";
|
package/src/events.ts
CHANGED
|
@@ -61,6 +61,13 @@ export const SessionTitleChanged = defineEvent("asterism/session-title", {
|
|
|
61
61
|
semantics: { kind: "snapshot", key: ["sessionId"] },
|
|
62
62
|
});
|
|
63
63
|
|
|
64
|
+
/** The operating system resumed; consumers can re-evaluate absolute deadlines against the current wall clock. */
|
|
65
|
+
export const SystemResumed = defineEvent("asterism/system-resumed", {
|
|
66
|
+
schema: z.strictObject({}),
|
|
67
|
+
source: "host",
|
|
68
|
+
semantics: { kind: "occurrence" },
|
|
69
|
+
});
|
|
70
|
+
|
|
64
71
|
/** Transient changes to the current resource set; used to release UI state across sessions. */
|
|
65
72
|
export const ResourcePresenceChanged = defineEvent("asterism/resource-presence", {
|
|
66
73
|
schema: z.strictObject({
|
package/src/json.ts
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
|
|
3
3
|
export type Json = null | boolean | number | string | Json[] | { [key: string]: Json };
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
function isPlainObject(value: object): boolean {
|
|
6
|
+
const prototype = Object.getPrototypeOf(value);
|
|
7
|
+
return prototype === Object.prototype || prototype === null;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function isJson(value: unknown): boolean {
|
|
11
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") return true;
|
|
12
|
+
if (typeof value === "number") return Number.isFinite(value);
|
|
13
|
+
if (Array.isArray(value)) return value.every(isJson);
|
|
14
|
+
return typeof value === "object" && isPlainObject(value) && Object.values(value).every(isJson);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Any JSON value. A non-recursive check keeps the JSON Schema projection the open schema `{}`. */
|
|
18
|
+
export const jsonSchema = z.unknown().refine(isJson, "Expected a JSON value") as z.ZodType<Json>;
|
package/src/messaging.ts
CHANGED
|
@@ -43,18 +43,23 @@ export const messagingTextPartSchema = z.strictObject({ kind: z.literal("text"),
|
|
|
43
43
|
export const messagingPartSchema = z.discriminatedUnion("kind", [messagingTextPartSchema, messagingFilePartSchema]);
|
|
44
44
|
export const messageSchema = z.strictObject({
|
|
45
45
|
id, sender: messageSenderSchema, parts: z.array(messagingPartSchema),
|
|
46
|
-
sentAt: z.string(), replyTo: id.optional(), threadId: id.optional(),
|
|
46
|
+
sentAt: z.string(), replyTo: id.optional(), threadId: id.optional(), groupId: id.optional(),
|
|
47
47
|
});
|
|
48
48
|
export const messagingFileQuerySchema = conversationAddressSchema.extend({ messageId: id, fileId: id });
|
|
49
49
|
export const conversationQuerySchema = z.strictObject({ since: id.optional() });
|
|
50
50
|
export const conversationListSchema = z.strictObject({
|
|
51
51
|
conversations: z.array(conversationSchema), cursor: id.optional(), truncated: z.boolean(),
|
|
52
52
|
});
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
const messagePageTargetSchema = z.strictObject({ since: id.optional(), limit: z.number().int().positive().optional() });
|
|
54
|
+
const messageIdsTargetSchema = z.strictObject({ messageIds: z.array(id).min(1) });
|
|
55
|
+
export const messageReadTargetSchema = z.union([messagePageTargetSchema, messageIdsTargetSchema]);
|
|
56
|
+
export const messageQuerySchema = z.union([
|
|
57
|
+
conversationAddressSchema.extend(messagePageTargetSchema.shape),
|
|
58
|
+
conversationAddressSchema.extend(messageIdsTargetSchema.shape),
|
|
59
|
+
]);
|
|
56
60
|
export const messageListSchema = z.strictObject({
|
|
57
61
|
messages: z.array(messageSchema), cursor: id.optional(), truncated: z.boolean(),
|
|
62
|
+
missingIds: z.array(id).optional(),
|
|
58
63
|
});
|
|
59
64
|
/** Files are references resolved by the provider when sending; text accompanies them as a caption. */
|
|
60
65
|
export const sendMessageSchema = conversationAddressSchema.extend({
|
|
@@ -63,7 +68,7 @@ export const sendMessageSchema = conversationAddressSchema.extend({
|
|
|
63
68
|
}).refine(value => value.parts.some(part => part.kind === "file-reference" || part.text.trim()), "A message requires text or a file.");
|
|
64
69
|
export const messagingEventSchema = z.discriminatedUnion("kind", [
|
|
65
70
|
z.strictObject({ kind: z.literal("conversation.discovered"), conversation: conversationSchema }),
|
|
66
|
-
z.strictObject({ kind: z.literal("
|
|
71
|
+
z.strictObject({ kind: z.literal("messages.received"), conversation: conversationSchema, messages: z.array(messageSchema).min(1) }),
|
|
67
72
|
]);
|
|
68
73
|
export type MessagingProviderType = z.infer<typeof messagingProviderTypeSchema>;
|
|
69
74
|
export type MessagingConnection = z.infer<typeof messagingConnectionSchema>;
|
package/src/model-provider.ts
CHANGED
|
@@ -3,9 +3,12 @@ import { uiTextSchema, type UiText } from "./i18n.ts";
|
|
|
3
3
|
import { jsonSchema, type Json } from "./json.ts";
|
|
4
4
|
import { providerUsageIdSchema } from "./provider-usage.ts";
|
|
5
5
|
|
|
6
|
+
/** Host-owned model wire protocols; plugins select one and cannot register their own. */
|
|
7
|
+
export const modelProtocolIds = ["openai-responses", "openai-chat", "anthropic"] as const;
|
|
8
|
+
export type ModelProtocolId = typeof modelProtocolIds[number];
|
|
6
9
|
export const modelProviderFixedFields = ["protocol", "baseUrl", "auth", "compatibility", "usage"] as const;
|
|
7
10
|
export interface ModelProviderConnection {
|
|
8
|
-
protocol:
|
|
11
|
+
protocol: ModelProtocolId;
|
|
9
12
|
baseUrl: string;
|
|
10
13
|
auth: "api_key" | "none";
|
|
11
14
|
compatibility: { id: string; value?: Json }[];
|
|
@@ -24,9 +27,9 @@ export interface ModelProviderPreset {
|
|
|
24
27
|
verifiedOn: string;
|
|
25
28
|
keywords?: readonly string[];
|
|
26
29
|
}
|
|
27
|
-
const webUrl = z.
|
|
30
|
+
const webUrl = z.url({ protocol: /^https?$/ });
|
|
28
31
|
export const modelProviderConnectionSchema = z.strictObject({
|
|
29
|
-
protocol: z.enum(
|
|
32
|
+
protocol: z.enum(modelProtocolIds),
|
|
30
33
|
baseUrl: webUrl, auth: z.enum(["api_key", "none"]),
|
|
31
34
|
compatibility: z.array(z.strictObject({ id: z.string().min(1), value: jsonSchema.optional() })),
|
|
32
35
|
usage: providerUsageIdSchema.nullable().optional(),
|
package/src/models.ts
CHANGED
|
@@ -15,7 +15,7 @@ export interface PromptBlock { id: string; text: string; source?: { id: string;
|
|
|
15
15
|
export interface PromptFile { readonly file: string; readonly text: string }
|
|
16
16
|
export interface SystemPrompt { blocks: readonly PromptBlock[] }
|
|
17
17
|
/** Reasoning text is the plaintext delivered by the protocol, and summary is an independent summary; both can coexist or be empty, and neither fills the other.
|
|
18
|
-
* continuation carries only native data such as signatures/ciphertext; target projection determines whether it can be reused.
|
|
18
|
+
* continuation carries only native data such as signatures/ciphertext, shaped by the producing protocol; target projection determines whether it can be reused.
|
|
19
19
|
*/
|
|
20
20
|
export type ModelPart =
|
|
21
21
|
| { kind: "thinking"; text: string; summary: string; continuation: Json }
|
|
@@ -23,7 +23,7 @@ export type ModelPart =
|
|
|
23
23
|
| { kind: "toolcall"; callId: string; name: string; arguments: Json; continuation: Json };
|
|
24
24
|
export type ModelItem =
|
|
25
25
|
| { kind: "input" | "context"; parts: readonly ModelInputPart[] }
|
|
26
|
-
// scope
|
|
26
|
+
// scope and adapter (the producing protocol's continuation format) constrain native data; they do not gate public content in cross-model requests.
|
|
27
27
|
| { kind: "output"; parts: ModelPart[]; scope: string; adapter: string }
|
|
28
28
|
| { kind: "result"; callId: string; name: string; outcome: ToolOutcome };
|
|
29
29
|
export interface Usage {
|
package/src/module-contract.ts
CHANGED
|
@@ -21,6 +21,7 @@ export interface ImplementationContract<S extends Json, T extends Json, A extend
|
|
|
21
21
|
tool: ToolContract<A>;
|
|
22
22
|
targetSchema: z.ZodType<T>;
|
|
23
23
|
effect: "read" | "write";
|
|
24
|
+
/** Sequential operations share submission order; parallel operations can overlap either lane. */
|
|
24
25
|
execution: "parallel" | "sequential";
|
|
25
26
|
}
|
|
26
27
|
export function defineResource<S extends Json>(kind: string, stateSchema: z.ZodType<S>): ResourceContract<S> {
|
package/src/provider-settings.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { uiTextSchema } from "./i18n.ts";
|
|
3
3
|
|
|
4
|
-
const helpUrlSchema = z.
|
|
4
|
+
const helpUrlSchema = z.url({ protocol: /^https?$/, error: "An HTTP or HTTPS URL is required." });
|
|
5
5
|
const base = { key: z.string().regex(/^[A-Za-z][A-Za-z0-9_]*$/u), label: uiTextSchema, description: uiTextSchema.optional() };
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
import type { ResourceRef } from "./workspace.ts";
|
|
3
|
+
import type { RendererCalls } from "./renderer-calls.ts";
|
|
4
|
+
import type { RendererIsland } from "./renderer-island.ts";
|
|
5
|
+
|
|
6
|
+
export interface RendererResourceOpenOptions { readonly origin?: HTMLElement | null }
|
|
7
|
+
|
|
8
|
+
/** The resource interprets location and chooses its operation or view. Islands belong to the target plugin. */
|
|
9
|
+
export interface RendererResourceOpenContext extends RendererResourceOpenOptions {
|
|
10
|
+
readonly resource: ResourceRef;
|
|
11
|
+
readonly calls: RendererCalls;
|
|
12
|
+
readonly island: RendererIsland;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type RendererResourceOpener = (location: string, context: RendererResourceOpenContext) => boolean | Promise<boolean>;
|
|
16
|
+
|
|
17
|
+
export interface RendererResourceNavigation {
|
|
18
|
+
/** Resolve current presence without model-request authorization. Failures are shown by the host; a cancelled open returns false. */
|
|
19
|
+
open(resource: Pick<ResourceRef, "sessionId" | "id">, location: string, options?: RendererResourceOpenOptions): Promise<boolean>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const Navigation = createContext<RendererResourceNavigation | null>(null);
|
|
23
|
+
export const RendererResourceNavigationProvider = Navigation.Provider;
|
|
24
|
+
|
|
25
|
+
/** Available in plugin cards, settings, Home entries, and islands. */
|
|
26
|
+
export function useRendererResourceNavigation(): RendererResourceNavigation {
|
|
27
|
+
const navigation = useContext(Navigation);
|
|
28
|
+
if (!navigation) throw new Error("Resource navigation must be provided by the host.");
|
|
29
|
+
return navigation;
|
|
30
|
+
}
|
package/src/renderer-services.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createContext, useContext } from "react";
|
|
1
|
+
import { createContext, useContext, type ReactNode } from "react";
|
|
2
2
|
import type { Json } from "./json.ts";
|
|
3
3
|
import type { DataContract } from "./presentation.ts";
|
|
4
4
|
import type { ConfigContract } from "./config.ts";
|
|
@@ -8,7 +8,7 @@ import type { EventSubscriber } from "./events.ts";
|
|
|
8
8
|
import type { ResourceDescription } from "./renderer.ts";
|
|
9
9
|
import type { UiText } from "./i18n.ts";
|
|
10
10
|
|
|
11
|
-
/**
|
|
11
|
+
/** Statically registered resource presentation and opening behavior. */
|
|
12
12
|
export interface RendererResources {
|
|
13
13
|
list(): readonly ResourceDescription[];
|
|
14
14
|
get(kind: string): ResourceDescription;
|
|
@@ -19,6 +19,8 @@ export interface RendererTools {
|
|
|
19
19
|
preparation(name: string): string;
|
|
20
20
|
/** Localized name of a tool by its model-facing name and implementation contract; null when no view declares one. */
|
|
21
21
|
label(name: string, implementation: string | null): string | null;
|
|
22
|
+
/** Static icon of a tool by the same identity; null when no view declares one. */
|
|
23
|
+
icon(name: string, implementation: string | null): ReactNode;
|
|
22
24
|
}
|
|
23
25
|
export interface RendererModels { readonly blocks: readonly ModelLiveBlock[] }
|
|
24
26
|
export interface RendererNavigation { home(): void }
|
package/src/renderer-tools.ts
CHANGED
|
@@ -48,6 +48,8 @@ export interface ToolExecutionPhaseView<P> extends ToolStreamingPhaseView<P> {
|
|
|
48
48
|
export interface ToolRendererDefinition<D = Json, T = Json, A = Json> {
|
|
49
49
|
label?: UiText;
|
|
50
50
|
icon?: ReactNode;
|
|
51
|
+
/** Whether the conversation shell exposes raw argument/result details; defaults to true. */
|
|
52
|
+
details?: boolean;
|
|
51
53
|
input?: ToolStreamingPhaseView<ToolInputRenderProps>;
|
|
52
54
|
execution?: ToolExecutionPhaseView<ToolExecutionRenderProps<D, T, A>>;
|
|
53
55
|
result?: ToolPhaseView<ToolResultRenderProps<D, T, A>>;
|
|
@@ -55,6 +57,7 @@ export interface ToolRendererDefinition<D = Json, T = Json, A = Json> {
|
|
|
55
57
|
export interface ToolView {
|
|
56
58
|
label?: UiText;
|
|
57
59
|
icon?: ReactNode;
|
|
60
|
+
details?: boolean;
|
|
58
61
|
header?: ReactNode;
|
|
59
62
|
body?: ReactNode;
|
|
60
63
|
/** Bodies in input or execution phases may participate in streaming preview expansion and collapse; false means no match this time, and phase completion is determined by the call lifecycle. */
|
|
@@ -66,14 +69,16 @@ export interface ToolRenderer {
|
|
|
66
69
|
contract: ContractReference;
|
|
67
70
|
/** Display name of the tool, readable without rendering a call. */
|
|
68
71
|
label?: UiText;
|
|
72
|
+
/** Static operation icon, available to call summaries without rendering arguments or results. */
|
|
73
|
+
icon?: ReactNode;
|
|
69
74
|
resolve(props: ToolRenderProps): ToolView | null;
|
|
70
75
|
}
|
|
71
76
|
|
|
72
77
|
function render<P extends { phase: ToolRenderProps["phase"] }>(
|
|
73
|
-
definition: Pick<ToolView, "label" | "icon">, view: ToolExecutionPhaseView<P> | undefined, props: P,
|
|
78
|
+
definition: Pick<ToolView, "label" | "icon" | "details">, view: ToolExecutionPhaseView<P> | undefined, props: P,
|
|
74
79
|
): ToolView {
|
|
75
80
|
return {
|
|
76
|
-
label: definition.label, icon: definition.icon,
|
|
81
|
+
label: definition.label, icon: definition.icon, details: definition.details,
|
|
77
82
|
header: view?.headerRenderer ? createElement(view.headerRenderer, props) : undefined,
|
|
78
83
|
body: view?.bodyRenderer ? createElement(view.bodyRenderer, props) : undefined,
|
|
79
84
|
streaming: (props.phase === "input" || props.phase === "executing")
|
|
@@ -87,7 +92,7 @@ export function toolRenderer<D extends Json, T extends Json = Json, A extends Js
|
|
|
87
92
|
contract: DataContract<D> & { targetSchema?: z.ZodType<T>; tool?: { argsSchema: z.ZodType<A> } },
|
|
88
93
|
definition: ToolRendererDefinition<D, T, A>,
|
|
89
94
|
): ToolRenderer {
|
|
90
|
-
return { contract: reference(contract), label: definition.label, resolve(props) {
|
|
95
|
+
return { contract: reference(contract), label: definition.label, icon: definition.icon, resolve(props) {
|
|
91
96
|
if (props.phase === "input") return definition.input ? render(definition, definition.input, props) : null;
|
|
92
97
|
const data = props.result?.data;
|
|
93
98
|
const parsed = data === null || data === undefined ? null : contract.schema.safeParse(data);
|
package/src/renderer.ts
CHANGED
|
@@ -17,6 +17,7 @@ export * from "./renderer-tools.ts";
|
|
|
17
17
|
export * from "./renderer-records.ts";
|
|
18
18
|
export * from "./renderer-card.ts";
|
|
19
19
|
export * from "./renderer-island.ts";
|
|
20
|
+
export * from "./renderer-resource-open.ts";
|
|
20
21
|
export * from "./renderer-view-state.ts";
|
|
21
22
|
import type { CardPanelDefinition, CardPanelView } from "./renderer-card.ts";
|
|
22
23
|
import type { RecordRenderer } from "./renderer-records.ts";
|
|
@@ -30,6 +31,7 @@ import type { EventSubscriber } from "./events.ts";
|
|
|
30
31
|
import type { PluginCalls } from "./calls.ts";
|
|
31
32
|
import type { RendererCalls } from "./renderer-calls.ts";
|
|
32
33
|
import type { ChannelContract, ChannelEnd, ChannelValue } from "./channels.ts";
|
|
34
|
+
import type { RendererResourceOpener } from "./renderer-resource-open.ts";
|
|
33
35
|
|
|
34
36
|
/** The frontend end of a channel: messages are delivered in order and buffered until a listener registers; closed resolves when either end terminates. */
|
|
35
37
|
export interface RendererChannel<Up extends ChannelValue = ChannelValue, Down extends ChannelValue = ChannelValue> {
|
|
@@ -80,13 +82,15 @@ export function useRendererObject(): RendererObjectContext {
|
|
|
80
82
|
return object;
|
|
81
83
|
}
|
|
82
84
|
|
|
83
|
-
/**
|
|
85
|
+
/** Resource type presentation and location opening, independent of card projection. */
|
|
84
86
|
export interface ResourceDescription {
|
|
85
87
|
kind: string;
|
|
86
88
|
label: UiText;
|
|
87
89
|
icon: ReactNode;
|
|
88
90
|
/** Default card dimensions available before creation, sharing a declaration with the card renderer. */
|
|
89
91
|
card?: CardAppearance;
|
|
92
|
+
/** Open an opaque location using this resource's own operation or content surface. */
|
|
93
|
+
open?: RendererResourceOpener;
|
|
90
94
|
}
|
|
91
95
|
export interface CardView extends CardAppearance {
|
|
92
96
|
body: ReactNode;
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
}
|
package/src/runtime-contracts.ts
CHANGED
|
@@ -155,6 +155,7 @@ export type PreparedResult = CallResult & ToolInvocationInfo;
|
|
|
155
155
|
export type ToolCaller = Readonly<Pick<ResourceSnapshot, "ref" | "title"> & { agent?: string }>;
|
|
156
156
|
export interface ToolInvocation extends ToolInvocationInfo {
|
|
157
157
|
effect: "read" | "write";
|
|
158
|
+
/** Sequential operations share submission order; parallel operations can overlap either lane. */
|
|
158
159
|
execution: "parallel" | "sequential";
|
|
159
160
|
execute(signal: AbortSignal, publish?: (data: Json) => void): Promise<CallResult>;
|
|
160
161
|
toModel?(data: Json): ToolModelOutput;
|
package/src/runtime-tools.ts
CHANGED
|
@@ -19,6 +19,7 @@ export interface TopLevelTool<A extends Json = Json, D extends Json = Json> exte
|
|
|
19
19
|
/** Encodes D for progress/history and decodes it for views and model projection. */
|
|
20
20
|
readonly resultSchema: z.ZodType<D>;
|
|
21
21
|
readonly effect: "read" | "write";
|
|
22
|
+
/** Sequential operations share submission order; parallel operations can overlap either lane. */
|
|
22
23
|
readonly execution: "parallel" | "sequential";
|
|
23
24
|
execute(args: A, context: TopLevelToolContext<D>): Promise<CallResult<D>>;
|
|
24
25
|
toModel?(data: D): ToolModelOutput;
|