@asterism-app/sdk 1.10.1 → 1.11.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 +10 -10
- package/docs/data-and-lifecycle.md +29 -101
- package/docs/getting-started.md +15 -23
- package/docs/manual.md +12 -27
- package/docs/messaging.md +21 -11
- package/docs/minimal-plugin.md +14 -22
- package/docs/project-structure.md +14 -18
- package/docs/resources-and-tools.md +27 -47
- package/docs/session-entries.md +15 -17
- package/docs/views-and-settings.md +26 -99
- package/package.json +1 -1
- package/src/model-catalog.ts +5 -0
- package/src/models.ts +8 -2
- package/src/module-contract.ts +6 -0
- package/src/provider-usage.ts +21 -0
- package/src/renderer-island.ts +2 -0
- package/src/renderer-resource-open.ts +5 -0
- package/src/runtime-contracts.ts +11 -3
- package/src/runtime-resources.ts +2 -2
|
@@ -1,73 +1,53 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Design resources and callable capabilities
|
|
2
2
|
|
|
3
|
-
A resource represents an object with identity and lifetime. A tool represents a model-callable operation.
|
|
3
|
+
A resource represents an object with identity and lifetime. A tool represents a model-callable operation. Keeping them independent lets the same operation work across different objects without forcing those objects into one domain model.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Choose the object boundary
|
|
6
6
|
|
|
7
|
-
Use a resource for something that belongs in a session and can be
|
|
7
|
+
Use a resource for something that belongs in a session and can be recognized or operated on independently. Give it responsibility for its state, model-facing projection, and object-owned work.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
A card is a presentation of that object, not its backend lifetime. Hiding a card should not silently end work that remains meaningful without it. Conversely, retaining saved data is not a reason to keep a live process running.
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Ask for disposal confirmation when ending a live instance has consequences the user should decide about. Base the warning on work that actually exists, not on saved state that could hypothetically be restored. Warning discovery and cleanup have different purposes.
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
## Design information and access separately
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
A resource's model-facing state should let a model recognize the object and understand its relevant condition. Keep that projection with the resource implementation rather than relying on the host to interpret private saved state. Tool definitions explain operations; they are not a substitute for object state.
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
Directed links express availability to a receiver. The reverse relationship is independent, and a path through another object is not implicit access. A readable title, reference, or member directory does not grant authority over the object it names.
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
For example, a bridge can choose recipients from its direct links without acquiring their private business state. Read current relationships when handling a new external event; a model request already in progress uses its captured scope.
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
## Choose a callable boundary
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
An application action or service call need not be a model tool. Expose it when a model needs that capability, and keep the implementation's business logic shared with other callers where appropriate.
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
Reuse a tool declaration when the operation has the same meaning and shared arguments across resources. Keep resource-specific selection with the implementation. A distinct meaning deserves a distinct contract even when its code happens to resemble another operation.
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
A read operation illustrates the distinction: reading keeps its meaning while a resource decides how content is addressed and which view is useful. Name operations by that meaning, not by the file or package that happens to declare them.
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
Use a top-level capability for operations on the execution context or shared resource lifecycle, rather than inventing a placeholder resource solely to host them.
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
## Put invocation knowledge in the contract
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
Tool descriptions, guidelines, and schemas must support use independently of the manual. Explain purpose, how outputs relate to later inputs, input meaning, result interpretation, and execution boundaries in the owning contract.
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
Use examples to clarify data flow without prescribing a workflow. Describe an operation's own use of a file reference rather than assuming which resource produced it or which consumer follows it. Distinguish failure, cancellation, partial output, and uncertain effects when those differences affect what a caller can conclude.
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
Choose scheduling according to ordering requirements, not simply whether an operation reads or writes. Require interaction only when completion depends on a user response; showing progress alone does not make backend work interactive.
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
## Compose model execution deliberately
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
Session-bound model execution is useful when a request should act through a resource's links and real session. Direct model execution suits work whose messages and executable tools are supplied by the caller without a workbench object. Choose based on the access and history relationship, not on a presumed requirement to create an Agent.
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
Capture configuration and authorization at the request boundary. Read ordinary mutable content when handling an operation. For a resource addressing a selected network, this keeps the meaning of its addresses stable through the tool batch without pretending the network's content is frozen.
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
The caller owns conversation policy, historical recording, and retry decisions. Keep transient progress distinct from durable operation results. A generation failure does not necessarily mean that every earlier tool effect failed or that repeating the request is safe.
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
Resource access and timeline activity are also separate. Work that depends on a history position needs the appropriate activity scope; merely holding access to a resource does not establish that dependency. Temporary conversations need explicit ownership of attachments that must survive into later requests.
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
## Separate services from their interfaces
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
A backend capability does not automatically need a resource card or a model tool. Typed calls, events, and sustained channels serve different interaction needs; choose them according to whether the consumer requests a result, observes a change, or maintains a live connection.
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
Tool input events arrive in model order before the batch executes. A consumer can begin an operation record for each input, then fill that record when its tool completion event arrives. Progress remains transient. Response termination metadata describes model generation independently of tool outcomes, including available diagnostics after a failed stream. The caller owns retry policy and can use the returned failure's retryability without interpreting provider error strings.
|
|
56
|
-
|
|
57
|
-
For a temporary conversation, use a content scope to retain generated attachments across requests. Pass it as the input reader and output owner for session-bound execution. Persistent records or a longer-lived scope must retain any surviving results before the temporary scope closes.
|
|
58
|
-
|
|
59
|
-
## Connect other interactions
|
|
60
|
-
|
|
61
|
-
Typed calls connect request and response between services or views. Events announce transient changes. Object channels support sustained data such as an interactive screen.
|
|
62
|
-
|
|
63
|
-
An action or service call is not automatically a model tool. Expose it deliberately when the model needs that operation.
|
|
64
|
-
|
|
65
|
-
## Use shell capabilities
|
|
66
|
-
|
|
67
|
-
Backend plugins access shell profiles, one-shot execution, and interactive terminals through `plugin.shell`. Profiles are shared host configuration: `profiles.get()` reads that configuration, while `profiles.list()` resolves executable availability. Plugins choose how to expose these capabilities through their resources and tools.
|
|
68
|
-
|
|
69
|
-
Use `shell.execute(cwd, args, options)` for a noninteractive command with piped output, progress, and a final result. Each execution owns its process; cancellation or timeout stops that execution without undoing completed effects.
|
|
70
|
-
|
|
71
|
-
Use `shell.terminals.create(config, events)` for a persistent interactive session. Start the returned handle when needed and register its disposal with the owning resource or plugin lifetime. Closing a terminal permits reopening the handle; disposing it releases it permanently. Input and readiness waits are separate operations, and cancelling a wait leaves the shell running.
|
|
72
|
-
|
|
73
|
-
A terminal can serve several views through its typed input/output messages. Plugins connect viewers through object channels and choose their own presentation. Backend reads expose screen text, retained output, or character-cell image data. The host owns the PTY and screen state; a terminal handle does not create a workbench resource or model tool by itself.
|
|
53
|
+
For example, a one-shot shell process and a persistent terminal need different owners. Cancelling a command concerns that process; closing one terminal view need not end a shell shared with other views. Host services supply the execution mechanics, while the plugin chooses the domain object, presentation, and callable interface.
|
package/docs/session-entries.md
CHANGED
|
@@ -1,31 +1,29 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Design a session starting point
|
|
2
2
|
|
|
3
|
-
A session contains a history tree and a workbench.
|
|
3
|
+
A session contains a history tree and a workbench. Its starting point can be an empty workspace or a set of resources prepared for a task. An Agent and an initial message are domain choices, not prerequisites for starting work.
|
|
4
4
|
|
|
5
|
-
## Own the starting
|
|
5
|
+
## Own the starting experience
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
A session entry owns the draft, validation feedback, submission state, and initial title for its workflow. The host owns opening the resulting session and the surrounding entry selection.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Choose initial resources that make the submitted work useful. A research entry might create a workspace around a source document; a conversation entry might create an Agent and accept input. Keep the entry's purpose visible rather than asking users to configure unrelated host mechanisms.
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Separate preparation from commitment
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Preparation can perform asynchronous validation and acquire what initialization needs. The final synchronous commit establishes the session and its initial facts together. A rejected submission should not leave an apparently valid but empty piece of work behind.
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
Use the original resource creation and action contracts when initial work has the same meaning as ordinary operations. This preserves their parsing and preparation rules instead of building a special first-use path that drifts from later use.
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
Observation after commitment is not a blocking initialization hook. If a resource must have state before use, make that state part of preparation and initialization rather than relying on an observer to catch up.
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
## Keep a submission's identity
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
Treat a retry as another attempt to learn the result of the same submission, not as new work. Retain its identity and draft until acceptance is known; give a genuinely new submission a new identity.
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
This distinction matters when a response fails after the session was created. The user should be able to recover the accepted work without silently creating a duplicate session.
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
Carry attachments through their content ownership boundary, separately from the business input. A content identifier alone is not access to bytes. Transfer ownership to durable state before releasing a temporary draft.
|
|
26
26
|
|
|
27
|
-
## Name the work
|
|
27
|
+
## Name the work, not the entry
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
A paradigm can attach its own typed detail to a title assignment and implement automatic naming policy. The host preserves that detail and provides generic title operations.
|
|
29
|
+
Use the initial title to identify the work being started. Later naming policy may reflect its development, but belongs to the plugin or paradigm that understands that work. The host preserves title history without deciding what the work means.
|
|
@@ -1,124 +1,51 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Design plugin views and settings
|
|
2
2
|
|
|
3
|
-
Views present state and accept input. Backend services own the work, results, and resource lifetime.
|
|
3
|
+
Views present state and accept input. Backend services own the work, results, and resource lifetime. That boundary lets an interface close or remount without changing the meaning of independent work.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Match presentation to ownership
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
A resource card presents an object; an operation view explains one attempt to do something. An input preview may still be incomplete and is not evidence that execution began. Present final outcomes according to what actually happened, including partial effects or failure.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Use host presentation for containment and navigation. Keep the plugin's domain content within it instead of rebuilding the surrounding application. Localize the view's styling so one plugin does not redefine another's interface.
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
## Give expanded views a meaningful identity
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
An island is an expanded plugin surface with its own view lifetime. Choose its identity according to what users consider the same open work. A shared settings editor may need one instance; editors for different resources or sessions need distinct identities.
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
Base a saved editor's identity on the saved object, not an unsaved identifier field. A creation draft and a persisted object have different identities even if a user names the object “new.” After saving, normalize the draft from the accepted result rather than continuing to display a merely proposed value.
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
Opening a child view does not give it the source component's context or durable ownership. Pass the domain identity it needs explicitly and reconstruct its state from the appropriate owner. Protect unsaved edits when closing or navigating away; do not confuse a close guard with cancellation of independent backend work.
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
Cancellation should mean something specific to the task. An editor can abandon a draft, while a running export may need to stop I/O. Decide that outcome rather than treating every dismissal gesture as permission to terminate a service.
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
## Make locations reconstructable
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
A resource owns the meaning of its locations and the surfaces used to display them. Prefer a location that supplies enough domain context to reopen the same content without depending on a previous component's memory.
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
A reference names something; it is not an access grant or proof of current availability. Resolve it when followed and report the actual result. Keep navigation initiated by a user distinct from a model request's captured authorization scope.
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
Opening a file should preserve its meaning as file content. Text inside it does not become another application interaction contract merely because the viewer can recognize a link-like string.
|
|
28
28
|
|
|
29
|
-
##
|
|
29
|
+
## Keep transfers with the right owner
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
Use immutable retained content when a preview and an export must refer to exactly the same bytes. A file reference is more appropriate when the intent is to resolve content at consumption time. Make that choice before presenting the transfer as a saved result.
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
The view owns pending indicators and feedback for a transfer it starts. Its cancellation signal should stop that transfer, not unrelated readers or the resource's independent services. Treat an unavailable source or failed transfer as a failure, not as empty content.
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
## Separate settings drafts from shared configuration
|
|
36
36
|
|
|
37
|
-
A
|
|
37
|
+
A settings page owns its edit draft and interaction state; the backend owns shared configuration. Closing the page ends view subscriptions, not every service affected by the settings.
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
Choose managed configuration for schema-validated settings. Other domain data may need a different persistence model. Avoid treating every editable value as configuration simply because it appears on a settings page.
|
|
40
40
|
|
|
41
|
-
##
|
|
41
|
+
## Offer commands as focused interactions
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
Use the application palette for actions and controls that are useful without opening a full editor. Decide whether an inapplicable action should be absent or whether a temporarily unavailable action should remain visible with a reason.
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
An asynchronous command owns its pending and failure state. Close its interface when the intended result is known, not merely when work was dispatched. Backend work still uses the plugin's ordinary communication and authorization boundaries.
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
For example, a compact-row preference and a reset action should address the same preference. The palette is another interaction surface, not a second store. A real control should own its input interaction rather than masquerading as an action row.
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
## Keep language independent of work
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
A plugin can declare several settings pages independently of sessions and resources. Each has its own identity, title, summary, optional icon, and body. The icon is a component the host draws at its own size and color; the host draws the card, page heading, and attribution, and the plugin supplies only the body. Entries appear on settings home with the contributing plugin's display name. Plugin management is a separate list for installation and enablement.
|
|
54
|
-
|
|
55
|
-
The page owns its edit drafts and pending interactions; the plugin service owns shared configuration. Navigation targets a plugin and page, with an optional declared location inside the page. A page failure is isolated and can be retried without disabling other settings pages.
|
|
56
|
-
|
|
57
|
-
Managed configuration suits schema-validated settings. Other plugin data can use a storage model appropriate to its purpose.
|
|
58
|
-
|
|
59
|
-
Closing a page releases its view subscriptions. It does not end every service the plugin uses.
|
|
60
|
-
|
|
61
|
-
## Contribute application commands
|
|
62
|
-
|
|
63
|
-
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.
|
|
64
|
-
|
|
65
|
-
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.
|
|
66
|
-
|
|
67
|
-
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.
|
|
68
|
-
|
|
69
|
-
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.
|
|
70
|
-
|
|
71
|
-
For example, a plugin can combine a persistent preference control with a reset action:
|
|
72
|
-
|
|
73
|
-
```tsx
|
|
74
|
-
import { useState } from "react";
|
|
75
|
-
import { z } from "zod";
|
|
76
|
-
import {
|
|
77
|
-
defineRendererPlugin, useRendererPreferences,
|
|
78
|
-
type RendererCommandGroup,
|
|
79
|
-
} from "@asterism-app/sdk/renderer";
|
|
80
|
-
|
|
81
|
-
function CompactRows() {
|
|
82
|
-
const preferences = useRendererPreferences();
|
|
83
|
-
const [compact, setCompact] = useState(
|
|
84
|
-
() => preferences.get("compactRows", z.boolean()) ?? false,
|
|
85
|
-
);
|
|
86
|
-
return <input type="checkbox" aria-label="Compact rows" checked={compact}
|
|
87
|
-
onChange={event => {
|
|
88
|
-
const next = event.currentTarget.checked;
|
|
89
|
-
preferences.set("compactRows", next);
|
|
90
|
-
setCompact(next);
|
|
91
|
-
}} />;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const appearance: RendererCommandGroup = {
|
|
95
|
-
id: "appearance", label: "Appearance",
|
|
96
|
-
useCommands({ close }) {
|
|
97
|
-
const preferences = useRendererPreferences();
|
|
98
|
-
return [
|
|
99
|
-
{ id: "compact", label: "Compact rows", control: <CompactRows /> },
|
|
100
|
-
{
|
|
101
|
-
id: "reset", label: "Reset row spacing",
|
|
102
|
-
onAction() {
|
|
103
|
-
preferences.set("compactRows", null);
|
|
104
|
-
close();
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
];
|
|
108
|
-
},
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
export default defineRendererPlugin({ commands: [appearance] });
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
## Start work from Home
|
|
115
|
-
|
|
116
|
-
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.
|
|
117
|
-
|
|
118
|
-
Keep a retry identity until submission succeeds. Attachments travel through the call's content capability independently of its JSON input. The host handles entry selection and retains access to templates when no entry is available.
|
|
119
|
-
|
|
120
|
-
## Write interface text
|
|
121
|
-
|
|
122
|
-
Plain text is valid. Message declarations and translation catalogs support plugins that need localized interfaces.
|
|
123
|
-
|
|
124
|
-
Keep protocol identifiers, code, and raw diagnostics distinct from interface explanations. UI language changes should not reset drafts or running work.
|
|
51
|
+
Localize interface explanations without changing protocol identifiers, user content, or raw diagnostics. Changing the UI language should not reset drafts or running operations. Keep translation choices in presentation rather than making business state depend on rendered text.
|
package/package.json
CHANGED
package/src/model-catalog.ts
CHANGED
|
@@ -9,6 +9,11 @@ export const catalogModelSchema = z.object({
|
|
|
9
9
|
generation: z.object({ maxOutputTokens: z.number().nullable() }),
|
|
10
10
|
capabilities: z.object({ reasoning: z.boolean(), tools: z.boolean(), thinkingLevels: z.array(thinkingSchema) }),
|
|
11
11
|
});
|
|
12
|
+
/** Enabled model metadata available to runtime consumers; model is the complete provider/model expression. */
|
|
13
|
+
export const modelInfoSchema = catalogModelSchema.omit({ providerId: true, modelId: true, enabled: true }).extend({
|
|
14
|
+
provider: z.string(), model: z.string(),
|
|
15
|
+
});
|
|
16
|
+
export type ModelInfo = z.infer<typeof modelInfoSchema>;
|
|
12
17
|
/** Configured model metadata for plugin selectors and diagnostics; credentials remain backend capabilities. */
|
|
13
18
|
export const ModelCatalog = defineData("asterism.models/catalog", z.object({
|
|
14
19
|
modelProviders: z.array(z.object({ id: z.string(), name: z.string(), enabled: z.boolean() })),
|
package/src/models.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** Shared model protocol: independent of resource implementations, agent configuration, and host adapters. */
|
|
2
2
|
import type { Json } from "./json.ts";
|
|
3
|
+
import type { ModelInfo } from "./model-catalog.ts";
|
|
3
4
|
import type { ModelInputPart } from "./model-input.ts";
|
|
4
5
|
import type { ContentReader } from "./content-runtime.ts";
|
|
5
6
|
import type { ToolOutcome, ToolInvocationInfo, ToolResult } from "./tool-result.ts";
|
|
@@ -72,7 +73,9 @@ export type ModelLiveBlock = { id: string; responseId: string; ordinal: number }
|
|
|
72
73
|
| { kind: "thinking"; text: string; startedAt: number; endedAt: number | null }
|
|
73
74
|
/** During the input phase, arguments is a display preview parsed tolerantly and cannot be used for execution; other phases contain complete arguments. */
|
|
74
75
|
| { kind: "toolcall"; name: string; argumentsText: string; arguments: Json; state: "input" | "ready" | "executing";
|
|
75
|
-
invocation: ToolInvocationInfo | null; result: Extract<ToolResult, { kind: "running" }> | null
|
|
76
|
+
invocation: ToolInvocationInfo | null; result: Extract<ToolResult, { kind: "running" }> | null;
|
|
77
|
+
/** One-shot attention time, present only in live execution; history does not replay notices. */
|
|
78
|
+
noticeAt?: number }
|
|
76
79
|
);
|
|
77
80
|
export type ModelRunEvent =
|
|
78
81
|
| { type: "block"; block: ModelBlock }
|
|
@@ -101,6 +104,8 @@ export interface ModelToolCall { callId: string; name: string; arguments: Json }
|
|
|
101
104
|
export interface ModelToolObserver {
|
|
102
105
|
prepared?(call: ModelToolCall, info: ToolInvocationInfo): void;
|
|
103
106
|
started?(call: ModelToolCall, info: ToolInvocationInfo): void;
|
|
107
|
+
/** An accepted invocation requested attention at execution start, independently of its progress or completion. */
|
|
108
|
+
noticed?(call: ModelToolCall): void;
|
|
104
109
|
published?(call: ModelToolCall, data: Json): void;
|
|
105
110
|
}
|
|
106
111
|
/** Executable tools supplied by the requesting paradigm or a host-bound request environment. */
|
|
@@ -150,5 +155,6 @@ export interface ModelServices {
|
|
|
150
155
|
stream(request: StreamRequest, options?: ModelInputOptions): AsyncIterable<ModelEvent>;
|
|
151
156
|
/** One request and its tool batch; neither saves history nor drives the next request. */
|
|
152
157
|
run(request: ModelRunRequest, options?: ModelInputOptions): Promise<ModelRunResult>;
|
|
153
|
-
|
|
158
|
+
/** Current configured metadata for models whose model and provider are enabled; listing does not probe credentials or connectivity. */
|
|
159
|
+
list(): readonly ModelInfo[];
|
|
154
160
|
}
|
package/src/module-contract.ts
CHANGED
|
@@ -20,6 +20,12 @@ export interface ToolContract<A extends ToolInput = ToolInput> extends ContractR
|
|
|
20
20
|
argsSchema: z.ZodType<A>;
|
|
21
21
|
/** Execution requires an endpoint that can receive user interaction. Output rendering alone does not require it. */
|
|
22
22
|
requiresInteraction?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Each validated invocation requests user attention once when execution starts, independently of interaction endpoint requirements.
|
|
25
|
+
* The host publishes an awaiting reminder for the caller and exposes a transient live-call highlight. Viewing consumes the reminder;
|
|
26
|
+
* the notice does not change execution state or track unresolved business work.
|
|
27
|
+
*/
|
|
28
|
+
requiresNotice?: boolean;
|
|
23
29
|
}
|
|
24
30
|
/** Tool definitions fix selection descriptions, usage guidance, and args; implementations add only target/result and execution information. */
|
|
25
31
|
export interface ImplementationContract<S extends Json, T extends ToolInput, A extends ToolInput, O extends Json> extends DataContract<O> {
|
package/src/provider-usage.ts
CHANGED
|
@@ -61,6 +61,27 @@ export function primaryQuota(items: readonly UsageItem[]): QuotaItem | null {
|
|
|
61
61
|
return selected;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Availability that every usage consumer presents the same way. Exhausted means a request cannot succeed: a window at zero or a
|
|
66
|
+
* balance at or below zero. Low compares the bare number, so balance depletion reads the same whatever its unit.
|
|
67
|
+
*/
|
|
68
|
+
export type UsageLevel = "available" | "low" | "exhausted";
|
|
69
|
+
const lowQuotaShare = 0.25, lowBalance = 10;
|
|
70
|
+
const levelRank: Record<UsageLevel, number> = { available: 0, low: 1, exhausted: 2 };
|
|
71
|
+
export function usageItemLevel(item: UsageItem): UsageLevel {
|
|
72
|
+
const [value, low] = item.type === "quota" ? [quotaRemaining(item), lowQuotaShare] : [item.remaining, lowBalance];
|
|
73
|
+
return value <= 0 ? "exhausted" : value < low ? "low" : "available";
|
|
74
|
+
}
|
|
75
|
+
/** The most constrained item decides; null when nothing is reported. */
|
|
76
|
+
export function usageLevel(items: readonly UsageItem[]): UsageLevel | null {
|
|
77
|
+
let level: UsageLevel | null = null;
|
|
78
|
+
for (const item of items) {
|
|
79
|
+
const next = usageItemLevel(item);
|
|
80
|
+
if (!level || levelRank[next] > levelRank[level]) level = next;
|
|
81
|
+
}
|
|
82
|
+
return level;
|
|
83
|
+
}
|
|
84
|
+
|
|
64
85
|
export type UsagePeriodUnit = "year" | "month" | "week" | "day" | "hour" | "minute" | "second";
|
|
65
86
|
const periodUnits: readonly [UsagePeriodUnit, number][] = [
|
|
66
87
|
["year", 31_536_000], ["month", 2_592_000], ["week", 604_800], ["day", 86_400], ["hour", 3_600], ["minute", 60],
|
package/src/renderer-island.ts
CHANGED
|
@@ -45,6 +45,8 @@ export interface RendererIsland {
|
|
|
45
45
|
export interface RendererIslandPanelProps {
|
|
46
46
|
title: string;
|
|
47
47
|
description?: string;
|
|
48
|
+
/** What the content belongs to, shown before the title, such as a reference chip for its resource or skill. */
|
|
49
|
+
source?: ReactNode;
|
|
48
50
|
/** Primary title bar action, such as save. */
|
|
49
51
|
action?: ReactNode;
|
|
50
52
|
/** Fixed toolbar below the title bar, such as search. */
|
|
@@ -14,7 +14,12 @@ export interface RendererResourceOpenContext extends RendererResourceOpenOptions
|
|
|
14
14
|
|
|
15
15
|
export type RendererResourceOpener = (location: string, context: RendererResourceOpenContext) => boolean | Promise<boolean>;
|
|
16
16
|
|
|
17
|
+
/** Current identity and title of a present resource; kind selects its presentation through useRendererResources. */
|
|
18
|
+
export interface RendererResourceIdentity { readonly ref: ResourceRef; readonly title: string }
|
|
19
|
+
|
|
17
20
|
export interface RendererResourceNavigation {
|
|
21
|
+
/** Read the resource's current identity and title at call time; null when the session or resource is absent. Other failures reject. */
|
|
22
|
+
resolve(resource: Pick<ResourceRef, "sessionId" | "id">): Promise<RendererResourceIdentity | null>;
|
|
18
23
|
/** Resolve current presence without model-request authorization. Failures are shown by the host; a cancelled open returns false. */
|
|
19
24
|
open(resource: Pick<ResourceRef, "sessionId" | "id">, location: string, options?: RendererResourceOpenOptions): Promise<boolean>;
|
|
20
25
|
}
|
package/src/runtime-contracts.ts
CHANGED
|
@@ -12,7 +12,7 @@ import type { EventContract, PluginEvents } from "./events.ts";
|
|
|
12
12
|
import type { ToolCompletion, ToolInvocationInfo, ToolModelOutput } from "./tool-result.ts";
|
|
13
13
|
import type { PluginConfig, PluginLogger, PluginSecrets, PluginTasks } from "./runtime.ts";
|
|
14
14
|
import type { ModelServices } from "./models.ts";
|
|
15
|
-
import type { ResourceSnapshot, SessionSnapshot, SessionDirectory } from "./workspace.ts";
|
|
15
|
+
import type { ResourceRef, ResourceSnapshot, SessionSnapshot, SessionDirectory } from "./workspace.ts";
|
|
16
16
|
import type { ActionContract, CreationContract } from "./commands.ts";
|
|
17
17
|
import type { ObjectReader, ObjectExecutor, SessionExecutor } from "./objects.ts";
|
|
18
18
|
import type { ContentReader, ContentScope } from "./content-runtime.ts";
|
|
@@ -116,6 +116,11 @@ export interface ActionContribution {
|
|
|
116
116
|
prepare?(input: Json, context: ActionPreparation): Preparation | Promise<Preparation>;
|
|
117
117
|
execute(input: Json, object: ObjectExecutor, signal: AbortSignal): Promise<void>;
|
|
118
118
|
}
|
|
119
|
+
/** A live runtime instance whose termination needs user confirmation. */
|
|
120
|
+
export interface ResourceDisposalWarning {
|
|
121
|
+
readonly resource: ResourceRef;
|
|
122
|
+
readonly warning: UiText;
|
|
123
|
+
}
|
|
119
124
|
export interface ResourceContribution {
|
|
120
125
|
readonly resource: ResourceContract;
|
|
121
126
|
/** Geometry declarations for backend placement, shared with ResourceDescription and cardRenderer. */
|
|
@@ -136,8 +141,11 @@ export interface ResourceContribution {
|
|
|
136
141
|
context?(resource: ResourceSnapshot, object: ObjectReader): Promise<ContextFile[]>;
|
|
137
142
|
/** Resolve a file address against this resource at consumption time; consumers need no link or registration of the reference. */
|
|
138
143
|
openFile?(resource: ResourceSnapshot, locator: Json, context: { object: ObjectReader; signal: AbortSignal }): AsyncIterable<Uint8Array>;
|
|
139
|
-
/**
|
|
140
|
-
|
|
144
|
+
/**
|
|
145
|
+
* Enumerate warnings from this backend's live instances without restoring saved resources.
|
|
146
|
+
* The host selects affected identities and resolves their current titles. Does not perform cleanup.
|
|
147
|
+
*/
|
|
148
|
+
disposalWarnings?(): readonly ResourceDisposalWarning[];
|
|
141
149
|
/**
|
|
142
150
|
* Called synchronously when an object enters the current set through startup, creation, restoration, or rewinding.
|
|
143
151
|
* Removal ends discovery and cancels owned tasks/model requests immediately; attachment lifetime cleanup follows captured request holds.
|
package/src/runtime-resources.ts
CHANGED
|
@@ -48,7 +48,7 @@ export function implementResource<S extends Json, V extends Json>(
|
|
|
48
48
|
inspect(data: NoInfer<S>, object: ObjectReader): Promise<Json>;
|
|
49
49
|
context?(data: NoInfer<S>, object: ObjectReader): Promise<ContextFile[]>;
|
|
50
50
|
openFile?(data: NoInfer<S>, locator: Json, context: { object: ObjectReader; signal: AbortSignal }): AsyncIterable<Uint8Array>;
|
|
51
|
-
|
|
51
|
+
disposalWarnings?: ResourceContribution["disposalWarnings"];
|
|
52
52
|
/** Called when an object enters the current set; external instances owned exclusively by the object register cleanup with lifetime. */
|
|
53
53
|
attach?(data: NoInfer<S>, object: ObjectReader, lifetime: Lifetime): void;
|
|
54
54
|
},
|
|
@@ -62,7 +62,7 @@ export function implementResource<S extends Json, V extends Json>(
|
|
|
62
62
|
context: async (snapshot, object) => definition.context?.(parse(resource.stateSchema, snapshot.data, "resource"), object) ?? [],
|
|
63
63
|
...(openFile ? { openFile: (snapshot: ResourceSnapshot, locator: Json, context: { object: ObjectReader; signal: AbortSignal }) =>
|
|
64
64
|
openFile(parse(resource.stateSchema, snapshot.data, "resource"), locator, context) } : {}),
|
|
65
|
-
|
|
65
|
+
disposalWarnings: definition.disposalWarnings,
|
|
66
66
|
...(attach ? { attach: (snapshot: Parameters<NonNullable<ResourceContribution["attach"]>>[0], object: ObjectReader, lifetime: Lifetime) =>
|
|
67
67
|
attach(parse(resource.stateSchema, snapshot.data, "resource"), object, lifetime) } : {}),
|
|
68
68
|
};
|