@pstdio/sdk 0.16.0 → 0.18.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.
@@ -3,6 +3,7 @@ import { type ExtensionClient } from "./extensions";
3
3
  import { type NotificationsClient } from "./notifications";
4
4
  import { type ProjectClient } from "./projects";
5
5
  import type { ClientOptions } from "./request";
6
+ import { type RuntimeClient } from "./runtime";
6
7
  import { type SessionClient } from "./sessions";
7
8
  import { type SettingsClient } from "./settings";
8
9
  import { type SkillClient } from "./skills";
@@ -20,5 +21,6 @@ export type PstdioClient = {
20
21
  extensions: ExtensionClient;
21
22
  settings: SettingsClient;
22
23
  sync: SyncClient;
24
+ runtime: RuntimeClient;
23
25
  };
24
26
  export declare const createClient: (options?: ClientOptions) => PstdioClient;
@@ -1,10 +1,11 @@
1
- import type { CommandExecuteRequest, CommandExecuteResponse, DispatchExtensionEventInput, EnableInstalledExtensionRequest, EnableInstalledExtensionResponse, ListExtensionAppearanceResponse, ListExtensionCommandsResponse, UpdateInstalledExtensionTemplateInput, UpdateInstalledExtensionTemplateResponse } from "pstdio-api-contracts";
1
+ import type { CommandExecuteRequest, CommandExecuteResponse, DispatchExtensionEventInput, EnableInstalledExtensionRequest, EnableInstalledExtensionResponse, ListExtensionAppearanceResponse, ListExtensionCommandsResponse, ListProjectExtensionsResponse, UpdateInstalledExtensionTemplateInput, UpdateInstalledExtensionTemplateResponse } from "pstdio-api-contracts";
2
2
  import type { RequestFn } from "./request";
3
3
  export type ExtensionClient = {
4
4
  enableInstalled(projectId: string, installName: string, request: EnableInstalledExtensionRequest): Promise<EnableInstalledExtensionResponse>;
5
5
  updateInstalledTemplate(installName: string, templateKey: string, input: UpdateInstalledExtensionTemplateInput): Promise<UpdateInstalledExtensionTemplateResponse>;
6
6
  listAppearance(projectId: string): Promise<ListExtensionAppearanceResponse>;
7
7
  listCommands(projectId: string): Promise<ListExtensionCommandsResponse>;
8
+ listProject(projectId: string): Promise<ListProjectExtensionsResponse>;
8
9
  execute(commandId: string, request: CommandExecuteRequest): Promise<CommandExecuteResponse>;
9
10
  dispatchEvent(projectId: string, input: DispatchExtensionEventInput): Promise<void>;
10
11
  };
@@ -4,6 +4,7 @@ export type { ExtensionClient } from "./extensions";
4
4
  export type { NotificationsClient } from "./notifications";
5
5
  export type { ProjectClient } from "./projects";
6
6
  export { type ClientOptions, createRequest, PstdioApiError, type RequestFn, type RequestOptions, } from "./request";
7
+ export { createRuntimeClient, type RuntimeClient } from "./runtime";
7
8
  export type { ListSessionsInput, SessionClient, SessionStreamConnection, SessionStreamHandlers } from "./sessions";
8
9
  export type { SettingsClient } from "./settings";
9
10
  export type { SkillClient } from "./skills";
@@ -31,6 +31,7 @@ var createExtensionClient = (request) => ({
31
31
  }),
32
32
  listAppearance: (projectId) => request(`/v1/projects/${projectId}/extensions/appearance`),
33
33
  listCommands: (projectId) => request(`/v1/projects/${projectId}/extensions/commands`),
34
+ listProject: (projectId) => request(`/v1/projects/${projectId}/extensions`),
34
35
  execute: (commandId, input) => {
35
36
  const { projectId, ...body } = input;
36
37
  return request(`/v1/projects/${projectId}/extensions/commands/${encodeURIComponent(commandId)}/execute`, {
@@ -150,15 +151,27 @@ ${hookOutput}` : message;
150
151
  }
151
152
  return `Request failed: ${status}`;
152
153
  };
153
- var resolveBaseUrl = (options) => options.baseUrl ?? (typeof process !== "undefined" ? process.env.PSTDIO_API_URL : undefined) ?? "http://localhost:19840";
154
+ var processEnvironment = () => typeof process !== "undefined" && process.env ? process.env : undefined;
155
+ var resolveBaseUrl = (options) => options.baseUrl ?? processEnvironment()?.PSTDIO_API_URL ?? "http://127.0.0.1:19840";
154
156
  var resolveClientUrl = (baseUrl, path) => path.startsWith("http://") || path.startsWith("https://") ? path : `${baseUrl}${path}`;
157
+ var isSameOriginTarget = (baseUrl, path, url) => {
158
+ if (!path.startsWith("http://") && !path.startsWith("https://"))
159
+ return true;
160
+ try {
161
+ return new URL(url).origin === new URL(baseUrl).origin;
162
+ } catch {
163
+ return false;
164
+ }
165
+ };
155
166
  var resolveFetch = (options) => options.fetch ?? globalThis.fetch;
167
+ var resolveToken = (options) => options.token ?? processEnvironment()?.PSTDIO_API_TOKEN;
156
168
  var createRequestHeaders = (options, reqOpts = {}) => {
157
169
  const headers = new Headers(reqOpts.headers);
158
170
  if (reqOpts.hasJsonBody && !headers.has("content-type"))
159
171
  headers.set("content-type", "application/json");
160
- if (options.token)
161
- headers.set("authorization", `Bearer ${options.token}`);
172
+ const token = resolveToken(options);
173
+ if (token)
174
+ headers.set("authorization", `Bearer ${token}`);
162
175
  return headers;
163
176
  };
164
177
  var isBinaryBody = (body) => body instanceof ArrayBuffer || ArrayBuffer.isView(body);
@@ -178,17 +191,20 @@ var createRequest = (options) => {
178
191
  const baseUrl = resolveBaseUrl(options);
179
192
  const fetchFn = resolveFetch(options);
180
193
  return async (path, reqOpts = {}) => {
194
+ const url = resolveClientUrl(baseUrl, path);
181
195
  const headers = createRequestHeaders(options, {
182
196
  headers: reqOpts.headers,
183
197
  hasJsonBody: reqOpts.body !== undefined && !isBinaryBody(reqOpts.body)
184
198
  });
185
- const url = resolveClientUrl(baseUrl, path);
199
+ if (!isSameOriginTarget(baseUrl, path, url))
200
+ headers.delete("authorization");
186
201
  const response = await fetchFn(url, {
187
202
  method: reqOpts.method ?? "GET",
188
203
  headers: Object.fromEntries(headers.entries()),
189
204
  body: reqOpts.body !== undefined ? serializeRequestBody(reqOpts.body) : undefined,
190
205
  signal: reqOpts.signal,
191
- cache: reqOpts.cache
206
+ cache: reqOpts.cache,
207
+ credentials: "same-origin"
192
208
  });
193
209
  if (!response.ok) {
194
210
  const errorBody = await response.json().catch(() => null);
@@ -201,6 +217,11 @@ var createRequest = (options) => {
201
217
  };
202
218
  };
203
219
 
220
+ // src/client/runtime.ts
221
+ var createRuntimeClient = (request) => ({
222
+ provisionBrowserSession: () => request("/runtime/browser-session", { method: "POST" })
223
+ });
224
+
204
225
  // src/client/sse.ts
205
226
  var parseSseEvent = (part) => {
206
227
  let event = "message";
@@ -260,6 +281,8 @@ var buildSessionsQuery = (projectId, input = {}) => {
260
281
  params.append("status", input.status);
261
282
  if (input.agent)
262
283
  params.append("agent", input.agent);
284
+ if (input.workspaceId)
285
+ params.append("workspace_id", input.workspaceId);
263
286
  if (input.archived)
264
287
  params.append("archived", "true");
265
288
  return params.toString();
@@ -467,7 +490,8 @@ var createSyncClient = (clientOptions) => ({
467
490
  try {
468
491
  const response = await resolveFetch(clientOptions)(resolveClientUrl(resolveBaseUrl(clientOptions), buildSyncStreamPath(lastSeq)), {
469
492
  headers: Object.fromEntries(createRequestHeaders(clientOptions).entries()),
470
- signal: abortController.signal
493
+ signal: abortController.signal,
494
+ credentials: "same-origin"
471
495
  });
472
496
  if (!response.ok || !response.body)
473
497
  throw new Error("SSE connection failed");
@@ -544,11 +568,13 @@ var createClient = (options = {}) => {
544
568
  notifications: createNotificationsClient(request),
545
569
  extensions: createExtensionClient(request),
546
570
  settings: createSettingsClient(request),
547
- sync: createSyncClient(options)
571
+ sync: createSyncClient(options),
572
+ runtime: createRuntimeClient(request)
548
573
  };
549
574
  };
550
575
  export {
551
576
  parseSyncDeleteEvent,
577
+ createRuntimeClient,
552
578
  createRequest,
553
579
  createClient,
554
580
  applySyncEvent,
@@ -0,0 +1,5 @@
1
+ import type { RequestFn } from "./request";
2
+ export type RuntimeClient = {
3
+ provisionBrowserSession: () => Promise<void>;
4
+ };
5
+ export declare const createRuntimeClient: (request: RequestFn) => RuntimeClient;
@@ -5,6 +5,7 @@ import { type SseEvent } from "./sse";
5
5
  export type ListSessionsInput = {
6
6
  status?: string;
7
7
  agent?: string;
8
+ workspaceId?: string;
8
9
  archived?: boolean;
9
10
  };
10
11
  export type SessionClient = {
@@ -42,8 +42,7 @@ type ExtensionAuthoringDefinition<TCommandSchemas extends CommandSchemas, TMiddl
42
42
  };
43
43
  /**
44
44
  * Identity helper that types the passed contributions. Authors get autocomplete on
45
- * contributions, and `commandsOf(packageName, ext)` can derive typed refs from the
46
- * returned definition. Extension identity (id, name, version, description, publisher,
45
+ * contributions. Extension identity (id, name, version, description, publisher,
47
46
  * engines.pstdio) lives in package.json.
48
47
  *
49
48
  * @example
@@ -1,12 +1,12 @@
1
1
  export type { CreateNotificationInput, ListNotificationsQuery, ListNotificationsResponse, Notification, NotificationAction, NotificationActionResult, NotificationActorType, NotificationKind, NotificationOrigin, NotificationPriority, NotificationStatus, UpdateNotificationInput, } from "pstdio-api-contracts";
2
2
  export type * from "pstdio-api-contracts/extension-kernel";
3
3
  export type { CommitPayload, ConflictPayload, MergePayload, RebasePayload, SessionLifecyclePayload, WorkspaceProvisionPayload, WorkspaceType, WorktreeRemovedPayload, } from "pstdio-api-contracts/extension-kernel";
4
- export { ALWAYS_AVAILABLE_WEBVIEW_CAPABILITIES, EXTENSION_API_VERSION, getWorkbenchModeLayoutTargetPanel, getWorkbenchTargetDefinition, gitEvents, isLocalizedString, type Localizable, type LocalizedString, l10n, packageAsset, projectEvents, projectSlots, sessionEvents, sessionSlots, WEBVIEW_DECLARABLE_CAPABILITIES, WEBVIEW_HOST_CAPABILITIES, WEBVIEW_HOST_CAPABILITY_VERSION, type WorkbenchAttachmentTarget, type WorkbenchContributionKind, type WorkbenchLayoutTarget, type WorkbenchMenuTarget, type WorkbenchModeLayoutTarget, type WorkbenchModePanel, type WorkbenchSettingsScope, type WorkbenchSettingsTarget, type WorkbenchTargetDefinition, type WorkbenchTargetGranularity, type WorkbenchTreeTarget, type WorkbenchViewTarget, workbenchMenuTargets, workbenchModeLayoutTargets, workbenchModePanels, workbenchSettingsScopes, workbenchSettingsTargets, workbenchTargets, workbenchTreeTargets, workbenchViewTargets, workspaceEvents, workspaceSlots, worktreeEvents, } from "pstdio-api-contracts/extension-kernel";
4
+ export { ALWAYS_AVAILABLE_WEBVIEW_CAPABILITIES, dockedWorkbenchRegions, EXTENSION_API_VERSION, getWorkbenchModeLayoutTargetPanel, getWorkbenchTargetDefinition, gitEvents, isLocalizedString, type Localizable, type LocalizedString, l10n, packageAsset, projectEvents, projectSlots, sessionEvents, sessionSlots, WEBVIEW_DECLARABLE_CAPABILITIES, WEBVIEW_HOST_CAPABILITIES, WEBVIEW_HOST_CAPABILITY_VERSION, type WorkbenchAttachmentTarget, type WorkbenchContributionKind, type WorkbenchLayoutTarget, type WorkbenchMenuTarget, type WorkbenchModeLayoutTarget, type WorkbenchModePanel, type WorkbenchSettingsScope, type WorkbenchSettingsTarget, type WorkbenchTargetDefinition, type WorkbenchTargetGranularity, type WorkbenchTreeTarget, type WorkbenchViewTarget, workbenchMenuTargets, workbenchModeLayoutTargets, workbenchModePanels, workbenchSettingsScopes, workbenchSettingsTargets, workbenchTargets, workbenchTreeTargets, workbenchViewTargets, workspaceEvents, workspaceSlots, worktreeEvents, } from "pstdio-api-contracts/extension-kernel";
5
5
  export { type CommandResponse, unwrapCommandOutcome } from "./command-outcome";
6
6
  export { defineCommand, defineHook, defineMiddleware } from "./define-command";
7
7
  export { defineExtension } from "./define-extension";
8
8
  export { defineExtensionView, type ExtensionViewModule, type ExtensionViewRender, type ExtensionViewRenderContext, type GuestHost, type PropsStore, type WebviewFilesClient, } from "./define-extension-view";
9
9
  export { params } from "./params";
10
- export { commandEvent, commandRef, commandsOf, eventRef } from "./refs";
10
+ export { commandEvent, commandRef, eventRef } from "./refs";
11
11
  export { createTerminalSessionBridge, type TerminalSessionAdapter, type TerminalSessionBridge, type TerminalSessionExit, } from "./terminal-session-bridge";
12
12
  export { matchesResourceWhen } from "./when";
@@ -82,8 +82,10 @@ var packageAsset = (path, baseUrl) => ({
82
82
  path,
83
83
  baseUrl
84
84
  });
85
+ // ../pstdio-api-contracts/src/extension-kernel/types/composition.ts
86
+ var dockedWorkbenchRegions = ["sidenav", "main", "secondary", "side"];
85
87
  // ../pstdio-api-contracts/src/extension-kernel/types/extension.ts
86
- var EXTENSION_API_VERSION = "1.0.0";
88
+ var EXTENSION_API_VERSION = "1.0.0-alpha.2";
87
89
  // ../pstdio-api-contracts/src/extension-kernel/types/webview-capabilities.ts
88
90
  var WEBVIEW_HOST_CAPABILITY_VERSION = 1;
89
91
  var WEBVIEW_DECLARABLE_CAPABILITIES = [
@@ -303,14 +305,6 @@ var params = {
303
305
  var commandEvent = (command, phase) => ({
304
306
  id: `command.${phase}:${command.id}`
305
307
  });
306
- var commandsOf = (packageName, extension) => {
307
- const refs = {};
308
- const commands = extension.commands ?? {};
309
- for (const key of Object.keys(commands)) {
310
- refs[key] = { id: `${packageName}.${key}` };
311
- }
312
- return refs;
313
- };
314
308
  // src/extensions/terminal-session-bridge.ts
315
309
  var TERMINAL_SESSION_CAPABILITY = "terminal.session";
316
310
  var createTerminalSessionBridge = (host) => ({
@@ -416,13 +410,13 @@ export {
416
410
  getWorkbenchTargetDefinition,
417
411
  getWorkbenchModeLayoutTargetPanel,
418
412
  eventRef,
413
+ dockedWorkbenchRegions,
419
414
  defineMiddleware,
420
415
  defineHook,
421
416
  defineExtensionView,
422
417
  defineExtension,
423
418
  defineCommand,
424
419
  createTerminalSessionBridge,
425
- commandsOf,
426
420
  commandRef,
427
421
  commandEvent,
428
422
  WEBVIEW_HOST_CAPABILITY_VERSION,
@@ -1,4 +1,4 @@
1
- import type { CommandDefinition, CommandLifecycleEventPayload, CommandLifecyclePhase, CommandRef, EventRef, ParamObjectSchema, ParamsOf, Struct } from "pstdio-api-contracts/extension-kernel";
1
+ import type { CommandLifecycleEventPayload, CommandLifecyclePhase, CommandRef, EventRef, Struct } from "pstdio-api-contracts/extension-kernel";
2
2
  export { commandRef, eventRef } from "pstdio-api-contracts/extension-kernel";
3
3
  /**
4
4
  * Build an `EventRef` for a command lifecycle phase (`requested`, `started`, `completed`,
@@ -6,23 +6,3 @@ export { commandRef, eventRef } from "pstdio-api-contracts/extension-kernel";
6
6
  * the correct shape.
7
7
  */
8
8
  export declare const commandEvent: <TPhase extends CommandLifecyclePhase, TParams extends Struct = Struct, TResult = unknown>(command: CommandRef<TParams, TResult>, phase: TPhase) => EventRef<CommandLifecycleEventPayload<TPhase, TParams, TResult>>;
9
- type CommandsRecord = Record<string, CommandDefinition<any, any, any>>;
10
- type CommandRefFromDefinition<TDefinition> = TDefinition extends CommandDefinition<infer TSchema, infer TResult, infer _TSettings> ? CommandRef<TSchema extends ParamObjectSchema ? ParamsOf<TSchema> : Struct, TResult> : never;
11
- type CommandsRefMap<TCommands extends CommandsRecord> = {
12
- [K in keyof TCommands]: CommandRefFromDefinition<TCommands[K]>;
13
- };
14
- /**
15
- * Derive typed `CommandRef`s from an extension contribution object. Renaming a
16
- * command in the definition surfaces as a type error wherever the ref is used.
17
- *
18
- * The package name is explicit because identity now lives in package.json, not in
19
- * `defineExtension()`.
20
- *
21
- * @example
22
- * const ext = defineExtension({ commands: { ... } });
23
- * const labCommands = commandsOf("extension-lab", ext);
24
- * labCommands.awaken; // CommandRef<{ title?: string }, ...>
25
- */
26
- export declare const commandsOf: <TExtension extends {
27
- commands?: CommandsRecord;
28
- }>(packageName: string, extension: TExtension) => CommandsRefMap<NonNullable<TExtension["commands"]>>;