@asterism-app/sdk 2.0.0 → 2.1.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.
@@ -14,7 +14,7 @@
14
14
  "zod": "^4.6.5"
15
15
  },
16
16
  "devDependencies": {
17
- "@asterism-app/sdk": "2.0.0",
17
+ "@asterism-app/sdk": "2.1.0",
18
18
  "typescript": "^7.0.2",
19
19
  "@types/node": "^26.6.1",
20
20
  "@types/react": "^19.3.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asterism-app/sdk",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Public contracts and host capabilities for Asterism plugins",
5
5
  "license": "MIT",
6
6
  "author": "Chien Zhang",
@@ -16,7 +16,8 @@ const encodePath = (path: string) => path.split("/").map(encodeURIComponent).joi
16
16
  const decodePath = (path: string) => path.split("/").map(decodeURIComponent).join("/");
17
17
 
18
18
  export function resourceUrl(resourceId: string, location: string): string {
19
- return `resource:${encodeURIComponent(resourceId)}/${encodePath(location)}`;
19
+ // Parentheses are URI-safe but delimit the Markdown destination used by references.
20
+ return `resource:${encodeURIComponent(resourceId)}/${encodePath(location)}`.replaceAll("(", "%28").replaceAll(")", "%29");
20
21
  }
21
22
 
22
23
  export function parseResourceUrl(value: string): ResourceUrl | null {
@@ -55,5 +56,5 @@ export function parseModelUrl(value: string): ModelExpression | null {
55
56
 
56
57
  /** The text form of a reference: a Markdown link whose label is display text and whose destination is the URL. */
57
58
  export function referenceMarkdown(label: string, url: string): string {
58
- return `[${label}](${url})`;
59
+ return `[${label.replace(/[\r\n]+/gu, " ").replace(/[\\[\]]/gu, "\\$&")}](${url})`;
59
60
  }
@@ -1,3 +1,7 @@
1
+ import type { UiText } from "./i18n.ts";
2
+ import type { RendererCalls } from "./renderer-calls.ts";
3
+ import type { ResourceRef } from "./workspace.ts";
4
+
1
5
  /**
2
6
  * Drag transfer of references. The payload is reference text: Markdown links whose destinations are reference URLs,
3
7
  * such as `[guide.md](resource:Dir-A/docs/guide.md)`. Any plugin view can be a source and any input can be a target;
@@ -20,3 +24,31 @@ export function hasReferenceDrag(transfer: DataTransfer): boolean {
20
24
  export function readReferenceDrag(transfer: DataTransfer): string | null {
21
25
  return hasReferenceDrag(transfer) ? transfer.getData(referenceDragType) : null;
22
26
  }
27
+
28
+ /** A selectable resource location. Its owner interprets the location; the picker only encodes it. */
29
+ export interface ReferenceTarget {
30
+ readonly label: string;
31
+ readonly detail?: UiText;
32
+ /** Resource-owned location; the empty location is reserved for the resource itself. */
33
+ readonly location: string;
34
+ }
35
+ export interface ListedReferenceTarget extends ReferenceTarget {
36
+ /** Additional local filtering keys. Presentation detail is not searched. */
37
+ readonly keywords?: readonly string[];
38
+ }
39
+ export interface ReferenceTargetContext {
40
+ readonly resource: ResourceRef;
41
+ readonly calls: RendererCalls;
42
+ readonly signal: AbortSignal;
43
+ }
44
+ export type ReferenceTargetProvider =
45
+ | { readonly kind: "list"; list(context: ReferenceTargetContext): Promise<readonly ListedReferenceTarget[]> }
46
+ | {
47
+ readonly kind: "search";
48
+ readonly prompt?: UiText;
49
+ readonly refineHint?: UiText;
50
+ search(query: string, context: ReferenceTargetContext): Promise<{
51
+ readonly items: readonly ReferenceTarget[];
52
+ /** Results stopped at a provider limit. Refine the query instead of paging. */
53
+ readonly limited: boolean;
54
+ }> };
package/src/renderer.ts CHANGED
@@ -35,6 +35,7 @@ import type { EventSubscriber } from "./events.ts";
35
35
  import type { PluginCalls } from "./calls.ts";
36
36
  import type { RendererCalls } from "./renderer-calls.ts";
37
37
  import type { ChannelContract, ChannelEnd, ChannelValue } from "./channels.ts";
38
+ import type { ReferenceTargetProvider } from "./renderer-references.ts";
38
39
  import type { RendererResourceOpener, RendererResourceLocationActions } from "./renderer-resource-open.ts";
39
40
 
40
41
  /** The frontend end of a channel: messages are delivered in order and buffered until a listener registers; closed resolves when either end terminates. */
@@ -95,6 +96,8 @@ export interface ResourceDescription {
95
96
  card?: CardAppearance;
96
97
  /** Open an opaque location using this resource's own operation or content surface. */
97
98
  open?: RendererResourceOpener;
99
+ /** Selectable internal reference targets. A resource root needs no provider. */
100
+ referenceTargets?: ReferenceTargetProvider;
98
101
  /** Additional user actions for a location, independent of its in-app preview format. The ID "open" is reserved for the host. */
99
102
  actions?: RendererResourceLocationActions;
100
103
  }
@@ -3,13 +3,16 @@ import { defineCall } from "./calls.ts";
3
3
  import { defineEvent } from "./events.ts";
4
4
  import { uiTextSchema } from "./i18n.ts";
5
5
 
6
- /** One live work scope, independent of timeline occupancy and notification consumption. */
7
- export const resourceActivitySchema = z.strictObject({
6
+ const activityBase = z.strictObject({
8
7
  id: z.string(),
9
8
  resource: z.strictObject({ sessionId: z.string(), id: z.string(), kind: z.string() }),
10
9
  title: uiTextSchema,
11
- progress: z.strictObject({ value: z.number().min(0).max(1) }).optional(),
12
10
  });
11
+ /** Live work or an open instance, independent of timeline occupancy and notification consumption. */
12
+ export const resourceActivitySchema = z.discriminatedUnion("kind", [
13
+ activityBase.extend({ kind: z.literal("work"), progress: z.strictObject({ value: z.number().min(0).max(1) }).optional() }),
14
+ activityBase.extend({ kind: z.literal("instance") }),
15
+ ]);
13
16
  export type ResourceActivity = z.infer<typeof resourceActivitySchema>;
14
17
 
15
18
  /** Read live scopes without loading session bodies. Subscribe to changes before reading, including after reconnection. */
@@ -29,6 +29,8 @@ export interface ExecutionServices {
29
29
  */
30
30
  withActivity<T>(resource: ResourceRef, work: (context: { signal: AbortSignal; progress(value: number | null): void }) => Promise<T>,
31
31
  options?: { signal?: AbortSignal }): Promise<T>;
32
+ /** Publish an open instance of an owned resource. Release the returned marker when the instance ends or is disposed. */
33
+ openInstanceActivity(resource: ResourceRef): () => void;
32
34
  /** Capture the owner's environment and hold resources through one request and tool batch. Callers own any timeline busy scope. */
33
35
  run(request: ResourceModelRequest, options?: ExecutionContentOptions): Promise<ModelRunResult>;
34
36
  /** Optional workbench output sink; the caller decides which execution events to send to it. */
@@ -20,5 +20,10 @@ export interface InteractiveTerminal {
20
20
  waitIdle(timeout: number | undefined, signal: AbortSignal): Promise<TerminalStatus & { reason: string; elapsedMs: number }>;
21
21
  }
22
22
  export interface TerminalSessions {
23
- create(config: TerminalConfig, events: { failed(error: unknown): void; log(message: string, error: unknown): void }): InteractiveTerminal;
23
+ create(config: TerminalConfig, events: {
24
+ /** Whether this terminal owns a live shell process, independent of viewers or foreground command state. */
25
+ aliveChanged?(alive: boolean): void;
26
+ failed(error: unknown): void;
27
+ log(message: string, error: unknown): void;
28
+ }): InteractiveTerminal;
24
29
  }