shuvcode 2.0.23-shuv.1 → 2.0.25-shuv.1

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/bin/launcher.mjs CHANGED
@@ -90,6 +90,14 @@ function packageNames() {
90
90
 
91
91
  function resolveBinary(name) {
92
92
  const packagePath = require.resolve(`${name}/package.json`)
93
+ // Package managers keep an older platform package when the matching version is not yet on the registry,
94
+ // which would silently run the previous release under the new launcher.
95
+ const version = JSON.parse(fs.readFileSync(packagePath, "utf8")).version
96
+ if (version !== dependencies[name]) {
97
+ const error = new Error(`${name} is ${version}, expected ${dependencies[name]}`)
98
+ error.code = "STALE_PLATFORM_BINARY"
99
+ throw error
100
+ }
93
101
  const binary = path.join(path.dirname(packagePath), "bin", sourceBinary)
94
102
  if (!fs.existsSync(binary)) throw new Error(`Binary not found at ${binary}`)
95
103
  return binary
@@ -101,14 +109,21 @@ function fail(message) {
101
109
  }
102
110
 
103
111
  const names = packageNames()
104
- const binary = names.reduce((result, name) => {
105
- if (result) return result
112
+ const binary = (() => {
106
113
  try {
107
- return resolveBinary(name)
108
- } catch {
109
- return undefined
114
+ return names.reduce((result, name) => {
115
+ if (result) return result
116
+ try {
117
+ return resolveBinary(name)
118
+ } catch (error) {
119
+ if (error && error.code === "STALE_PLATFORM_BINARY") throw error
120
+ return undefined
121
+ }
122
+ }, undefined)
123
+ } catch (error) {
124
+ fail(error instanceof Error ? error.message : String(error))
110
125
  }
111
- }, undefined)
126
+ })()
112
127
 
113
128
  if (!binary) fail(`Failed to find Shuvcode binary package. Reinstall ${packageJson.name}.`)
114
129
 
@@ -113,6 +113,7 @@ export declare function make(options: ClientOptions): {
113
113
  };
114
114
  connect: {
115
115
  key: (input: import("./index.js").IntegrationConnectKeyInput, requestOptions?: OpenCode.RequestOptions) => Promise<void>;
116
+ external: (input: import("./index.js").IntegrationConnectExternalInput, requestOptions?: OpenCode.RequestOptions) => Promise<void>;
116
117
  };
117
118
  oauth: {
118
119
  connect: (input: import("./index.js").IntegrationOauthConnectInput, requestOptions?: OpenCode.RequestOptions) => Promise<import("./index.js").IntegrationOauthConnectOutput>;
@@ -1,4 +1,4 @@
1
- import type { ServerConnectInput, LocationGetInput, AgentListInput, AgentListOutput, AgentGetInput, AgentGetOutput, PluginListInput, PluginListOutput, PluginCheckInput, PluginCheckOutput, PluginUpdateInput, SessionListInput, SessionStatsInput, SessionCreateInput, SessionImportInput, SessionExportInput, SessionGetInput, SessionRemoveInput, SessionForkInput, SessionSwitchAgentInput, SessionSwitchModelInput, SessionUpdateInput, SessionMoveInput, SessionPromptInput, SessionCommandInput, SessionSkillInput, SessionSyntheticInput, SessionShellInput, SessionCompactInput, SessionWaitInput, SessionRevertStageInput, SessionRevertClearInput, SessionRevertCommitInput, SessionContextInput, SessionDiffInput, SessionInboxListInput, SessionInboxCancelInput, SessionInboxUpdateInput, SessionInstructionsEntryListInput, SessionInstructionsEntryPutInput, SessionInstructionsEntryRemoveInput, SessionGenerateInput, SessionLogInput, SessionLogOutput, SessionInterruptInput, SessionBackgroundInput, SessionMessageGetInput, SessionFormListInput, SessionFormCreateInput, SessionFormGetInput, SessionFormReplyInput, SessionFormCancelInput, SessionEnvironmentInput, SessionViewInput, MessageListInput, ModelListInput, ModelListOutput, ModelDefaultInput, ModelDefaultOutput, GenerateTextInput, ProviderListInput, ProviderListOutput, ProviderGetInput, ProviderGetOutput, IntegrationListInput, IntegrationListOutput, IntegrationGetInput, IntegrationGetOutput, IntegrationWellknownAddInput, IntegrationConnectKeyInput, IntegrationOauthConnectInput, IntegrationOauthConnectOutput, IntegrationOauthStatusInput, IntegrationOauthStatusOutput, IntegrationOauthCompleteInput, IntegrationOauthCancelInput, IntegrationCommandConnectInput, IntegrationCommandConnectOutput, IntegrationCommandStatusInput, IntegrationCommandStatusOutput, IntegrationCommandCancelInput, McpListInput, McpListOutput, McpAddInput, McpRemoveInput, McpConnectInput, McpDisconnectInput, McpResourceCatalogInput, McpResourceCatalogOutput, CredentialCreateInput, CredentialUpdateInput, CredentialActivateInput, CredentialRemoveInput, ProjectListOutput, ProjectUpdateInput, FormListInput, FormListOutput, PermissionRequestListInput, PermissionRequestListOutput, PermissionSavedListInput, PermissionSavedRemoveInput, PermissionCreateInput, PermissionListInput, PermissionGetInput, PermissionReplyInput, FileReadInput, FileReadOutput, FileListInput, FileListOutput, FileFindInput, FileFindOutput, FileWriteInput, FileWriteOutput, CommandListInput, CommandListOutput, SkillListInput, SkillListOutput, RpcCallInput, EventSubscribeOutput, PtyListInput, PtyListOutput, PtyCreateInput, PtyCreateOutput, PtyGetInput, PtyGetOutput, PtyUpdateInput, PtyUpdateOutput, PtyRemoveInput, PtyConnectTokenInput, PtyConnectTokenOutput, ExperimentalPersistentPtyReadInput, ExperimentalPersistentPtyListInput, ExperimentalPersistentPtyCreateInput, ExperimentalPersistentPtyHandoffOutput, ExperimentalPersistentPtyGetInput, ExperimentalPersistentPtyUpdateInput, ExperimentalPersistentPtySnapshotInput, ExperimentalPersistentPtyRemoveInput, ExperimentalPersistentPtyConnectTokenInput, ShellListInput, ShellListOutput, ShellCreateInput, ShellCreateOutput, ShellGetInput, ShellGetOutput, ShellOutputInput, ShellOutputOutput, ShellRemoveInput, ReferenceListInput, ReferenceListOutput, WorktreeListInput, WorktreeCreateInput, WorktreeRemoveInput, WorktreeRefreshInput, VcsInitInput, VcsGetInput, VcsGetOutput, VcsBaseInput, VcsBaseOutput, VcsStatusInput, VcsStatusOutput, VcsBranchListInput, VcsBranchListOutput, VcsDiffInput, VcsDiffOutput, DebugLocationListOutput, DebugLocationEvictInput, MigrationV1StatusOutput, WebsearchProvidersInput, WebsearchProvidersOutput, WebsearchQueryInput, WebsearchQueryOutput, ConfigGetInput, ConfigGetOutput, ConfigShellsOutput, ConfigUpdateInput } from "./types.js";
1
+ import type { ServerConnectInput, LocationGetInput, AgentListInput, AgentListOutput, AgentGetInput, AgentGetOutput, PluginListInput, PluginListOutput, PluginCheckInput, PluginCheckOutput, PluginUpdateInput, SessionListInput, SessionStatsInput, SessionCreateInput, SessionImportInput, SessionExportInput, SessionGetInput, SessionRemoveInput, SessionForkInput, SessionSwitchAgentInput, SessionSwitchModelInput, SessionUpdateInput, SessionMoveInput, SessionPromptInput, SessionCommandInput, SessionSkillInput, SessionSyntheticInput, SessionShellInput, SessionCompactInput, SessionWaitInput, SessionRevertStageInput, SessionRevertClearInput, SessionRevertCommitInput, SessionContextInput, SessionDiffInput, SessionInboxListInput, SessionInboxCancelInput, SessionInboxUpdateInput, SessionInstructionsEntryListInput, SessionInstructionsEntryPutInput, SessionInstructionsEntryRemoveInput, SessionGenerateInput, SessionLogInput, SessionLogOutput, SessionInterruptInput, SessionBackgroundInput, SessionMessageGetInput, SessionFormListInput, SessionFormCreateInput, SessionFormGetInput, SessionFormReplyInput, SessionFormCancelInput, SessionEnvironmentInput, SessionViewInput, MessageListInput, ModelListInput, ModelListOutput, ModelDefaultInput, ModelDefaultOutput, GenerateTextInput, ProviderListInput, ProviderListOutput, ProviderGetInput, ProviderGetOutput, IntegrationListInput, IntegrationListOutput, IntegrationGetInput, IntegrationGetOutput, IntegrationWellknownAddInput, IntegrationConnectKeyInput, IntegrationConnectExternalInput, IntegrationOauthConnectInput, IntegrationOauthConnectOutput, IntegrationOauthStatusInput, IntegrationOauthStatusOutput, IntegrationOauthCompleteInput, IntegrationOauthCancelInput, IntegrationCommandConnectInput, IntegrationCommandConnectOutput, IntegrationCommandStatusInput, IntegrationCommandStatusOutput, IntegrationCommandCancelInput, McpListInput, McpListOutput, McpAddInput, McpRemoveInput, McpConnectInput, McpDisconnectInput, McpResourceCatalogInput, McpResourceCatalogOutput, CredentialCreateInput, CredentialUpdateInput, CredentialActivateInput, CredentialRemoveInput, ProjectListOutput, ProjectUpdateInput, FormListInput, FormListOutput, PermissionRequestListInput, PermissionRequestListOutput, PermissionSavedListInput, PermissionSavedRemoveInput, PermissionCreateInput, PermissionListInput, PermissionGetInput, PermissionReplyInput, FileReadInput, FileReadOutput, FileListInput, FileListOutput, FileFindInput, FileFindOutput, FileWriteInput, FileWriteOutput, CommandListInput, CommandListOutput, SkillListInput, SkillListOutput, RpcCallInput, EventSubscribeOutput, PtyListInput, PtyListOutput, PtyCreateInput, PtyCreateOutput, PtyGetInput, PtyGetOutput, PtyUpdateInput, PtyUpdateOutput, PtyRemoveInput, PtyConnectTokenInput, PtyConnectTokenOutput, ExperimentalPersistentPtyReadInput, ExperimentalPersistentPtyListInput, ExperimentalPersistentPtyCreateInput, ExperimentalPersistentPtyHandoffOutput, ExperimentalPersistentPtyGetInput, ExperimentalPersistentPtyUpdateInput, ExperimentalPersistentPtySnapshotInput, ExperimentalPersistentPtyRemoveInput, ExperimentalPersistentPtyConnectTokenInput, ShellListInput, ShellListOutput, ShellCreateInput, ShellCreateOutput, ShellGetInput, ShellGetOutput, ShellOutputInput, ShellOutputOutput, ShellRemoveInput, ReferenceListInput, ReferenceListOutput, WorktreeListInput, WorktreeCreateInput, WorktreeRemoveInput, WorktreeRefreshInput, VcsInitInput, VcsGetInput, VcsGetOutput, VcsBaseInput, VcsBaseOutput, VcsStatusInput, VcsStatusOutput, VcsBranchListInput, VcsBranchListOutput, VcsDiffInput, VcsDiffOutput, DebugLocationListOutput, DebugLocationEvictInput, MigrationV1StatusOutput, WebsearchProvidersInput, WebsearchProvidersOutput, WebsearchQueryInput, WebsearchQueryOutput, ConfigGetInput, ConfigGetOutput, ConfigShellsOutput, ConfigUpdateInput } from "./types.js";
2
2
  export interface ClientOptions {
3
3
  readonly baseUrl: string;
4
4
  readonly fetch?: typeof globalThis.fetch;
@@ -114,6 +114,7 @@ export declare function make(options: ClientOptions): {
114
114
  };
115
115
  connect: {
116
116
  key: (input: IntegrationConnectKeyInput, requestOptions?: RequestOptions) => Promise<void>;
117
+ external: (input: IntegrationConnectExternalInput, requestOptions?: RequestOptions) => Promise<void>;
117
118
  };
118
119
  oauth: {
119
120
  connect: (input: IntegrationOauthConnectInput, requestOptions?: RequestOptions) => Promise<IntegrationOauthConnectOutput>;
@@ -695,6 +695,15 @@ export function make(options) {
695
695
  declaredStatuses: [400, 401, 404],
696
696
  empty: true,
697
697
  }, requestOptions),
698
+ external: (input, requestOptions) => request({
699
+ method: "POST",
700
+ path: `/api/integration/${encodeURIComponent(input.integrationID)}/connect/external`,
701
+ query: { location: input["location"] },
702
+ body: { methodID: input["methodID"], answer: input["answer"], label: input["label"] },
703
+ successStatus: 204,
704
+ declaredStatuses: [400, 401, 404],
705
+ empty: true,
706
+ }, requestOptions),
698
707
  },
699
708
  oauth: {
700
709
  connect: (input, requestOptions) => request({
@@ -496,6 +496,13 @@ export type CredentialOAuth = {
496
496
  [x: string]: JsonValue;
497
497
  };
498
498
  };
499
+ export type CredentialExternal = {
500
+ type: "external";
501
+ methodID: string;
502
+ metadata?: {
503
+ [x: string]: JsonValue;
504
+ };
505
+ };
499
506
  export type ProjectVcs = string;
500
507
  export type ProjectIcon = {
501
508
  url?: string;
@@ -1288,6 +1295,32 @@ export type SessionToolInputEnded = {
1288
1295
  text: string;
1289
1296
  };
1290
1297
  };
1298
+ export type SessionToolSubagentPrepared = {
1299
+ id: string;
1300
+ created: number;
1301
+ metadata?: {
1302
+ [x: string]: any;
1303
+ };
1304
+ type: "session.tool.subagent.prepared";
1305
+ durable: {
1306
+ aggregateID: string;
1307
+ seq: number;
1308
+ version: 1;
1309
+ };
1310
+ location?: LocationRef;
1311
+ data: {
1312
+ sessionID: string;
1313
+ assistantMessageID: string;
1314
+ id: string;
1315
+ recovery: {
1316
+ childSessionID: string;
1317
+ inboxID: string;
1318
+ inputDigest: string;
1319
+ agent: string;
1320
+ model?: ModelRef;
1321
+ };
1322
+ };
1323
+ };
1291
1324
  export type SessionRetryScheduled = {
1292
1325
  id: string;
1293
1326
  created: number;
@@ -2220,6 +2253,8 @@ export type ModelCompatibility = {
2220
2253
  requireFinishReason?: boolean;
2221
2254
  requireAssistantAfterTool?: boolean;
2222
2255
  supportsPromptCacheKey?: boolean;
2256
+ supportsThinkingBlockBinding?: boolean;
2257
+ supportsEffortUpdates?: boolean;
2223
2258
  };
2224
2259
  export type ModelCost = {
2225
2260
  tier?: {
@@ -2237,7 +2272,7 @@ export type ConnectionCredentialInfo = {
2237
2272
  type: "credential";
2238
2273
  id: string;
2239
2274
  label: string;
2240
- method: "key" | "oauth";
2275
+ method: "key" | "oauth" | "external";
2241
2276
  status?: ConnectionStatus;
2242
2277
  };
2243
2278
  export type ConnectionEnvInfo = {
@@ -3150,7 +3185,7 @@ export type ConfigEntry = {
3150
3185
  subagent_depth?: number;
3151
3186
  jev?: boolean;
3152
3187
  policies?: Array<{
3153
- action: "provider.use" | "permission";
3188
+ action: "provider.use" | "tool.use" | "integration.use";
3154
3189
  resource: string;
3155
3190
  effect: "allow" | "deny";
3156
3191
  }>;
@@ -3217,7 +3252,7 @@ export type SessionMessageAssistantTool1 = {
3217
3252
  };
3218
3253
  };
3219
3254
  export type FormFields = [FormField, ...Array<FormField>];
3220
- export type CredentialValue = CredentialOAuth | CredentialKey;
3255
+ export type CredentialValue = CredentialOAuth | CredentialKey | CredentialExternal;
3221
3256
  export type FormFields2 = [FormField1, ...Array<FormField1>];
3222
3257
  export type SessionsResponse = {
3223
3258
  data: Array<SessionInfo>;
@@ -3300,6 +3335,12 @@ export type IntegrationKeyMethod = {
3300
3335
  label?: string;
3301
3336
  form?: FormFields;
3302
3337
  };
3338
+ export type IntegrationExternalMethod = {
3339
+ id: string;
3340
+ type: "external";
3341
+ label: string;
3342
+ form?: FormFields;
3343
+ };
3303
3344
  export type CredentialEntry = {
3304
3345
  id: string;
3305
3346
  integrationID: string;
@@ -3334,7 +3375,7 @@ export type SessionMessageContentUpdated = {
3334
3375
  content: Array<SessionMessageAssistantContentEncoded>;
3335
3376
  };
3336
3377
  };
3337
- export type IntegrationMethod = IntegrationOAuthMethod | IntegrationCommandMethod | IntegrationKeyMethod | IntegrationEnvMethod;
3378
+ export type IntegrationMethod = IntegrationOAuthMethod | IntegrationCommandMethod | IntegrationKeyMethod | IntegrationExternalMethod | IntegrationEnvMethod;
3338
3379
  export type FormCreated = {
3339
3380
  id: string;
3340
3381
  created: number;
@@ -3358,7 +3399,7 @@ export type SessionMessagesResponse = {
3358
3399
  next?: string | null;
3359
3400
  };
3360
3401
  };
3361
- export type SessionEventDurable = SessionCreated | SessionAgentSelected | SessionModelSelected | SessionMoved | SessionRenamed | SessionMetadataUpdated | SessionPermissions | SessionViewed | SessionDeleted | SessionForked | SessionInboxDelivered | SessionInboxEnqueued | SessionInboxCancelled | SessionInboxDeliveryChanged | SessionExecutionStarted | SessionExecutionSucceeded | SessionExecutionFailed | SessionExecutionInterrupted | SessionInstructionsUpdated | SessionSynthetic | SessionSkillActivated | SessionShellStarted | SessionShellEnded | SessionStepStarted | SessionStepStreamed | SessionStepEnded | SessionStepFailed | SessionTextStarted | SessionTextEnded | SessionReasoningStarted | SessionReasoningEnded | SessionToolInputStarted | SessionToolInputEnded | SessionToolCalled | SessionToolSuccess | SessionToolFailed | SessionRetryScheduled | SessionCompactionStarted | SessionCompactionEnded | SessionCompactionFailed | SessionRevertStaged | SessionRevertCleared | SessionRevertCommitted | SessionUsageRecorded | SessionMessageContentUpdated;
3402
+ export type SessionEventDurable = SessionCreated | SessionAgentSelected | SessionModelSelected | SessionMoved | SessionRenamed | SessionMetadataUpdated | SessionPermissions | SessionViewed | SessionDeleted | SessionForked | SessionInboxDelivered | SessionInboxEnqueued | SessionInboxCancelled | SessionInboxDeliveryChanged | SessionExecutionStarted | SessionExecutionSucceeded | SessionExecutionFailed | SessionExecutionInterrupted | SessionInstructionsUpdated | SessionSynthetic | SessionSkillActivated | SessionShellStarted | SessionShellEnded | SessionStepStarted | SessionStepStreamed | SessionStepEnded | SessionStepFailed | SessionTextStarted | SessionTextEnded | SessionReasoningStarted | SessionReasoningEnded | SessionToolInputStarted | SessionToolInputEnded | SessionToolCalled | SessionToolSubagentPrepared | SessionToolSuccess | SessionToolFailed | SessionRetryScheduled | SessionCompactionStarted | SessionCompactionEnded | SessionCompactionFailed | SessionRevertStaged | SessionRevertCleared | SessionRevertCommitted | SessionUsageRecorded | SessionMessageContentUpdated;
3362
3403
  export type IntegrationInfo = {
3363
3404
  id: string;
3364
3405
  name: string;
@@ -3368,7 +3409,7 @@ export type IntegrationInfo = {
3368
3409
  methods: Array<IntegrationMethod>;
3369
3410
  connections: Array<ConnectionInfo>;
3370
3411
  };
3371
- export type V2Event = LocationShutdown | ModelsDevRefreshed | CredentialUpdated | CredentialSwitched | IntegrationUpdated | ProviderUpdated | ModelUpdated | AgentUpdated | SessionCreated | SessionAgentSelected | SessionModelSelected | SessionMoved | SessionRenamed | SessionMetadataUpdated | SessionPermissions | SessionViewed | SessionUsageUpdated | SessionDeleted | SessionForked | SessionInboxDelivered | SessionInboxEnqueued | SessionInboxCancelled | SessionInboxDeliveryChanged | SessionExecutionStarted | SessionExecutionSucceeded | SessionExecutionFailed | SessionExecutionInterrupted | SessionInstructionsUpdated | SessionSynthetic | SessionSkillActivated | SessionShellStarted | SessionShellEnded | SessionStepStarted | SessionStepStreamed | SessionStepEnded | SessionStepFailed | SessionTextStarted | SessionTextDelta | SessionTextEnded | SessionReasoningStarted | SessionReasoningDelta | SessionReasoningEnded | SessionToolInputStarted | SessionToolInputDelta | SessionToolInputEnded | SessionToolCalled | SessionToolProgress | SessionToolSuccess | SessionToolFailed | SessionRetryScheduled | SessionCompactionStarted | SessionCompactionDelta | SessionCompactionEnded | SessionCompactionFailed | SessionRevertStaged | SessionRevertCleared | SessionRevertCommitted | FilesystemChanged | ReferenceUpdated | PermissionAsked | PermissionReplied | PermissionCancelled | PluginUpdated | ProjectUpdated | WorktreeUpdated | WorktreeResolved | CommandUpdated | ConfigUpdated | SkillUpdated | PtyCreated | PtyUpdated | PtyExited | PtyDeleted | PersistentPtyAdded | PersistentPtyRemoved | ShellCreated | ShellExited | ShellDeleted | FormCreated | FormReplied | FormCancelled | WebsearchUpdated | SessionStatusUpdated | SessionIdle | TuiPromptAppend | TuiCommandExecute | TuiToastShow | TuiSessionSelect | InstallationUpdated | InstallationUpdateAvailable | VcsBranchUpdated | McpStatusChanged | McpResourcesChanged | V2EventRpc | V2EventServerConnected;
3412
+ export type V2Event = LocationShutdown | ModelsDevRefreshed | CredentialUpdated | CredentialSwitched | IntegrationUpdated | ProviderUpdated | ModelUpdated | AgentUpdated | SessionCreated | SessionAgentSelected | SessionModelSelected | SessionMoved | SessionRenamed | SessionMetadataUpdated | SessionPermissions | SessionViewed | SessionUsageUpdated | SessionDeleted | SessionForked | SessionInboxDelivered | SessionInboxEnqueued | SessionInboxCancelled | SessionInboxDeliveryChanged | SessionExecutionStarted | SessionExecutionSucceeded | SessionExecutionFailed | SessionExecutionInterrupted | SessionInstructionsUpdated | SessionSynthetic | SessionSkillActivated | SessionShellStarted | SessionShellEnded | SessionStepStarted | SessionStepStreamed | SessionStepEnded | SessionStepFailed | SessionTextStarted | SessionTextDelta | SessionTextEnded | SessionReasoningStarted | SessionReasoningDelta | SessionReasoningEnded | SessionToolInputStarted | SessionToolInputDelta | SessionToolInputEnded | SessionToolCalled | SessionToolSubagentPrepared | SessionToolProgress | SessionToolSuccess | SessionToolFailed | SessionRetryScheduled | SessionCompactionStarted | SessionCompactionDelta | SessionCompactionEnded | SessionCompactionFailed | SessionRevertStaged | SessionRevertCleared | SessionRevertCommitted | FilesystemChanged | ReferenceUpdated | PermissionAsked | PermissionReplied | PermissionCancelled | PluginUpdated | ProjectUpdated | WorktreeUpdated | WorktreeResolved | CommandUpdated | ConfigUpdated | SkillUpdated | PtyCreated | PtyUpdated | PtyExited | PtyDeleted | PersistentPtyAdded | PersistentPtyRemoved | ShellCreated | ShellExited | ShellDeleted | FormCreated | FormReplied | FormCancelled | WebsearchUpdated | SessionStatusUpdated | SessionIdle | TuiPromptAppend | TuiCommandExecute | TuiToastShow | TuiSessionSelect | InstallationUpdated | InstallationUpdateAvailable | VcsBranchUpdated | McpStatusChanged | McpResourcesChanged | V2EventRpc | V2EventServerConnected;
3372
3413
  export type SessionLogItem = SessionEventDurable | EventLogSynced;
3373
3414
  export type InvalidRequestError = {
3374
3415
  readonly _tag: "InvalidRequestError";
@@ -7336,6 +7377,38 @@ export type IntegrationConnectKeyInput = {
7336
7377
  }["label"];
7337
7378
  };
7338
7379
  export type IntegrationConnectKeyOutput = void;
7380
+ export type IntegrationConnectExternalInput = {
7381
+ readonly integrationID: {
7382
+ readonly integrationID: string;
7383
+ }["integrationID"];
7384
+ readonly location?: {
7385
+ readonly location?: {
7386
+ readonly directory?: string | undefined;
7387
+ } | undefined;
7388
+ }["location"];
7389
+ readonly methodID: {
7390
+ readonly methodID: string;
7391
+ readonly answer?: {
7392
+ readonly [x: string]: string | number | boolean | ReadonlyArray<string>;
7393
+ } | undefined;
7394
+ readonly label?: string | undefined;
7395
+ }["methodID"];
7396
+ readonly answer?: {
7397
+ readonly methodID: string;
7398
+ readonly answer?: {
7399
+ readonly [x: string]: string | number | boolean | ReadonlyArray<string>;
7400
+ } | undefined;
7401
+ readonly label?: string | undefined;
7402
+ }["answer"];
7403
+ readonly label?: {
7404
+ readonly methodID: string;
7405
+ readonly answer?: {
7406
+ readonly [x: string]: string | number | boolean | ReadonlyArray<string>;
7407
+ } | undefined;
7408
+ readonly label?: string | undefined;
7409
+ }["label"];
7410
+ };
7411
+ export type IntegrationConnectExternalOutput = void;
7339
7412
  export type IntegrationOauthConnectInput = {
7340
7413
  readonly integrationID: {
7341
7414
  readonly integrationID: string;
@@ -7614,6 +7687,12 @@ export type CredentialCreateInput = {
7614
7687
  readonly configuration?: {
7615
7688
  readonly [x: string]: string | number | "Infinity" | "-Infinity" | "NaN" | boolean | ReadonlyArray<string>;
7616
7689
  };
7690
+ } | {
7691
+ readonly type: "external";
7692
+ readonly methodID: string;
7693
+ readonly metadata?: {
7694
+ readonly [x: string]: JsonValue;
7695
+ };
7617
7696
  };
7618
7697
  readonly activate?: boolean;
7619
7698
  }["id"];
@@ -7639,6 +7718,12 @@ export type CredentialCreateInput = {
7639
7718
  readonly configuration?: {
7640
7719
  readonly [x: string]: string | number | "Infinity" | "-Infinity" | "NaN" | boolean | ReadonlyArray<string>;
7641
7720
  };
7721
+ } | {
7722
+ readonly type: "external";
7723
+ readonly methodID: string;
7724
+ readonly metadata?: {
7725
+ readonly [x: string]: JsonValue;
7726
+ };
7642
7727
  };
7643
7728
  readonly activate?: boolean;
7644
7729
  }["integrationID"];
@@ -7664,6 +7749,12 @@ export type CredentialCreateInput = {
7664
7749
  readonly configuration?: {
7665
7750
  readonly [x: string]: string | number | "Infinity" | "-Infinity" | "NaN" | boolean | ReadonlyArray<string>;
7666
7751
  };
7752
+ } | {
7753
+ readonly type: "external";
7754
+ readonly methodID: string;
7755
+ readonly metadata?: {
7756
+ readonly [x: string]: JsonValue;
7757
+ };
7667
7758
  };
7668
7759
  readonly activate?: boolean;
7669
7760
  }["label"];
@@ -7689,6 +7780,12 @@ export type CredentialCreateInput = {
7689
7780
  readonly configuration?: {
7690
7781
  readonly [x: string]: string | number | "Infinity" | "-Infinity" | "NaN" | boolean | ReadonlyArray<string>;
7691
7782
  };
7783
+ } | {
7784
+ readonly type: "external";
7785
+ readonly methodID: string;
7786
+ readonly metadata?: {
7787
+ readonly [x: string]: JsonValue;
7788
+ };
7692
7789
  };
7693
7790
  readonly activate?: boolean;
7694
7791
  }["value"];
@@ -7714,6 +7811,12 @@ export type CredentialCreateInput = {
7714
7811
  readonly configuration?: {
7715
7812
  readonly [x: string]: string | number | "Infinity" | "-Infinity" | "NaN" | boolean | ReadonlyArray<string>;
7716
7813
  };
7814
+ } | {
7815
+ readonly type: "external";
7816
+ readonly methodID: string;
7817
+ readonly metadata?: {
7818
+ readonly [x: string]: JsonValue;
7819
+ };
7717
7820
  };
7718
7821
  readonly activate?: boolean;
7719
7822
  }["activate"];
package/client/index.js CHANGED
@@ -1,4 +1,4 @@
1
- var A=Object.defineProperty;var E=(t)=>t;function q(t,a){this[t]=E.bind(null,a)}var w=(t,a)=>{for(var s in a)A(t,s,{get:a[s],enumerable:!0,configurable:!0,set:q.bind(a,s)})};class c extends Error{reason;name="ClientError";constructor(t,a){let s=a?.detail??(a?.cause instanceof Error?a.cause.message:void 0);super(s?`${t}: ${s}`:t,a);this.reason=t}}var L=16777216;function F(t){let a=t.fetch??globalThis.fetch,s=(e,n)=>{let o=new URL(t.baseUrl);if(!o.pathname.endsWith("/"))o.pathname+="/";let i=new URL(e.path.slice(1),o);for(let[d,y]of Object.entries(e.query??{}))h(i.searchParams,d,y);let m=new Headers(t.headers);for(let[d,y]of Object.entries(e.headers??{}))if(y!==void 0&&y!==null)m.set(d,String(y));for(let[d,y]of new Headers(n?.headers))m.set(d,y);if(e.body!==void 0&&!m.has("content-type"))m.set("content-type",e.binaryBody?"application/octet-stream":"application/json");return{url:i,init:{method:e.method,signal:n?.signal,headers:m,body:e.body===void 0?void 0:e.binaryBody?e.body:JSON.stringify(e.body)}}},g=async(e,n)=>{try{let o=s(e,n);return await a(o.url,o.init)}catch(o){throw new c("Transport",{cause:o})}},p=async(e,n)=>{if(n.declaredStatuses.includes(e.status))throw N(await R(e));try{await e.body?.cancel()}catch{}throw new c("UnexpectedStatus",{cause:{status:e.status},detail:String(e.status)})},r=async(e,n)=>{let o=await g(e,n);if(o.status!==e.successStatus)return p(o,e);if(e.binary)return new Uint8Array(await o.arrayBuffer());if(e.empty){try{await o.body?.cancel()}catch{}return}return await R(o)},l=(e,n)=>({async*[Symbol.asyncIterator](){let o=await g(e,n);if(o.status!==e.successStatus)await p(o,e);if(!D(o,"text/event-stream")){try{await o.body?.cancel()}catch{}throw new c("UnsupportedContentType",{detail:o.headers.get("content-type")})}if(o.body===null)throw new c("MalformedResponse");let i=o.body.getReader(),m=new TextDecoder,d="";try{while(!0){let y;try{y=await i.read()}catch(I){throw new c("Transport",{cause:I})}if(!y.done)n?.onActivity?.();if(d+=m.decode(y.value,{stream:!y.done}),d.length>L)throw new c("SseEventTooLarge");let f=!y.done&&d.endsWith("\r");if(f)d=d.slice(0,-1);if(d=d.replaceAll(`\r
1
+ var E=Object.defineProperty;var A=(t)=>t;function q(t,a){this[t]=A.bind(null,a)}var w=(t,a)=>{for(var s in a)E(t,s,{get:a[s],enumerable:!0,configurable:!0,set:q.bind(a,s)})};class c extends Error{reason;name="ClientError";constructor(t,a){let s=a?.detail??(a?.cause instanceof Error?a.cause.message:void 0);super(s?`${t}: ${s}`:t,a);this.reason=t}}var L=16777216;function F(t){let a=t.fetch??globalThis.fetch,s=(e,n)=>{let o=new URL(t.baseUrl);if(!o.pathname.endsWith("/"))o.pathname+="/";let i=new URL(e.path.slice(1),o);for(let[d,y]of Object.entries(e.query??{}))h(i.searchParams,d,y);let m=new Headers(t.headers);for(let[d,y]of Object.entries(e.headers??{}))if(y!==void 0&&y!==null)m.set(d,String(y));for(let[d,y]of new Headers(n?.headers))m.set(d,y);if(e.body!==void 0&&!m.has("content-type"))m.set("content-type",e.binaryBody?"application/octet-stream":"application/json");return{url:i,init:{method:e.method,signal:n?.signal,headers:m,body:e.body===void 0?void 0:e.binaryBody?e.body:JSON.stringify(e.body)}}},g=async(e,n)=>{try{let o=s(e,n);return await a(o.url,o.init)}catch(o){throw new c("Transport",{cause:o})}},p=async(e,n)=>{if(n.declaredStatuses.includes(e.status))throw N(await R(e));try{await e.body?.cancel()}catch{}throw new c("UnexpectedStatus",{cause:{status:e.status},detail:String(e.status)})},r=async(e,n)=>{let o=await g(e,n);if(o.status!==e.successStatus)return p(o,e);if(e.binary)return new Uint8Array(await o.arrayBuffer());if(e.empty){try{await o.body?.cancel()}catch{}return}return await R(o)},l=(e,n)=>({async*[Symbol.asyncIterator](){let o=await g(e,n);if(o.status!==e.successStatus)await p(o,e);if(!D(o,"text/event-stream")){try{await o.body?.cancel()}catch{}throw new c("UnsupportedContentType",{detail:o.headers.get("content-type")})}if(o.body===null)throw new c("MalformedResponse");let i=o.body.getReader(),m=new TextDecoder,d="";try{while(!0){let y;try{y=await i.read()}catch(I){throw new c("Transport",{cause:I})}if(!y.done)n?.onActivity?.();if(d+=m.decode(y.value,{stream:!y.done}),d.length>L)throw new c("SseEventTooLarge");let f=!y.done&&d.endsWith("\r");if(f)d=d.slice(0,-1);if(d=d.replaceAll(`\r
2
2
  `,`
3
3
  `).replaceAll("\r",`
4
4
  `),f)d+="\r";if(y.done&&d!=="")d+=`
@@ -9,4 +9,4 @@ var A=Object.defineProperty;var E=(t)=>t;function q(t,a){this[t]=E.bind(null,a)}
9
9
  `).flatMap((x)=>x.startsWith("data:")?[x.slice(5).trimStart()]:[]).join(`
10
10
  `);if(b!=="")try{yield JSON.parse(b)}catch(x){throw new c("MalformedResponse",{cause:x})}u=d.indexOf(`
11
11
 
12
- `)}if(y.done)return}}finally{try{await i.cancel()}catch{}i.releaseLock()}}});return{server:{info:(e)=>r({method:"GET",path:"/api/info",successStatus:200,declaredStatuses:[400,401],empty:!1},e),pair:(e)=>r({method:"POST",path:"/api/pair",successStatus:200,declaredStatuses:[400,401],empty:!1},e),connect:(e,n)=>r({method:"GET",path:`/auth/connect/${encodeURIComponent(e.code)}`,successStatus:200,declaredStatuses:[400,401],empty:!1},n)},location:{get:(e,n)=>r({method:"GET",path:"/api/location",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),reload:(e)=>r({method:"POST",path:"/api/location/reload",successStatus:204,declaredStatuses:[400,401,503],empty:!0},e)},agent:{list:(e,n)=>r({method:"GET",path:"/api/agent",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),get:(e,n)=>r({method:"GET",path:`/api/agent/${encodeURIComponent(e.agentID)}`,query:{location:e.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n)},plugin:{list:(e,n)=>r({method:"GET",path:"/api/plugin",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),check:(e,n)=>r({method:"POST",path:"/api/plugin/check",query:{location:e?.location},body:{target:e?.target},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),update:(e,n)=>r({method:"POST",path:"/api/plugin/update",query:{location:e.location},body:{targets:e.targets},successStatus:204,declaredStatuses:[400,401,404,503],empty:!0},n)},session:{list:(e,n)=>r({method:"GET",path:"/api/session",query:{limit:e?.limit,order:e?.order,search:e?.search,parentID:e?.parentID,directory:e?.directory,project:e?.project,subpath:e?.subpath,cursor:e?.cursor},successStatus:200,declaredStatuses:[400,401],empty:!1},n),stats:(e,n)=>r({method:"GET",path:"/api/experimental/session/stats",query:{from:e?.from,to:e?.to,project:e?.project,timezone:e?.timezone,tools:e?.tools},successStatus:200,declaredStatuses:[400,401],empty:!1},n).then((o)=>o.data),create:(e,n)=>r({method:"POST",path:"/api/session",body:{id:e?.id,parentID:e?.parentID,title:e?.title,agent:e?.agent,model:e?.model,location:e?.location,metadata:e?.metadata,permissions:e?.permissions},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n).then((o)=>o.data),import:(e,n)=>r({method:"POST",path:"/api/experimental/session/import",body:{info:e.info,messages:e.messages,location:e.location},successStatus:200,declaredStatuses:[400,401,404,409],empty:!1},n).then((o)=>o.data),export:(e,n)=>r({method:"GET",path:`/api/experimental/session/${encodeURIComponent(e.sessionID)}/export`,query:{sanitize:e.sanitize},successStatus:200,declaredStatuses:[400,401,404,500],empty:!1},n).then((o)=>o.data),active:(e)=>r({method:"GET",path:"/api/session/active",successStatus:200,declaredStatuses:[400,401],empty:!1},e).then((n)=>n.data),get:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}`,successStatus:200,declaredStatuses:[400,401,404],empty:!1},n).then((o)=>o.data),remove:(e,n)=>r({method:"DELETE",path:`/api/session/${encodeURIComponent(e.sessionID)}`,successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),fork:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/fork`,body:{before:e.before},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n).then((o)=>o.data),switchAgent:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/agent`,body:{agent:e.agent},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),switchModel:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/model`,body:{model:e.model},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),update:(e,n)=>r({method:"PATCH",path:`/api/session/${encodeURIComponent(e.sessionID)}`,body:{title:e.title,metadata:e.metadata,permissions:e.permissions},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),move:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/move`,body:{directory:e.directory,delivery:e.delivery},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),prompt:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/prompt`,body:{id:e.id,text:e.text,files:e.files,agents:e.agents,skills:e.skills,metadata:e.metadata,delivery:e.delivery,resume:e.resume},successStatus:200,declaredStatuses:[400,401,404,409],empty:!1},n).then((o)=>o.data),command:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/command`,body:{name:e.name,text:e.text,files:e.files,agents:e.agents,skills:e.skills,delivery:e.delivery},successStatus:204,declaredStatuses:[400,401,404,500],empty:!0},n),skill:(e,n)=>r({method:"POST",path:`/api/experimental/session/${encodeURIComponent(e.sessionID)}/skill`,body:{id:e.id,resume:e.resume},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),synthetic:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/synthetic`,body:{id:e.id,text:e.text,description:e.description,metadata:e.metadata,delivery:e.delivery,resume:e.resume},successStatus:200,declaredStatuses:[400,401,404,409],empty:!1},n).then((o)=>o.data),shell:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/shell`,body:{id:e.id,command:e.command},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),compact:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/compact`,body:{id:e.id,delivery:e.delivery},successStatus:200,declaredStatuses:[400,401,404,409],empty:!1},n).then((o)=>o.data),wait:(e,n)=>r({method:"POST",path:`/api/experimental/session/${encodeURIComponent(e.sessionID)}/wait`,successStatus:204,declaredStatuses:[400,401,404,503],empty:!0},n),revert:{stage:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/revert/stage`,body:{messageID:e.messageID,files:e.files},successStatus:200,declaredStatuses:[400,401,404,409,500],empty:!1},n).then((o)=>o.data),clear:(e,n)=>r({method:"DELETE",path:`/api/session/${encodeURIComponent(e.sessionID)}/revert`,successStatus:204,declaredStatuses:[400,401,404,409,500],empty:!0},n),commit:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/revert/commit`,successStatus:204,declaredStatuses:[400,401,404,409],empty:!0},n)},context:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/context`,successStatus:200,declaredStatuses:[400,401,404,500],empty:!1},n).then((o)=>o.data),diff:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/diff`,query:{from:e.from,to:e.to,context:e.context},successStatus:200,declaredStatuses:[400,401,404,500],empty:!1},n).then((o)=>o.data),inbox:{list:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/inbox`,successStatus:200,declaredStatuses:[400,401,404],empty:!1},n).then((o)=>o.data),cancel:(e,n)=>r({method:"DELETE",path:`/api/session/${encodeURIComponent(e.sessionID)}/inbox/${encodeURIComponent(e.inboxID)}`,successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),update:(e,n)=>r({method:"PATCH",path:`/api/session/${encodeURIComponent(e.sessionID)}/inbox/${encodeURIComponent(e.inboxID)}`,body:{delivery:e.delivery},successStatus:204,declaredStatuses:[400,401,404,409],empty:!0},n)},instructions:{entry:{list:(e,n)=>r({method:"GET",path:`/api/experimental/session/${encodeURIComponent(e.sessionID)}/instructions/entries`,successStatus:200,declaredStatuses:[400,401,404],empty:!1},n).then((o)=>o.data),put:(e,n)=>r({method:"PUT",path:`/api/experimental/session/${encodeURIComponent(e.sessionID)}/instructions/entries/${encodeURIComponent(e.key)}`,body:{value:e.value},successStatus:204,declaredStatuses:[400,401,404,413],empty:!0},n),remove:(e,n)=>r({method:"DELETE",path:`/api/experimental/session/${encodeURIComponent(e.sessionID)}/instructions/entries/${encodeURIComponent(e.key)}`,successStatus:204,declaredStatuses:[400,401,404],empty:!0},n)}},generate:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/generate`,body:{prompt:e.prompt},successStatus:200,declaredStatuses:[400,401,404,503],empty:!1},n).then((o)=>o.data),log:(e,n)=>l({method:"GET",path:`/api/experimental/session/${encodeURIComponent(e.sessionID)}/log`,query:{after:e.after,follow:e.follow},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),interrupt:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/interrupt`,query:{resume:e.resume},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),background:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/background`,successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),message:{get:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/message/${encodeURIComponent(e.messageID)}`,successStatus:200,declaredStatuses:[400,401,404],empty:!1},n).then((o)=>o.data)},form:{list:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/form`,successStatus:200,declaredStatuses:[400,401,404],empty:!1},n).then((o)=>o.data),create:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/form`,body:{id:e.id,title:e.title,metadata:e.metadata,fields:e.fields},successStatus:200,declaredStatuses:[400,401,404,409],empty:!1},n).then((o)=>o.data),get:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/form/${encodeURIComponent(e.formID)}`,successStatus:200,declaredStatuses:[400,401,404],empty:!1},n).then((o)=>o.data),reply:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/form/${encodeURIComponent(e.formID)}/reply`,body:{answer:e.answer},successStatus:204,declaredStatuses:[400,401,404,409],empty:!0},n),cancel:(e,n)=>r({method:"DELETE",path:`/api/session/${encodeURIComponent(e.sessionID)}/form/${encodeURIComponent(e.formID)}`,query:{message:e.message},successStatus:204,declaredStatuses:[400,401,404,409],empty:!0},n)},environment:(e,n)=>r({method:"PUT",path:`/api/session/${encodeURIComponent(e.sessionID)}/environment`,body:{variables:e.variables},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),view:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/view`,body:{idle:e.idle},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n)},message:{list:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/message`,query:{limit:e.limit,order:e.order,cursor:e.cursor,type:e.type},successStatus:200,declaredStatuses:[400,401,404,500],empty:!1},n)},model:{list:(e,n)=>r({method:"GET",path:"/api/model",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404,503],empty:!1},n),default:(e,n)=>r({method:"GET",path:"/api/model/default",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404,503],empty:!1},n)},generate:{text:(e,n)=>r({method:"POST",path:"/api/experimental/generate",body:{prompt:e.prompt,model:e.model},successStatus:200,declaredStatuses:[400,401,404,503],empty:!1},n).then((o)=>o.data)},provider:{list:(e,n)=>r({method:"GET",path:"/api/provider",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404,503],empty:!1},n),get:(e,n)=>r({method:"GET",path:`/api/provider/${encodeURIComponent(e.providerID)}`,query:{location:e.location},successStatus:200,declaredStatuses:[400,401,404,503],empty:!1},n)},integration:{list:(e,n)=>r({method:"GET",path:"/api/integration",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),get:(e,n)=>r({method:"GET",path:`/api/integration/${encodeURIComponent(e.integrationID)}`,query:{location:e.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),wellknown:{add:(e,n)=>r({method:"POST",path:"/api/experimental/integration/wellknown",query:{location:e.location},body:{url:e.url},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n)},connect:{key:(e,n)=>r({method:"POST",path:`/api/integration/${encodeURIComponent(e.integrationID)}/connect/key`,query:{location:e.location},body:{key:e.key,answer:e.answer,label:e.label},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n)},oauth:{connect:(e,n)=>r({method:"POST",path:`/api/integration/${encodeURIComponent(e.integrationID)}/connect/oauth`,query:{location:e.location},body:{methodID:e.methodID,answer:e.answer,label:e.label},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),status:(e,n)=>r({method:"GET",path:`/api/integration/${encodeURIComponent(e.integrationID)}/connect/oauth/${encodeURIComponent(e.attemptID)}`,query:{location:e.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),complete:(e,n)=>r({method:"POST",path:`/api/integration/${encodeURIComponent(e.integrationID)}/connect/oauth/${encodeURIComponent(e.attemptID)}/complete`,query:{location:e.location},body:{code:e.code},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),cancel:(e,n)=>r({method:"DELETE",path:`/api/integration/${encodeURIComponent(e.integrationID)}/connect/oauth/${encodeURIComponent(e.attemptID)}`,query:{location:e.location},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n)},command:{connect:(e,n)=>r({method:"POST",path:`/api/integration/${encodeURIComponent(e.integrationID)}/connect/command`,query:{location:e.location},body:{methodID:e.methodID,label:e.label},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),status:(e,n)=>r({method:"GET",path:`/api/integration/${encodeURIComponent(e.integrationID)}/connect/command/${encodeURIComponent(e.attemptID)}`,query:{location:e.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),cancel:(e,n)=>r({method:"DELETE",path:`/api/integration/${encodeURIComponent(e.integrationID)}/connect/command/${encodeURIComponent(e.attemptID)}`,query:{location:e.location},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n)}},mcp:{list:(e,n)=>r({method:"GET",path:"/api/mcp",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),add:(e,n)=>r({method:"PUT",path:`/api/experimental/mcp/${encodeURIComponent(e.server)}`,query:{location:e.location},body:{config:e.config},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),remove:(e,n)=>r({method:"DELETE",path:`/api/experimental/mcp/${encodeURIComponent(e.server)}`,query:{location:e.location},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),connect:(e,n)=>r({method:"POST",path:`/api/experimental/mcp/${encodeURIComponent(e.server)}/connect`,query:{location:e.location},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),disconnect:(e,n)=>r({method:"POST",path:`/api/experimental/mcp/${encodeURIComponent(e.server)}/disconnect`,query:{location:e.location},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),resource:{catalog:(e,n)=>r({method:"GET",path:"/api/mcp/resource",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n)}},credential:{list:(e)=>r({method:"GET",path:"/api/credential",successStatus:200,declaredStatuses:[400,401],empty:!1},e).then((n)=>n.data),create:(e,n)=>r({method:"POST",path:"/api/credential",body:{id:e.id,integrationID:e.integrationID,label:e.label,value:e.value,activate:e.activate},successStatus:200,declaredStatuses:[400,401,409],empty:!1},n).then((o)=>o.data),update:(e,n)=>r({method:"PATCH",path:`/api/credential/${encodeURIComponent(e.credentialID)}`,body:{label:e.label},successStatus:204,declaredStatuses:[400,401],empty:!0},n),activate:(e,n)=>r({method:"POST",path:`/api/credential/${encodeURIComponent(e.credentialID)}/activate`,successStatus:204,declaredStatuses:[400,401],empty:!0},n),remove:(e,n)=>r({method:"DELETE",path:`/api/credential/${encodeURIComponent(e.credentialID)}`,successStatus:204,declaredStatuses:[400,401],empty:!0},n)},project:{list:(e)=>r({method:"GET",path:"/api/project",successStatus:200,declaredStatuses:[400,401,404],empty:!1},e),update:(e,n)=>r({method:"PATCH",path:`/api/project/${encodeURIComponent(e.projectID)}`,body:{canonical:e.canonical,name:e.name,icon:e.icon,commands:e.commands},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n)},form:{list:(e,n)=>r({method:"GET",path:"/api/form",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n)},permission:{request:{list:(e,n)=>r({method:"GET",path:"/api/permission/request",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n)},saved:{list:(e,n)=>r({method:"GET",path:"/api/permission/saved",query:{projectID:e?.projectID},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n).then((o)=>o.data),remove:(e,n)=>r({method:"DELETE",path:`/api/permission/saved/${encodeURIComponent(e.id)}`,successStatus:204,declaredStatuses:[400,401,404],empty:!0},n)},create:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/permission`,body:{id:e.id,action:e.action,resources:e.resources,save:e.save,metadata:e.metadata,source:e.source,agent:e.agent},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n).then((o)=>o.data),list:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/permission`,successStatus:200,declaredStatuses:[400,401,404],empty:!1},n).then((o)=>o.data),get:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/permission/${encodeURIComponent(e.requestID)}`,successStatus:200,declaredStatuses:[400,401,404],empty:!1},n).then((o)=>o.data),reply:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/permission/${encodeURIComponent(e.requestID)}/reply`,body:{decision:e.decision,message:e.message},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n)},file:{read:(e,n)=>r({method:"GET",path:`/api/fs/read/${M(e.path)}`,query:{location:e.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1,binary:!0},n),list:(e,n)=>r({method:"GET",path:"/api/fs/list",query:{location:e?.location,path:e?.path},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),find:(e,n)=>r({method:"GET",path:"/api/fs/find",query:{location:e.location,query:e.query,type:e.type,limit:e.limit},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),write:(e,n)=>r({method:"POST",path:"/api/experimental/fs/write",query:{location:e.location,path:e.path},body:e.payload,successStatus:200,declaredStatuses:[400,401,404],empty:!1,binaryBody:!0},n)},command:{list:(e,n)=>r({method:"GET",path:"/api/command",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n)},skill:{list:(e,n)=>r({method:"GET",path:"/api/skill",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n)},rpc:{call:(e,n)=>r({method:"POST",path:`/api/rpc/${encodeURIComponent(e.rpcID)}/${encodeURIComponent(e.method)}`,query:{location:e.location},body:{input:e.input},successStatus:200,declaredStatuses:[400,401,404,500],empty:!1},n)},event:{subscribe:(e)=>l({method:"GET",path:"/api/event",successStatus:200,declaredStatuses:[400,401],empty:!1},e)},pty:{list:(e,n)=>r({method:"GET",path:"/api/pty",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),create:(e,n)=>r({method:"POST",path:"/api/pty",query:{location:e?.location},body:{command:e?.command,args:e?.args,cwd:e?.cwd,title:e?.title,env:e?.env},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),get:(e,n)=>r({method:"GET",path:`/api/pty/${encodeURIComponent(e.ptyID)}`,query:{location:e.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),update:(e,n)=>r({method:"PUT",path:`/api/pty/${encodeURIComponent(e.ptyID)}`,query:{location:e.location},body:{title:e.title,size:e.size},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),remove:(e,n)=>r({method:"DELETE",path:`/api/pty/${encodeURIComponent(e.ptyID)}`,query:{location:e.location},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),connect:{token:(e,n)=>r({method:"POST",path:`/api/pty/${encodeURIComponent(e.ptyID)}/connect-token`,query:{location:e.location},headers:{"x-opencode-ticket":e["x-opencode-ticket"]},successStatus:200,declaredStatuses:[400,401,403,404],empty:!1},n)}},experimental:{persistentPty:{read:(e,n)=>r({method:"GET",path:`/api/experimental/session/${encodeURIComponent(e.sessionID)}/terminal/read`,query:{lines:e.lines},successStatus:200,declaredStatuses:[400,401,503],empty:!1},n).then((o)=>o.data),list:(e,n)=>r({method:"GET",path:`/api/experimental/session/${encodeURIComponent(e.sessionID)}/terminal`,successStatus:200,declaredStatuses:[400,401,503],empty:!1},n).then((o)=>o.data),create:(e,n)=>r({method:"POST",path:`/api/experimental/session/${encodeURIComponent(e.sessionID)}/terminal`,body:{command:e.command,args:e.args,cwd:e.cwd,title:e.title,env:e.env,size:e.size},successStatus:200,declaredStatuses:[400,401,503],empty:!1},n).then((o)=>o.data),shutdown:(e)=>r({method:"POST",path:"/api/experimental/persistent-pty/shutdown",successStatus:204,declaredStatuses:[400,401,503],empty:!0},e),handoff:(e)=>r({method:"POST",path:"/api/experimental/persistent-pty/handoff",successStatus:200,declaredStatuses:[400,401,503],empty:!1},e),get:(e,n)=>r({method:"GET",path:`/api/experimental/persistent-pty/${encodeURIComponent(e.ptyID)}`,successStatus:200,declaredStatuses:[400,401,404,503],empty:!1},n).then((o)=>o.data),update:(e,n)=>r({method:"PUT",path:`/api/experimental/persistent-pty/${encodeURIComponent(e.ptyID)}`,body:{attachmentID:e.attachmentID,size:e.size},successStatus:200,declaredStatuses:[400,401,404,503],empty:!1},n).then((o)=>o.data),snapshot:(e,n)=>r({method:"GET",path:`/api/experimental/persistent-pty/${encodeURIComponent(e.ptyID)}/snapshot`,successStatus:200,declaredStatuses:[400,401,404,503],empty:!1},n).then((o)=>o.data),remove:(e,n)=>r({method:"DELETE",path:`/api/experimental/persistent-pty/${encodeURIComponent(e.ptyID)}`,successStatus:204,declaredStatuses:[400,401,404,503],empty:!0},n),connectToken:(e,n)=>r({method:"POST",path:`/api/experimental/persistent-pty/${encodeURIComponent(e.ptyID)}/connect-token`,headers:{"x-opencode-ticket":e["x-opencode-ticket"]},successStatus:200,declaredStatuses:[400,401,403,404,503],empty:!1},n).then((o)=>o.data)}},shell:{list:(e,n)=>r({method:"GET",path:"/api/shell",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),create:(e,n)=>r({method:"POST",path:"/api/shell",query:{location:e.location},body:{command:e.command,cwd:e.cwd,timeout:e.timeout,metadata:e.metadata},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),get:(e,n)=>r({method:"GET",path:`/api/shell/${encodeURIComponent(e.id)}`,query:{location:e.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),output:(e,n)=>r({method:"GET",path:`/api/shell/${encodeURIComponent(e.id)}/output`,query:{location:e.location,cursor:e.cursor,limit:e.limit},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),remove:(e,n)=>r({method:"DELETE",path:`/api/shell/${encodeURIComponent(e.id)}`,query:{location:e.location},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n)},reference:{list:(e,n)=>r({method:"GET",path:"/api/reference",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n)},worktree:{list:(e,n)=>r({method:"GET",path:"/api/worktree",query:{projectID:e.projectID},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),create:(e,n)=>r({method:"POST",path:"/api/worktree",body:{projectID:e.projectID,from:e.from,branch:e.branch,directory:e.directory,name:e.name},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),remove:(e,n)=>r({method:"DELETE",path:"/api/worktree",body:{projectID:e.projectID,directory:e.directory,force:e.force},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),refresh:(e,n)=>r({method:"POST",path:"/api/worktree/refresh",body:{projectID:e.projectID},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n)},vcs:{init:(e,n)=>r({method:"POST",path:"/api/vcs/init",query:{location:e?.location,provider:e?.provider},successStatus:204,declaredStatuses:[400,401,404,409,501,503],empty:!0},n),get:(e,n)=>r({method:"GET",path:"/api/vcs",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),base:(e,n)=>r({method:"GET",path:"/api/vcs/base",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404,503],empty:!1},n),status:(e,n)=>r({method:"GET",path:"/api/vcs/status",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),branch:{list:(e,n)=>r({method:"GET",path:"/api/vcs/branch",query:{location:e?.location,search:e?.search,limit:e?.limit},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n)},diff:(e,n)=>r({method:"GET",path:"/api/vcs/diff",query:{location:e.location,mode:e.mode,base:e.base,context:e.context},successStatus:200,declaredStatuses:[400,401,404,503],empty:!1},n)},debug:{location:{list:(e)=>r({method:"GET",path:"/api/debug/location",successStatus:200,declaredStatuses:[400,401],empty:!1},e),evict:(e,n)=>r({method:"DELETE",path:"/api/debug/location",query:{location:e?.location},successStatus:204,declaredStatuses:[400,401],empty:!0},n)}},migration:{v1:{status:(e)=>r({method:"GET",path:"/api/experimental/migration/v1",successStatus:200,declaredStatuses:[400,401],empty:!1},e)}},websearch:{providers:(e,n)=>r({method:"GET",path:"/api/websearch/provider",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404,503],empty:!1},n),query:(e,n)=>r({method:"POST",path:"/api/websearch",query:{location:e.location},body:{query:e.query,providerID:e.providerID},successStatus:200,declaredStatuses:[400,401,404,503],empty:!1},n)},config:{get:(e,n)=>r({method:"GET",path:"/api/config",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),shells:(e)=>r({method:"GET",path:"/api/config/shell",successStatus:200,declaredStatuses:[400,401,404],empty:!1},e),update:(e,n)=>r({method:"PATCH",path:"/api/experimental/config",body:{shell:e.shell},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n)}}}function M(t){return t.split("/").map(encodeURIComponent).join("/")}function h(t,a,s){if(s===void 0)return;if(s===null){t.append(a,"null");return}if(Array.isArray(s)){for(let g of s)h(t,a,g);return}if(typeof s==="object"){for(let[g,p]of Object.entries(s))h(t,`${a}[${g}]`,p);return}t.append(a,String(s))}async function R(t){if(!D(t,"application/json")&&!t.headers.get("content-type")?.includes("+json")){try{await t.body?.cancel()}catch{}throw new c("UnsupportedContentType",{detail:t.headers.get("content-type")})}let a;try{a=await t.text()}catch(s){throw new c("Transport",{cause:s})}if(a==="")throw new c("MalformedResponse");try{return JSON.parse(a)}catch(s){throw new c("MalformedResponse",{cause:s})}}function N(t){let a=Object.assign(Error(t.message??t.data?.message),t);if(t._tag)a.name=t._tag;return a}function D(t,a){return t.headers.get("content-type")?.split(";",1)[0]?.trim().toLowerCase()===a}var _=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="InvalidRequestError",W=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="UnauthorizedError",z=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="LocationNotFoundError",B=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="ServiceUnavailableError",K=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="AgentNotFoundError",H=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="InvalidCursorError",Q=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="SessionNotFoundError",X=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="ConflictError",Y=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="UnknownError",Z=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="MessageNotFoundError",ee=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="CommandNotFoundError",ne=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="CommandExecutionError",te=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="SkillNotFoundError",re=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="SessionBusyError",oe=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="InstructionEntryValueTooLargeError",ae=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="FormNotFoundError",se=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="FormInvalidAnswerError",ie=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="FormAlreadySettledError",de=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="ProviderNotFoundError",le=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="IntegrationNotFoundError",ye=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="IntegrationAttemptNotFoundError",ue=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="IntegrationMethodNotFoundError",pe=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="McpServerNotFoundError",ge=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="ProjectNotFoundError",ce=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="PermissionNotFoundError",me=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="FileNotFoundError",O=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="RpcError",P=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="RpcInternalError",Ie=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="PtyNotFoundError",be=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="ForbiddenError",fe=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="ShellNotFoundError",xe=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="WorktreeError",Se=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="VcsInitNotSupportedError";var S={};w(S,{OpenCode:()=>S,make:()=>V});function T(t){let a,s=4096;function g(r){if(r.connected=void 0,r.controller.abort(),a===r)a=void 0}async function p(r){let l,e={};try{if(r.controller.signal.aborted)return;l=t(r.controller.signal,()=>{r.subscribers.forEach((n)=>n.activity?.())})[Symbol.asyncIterator]();while(!r.controller.signal.aborted){let n=await l.next();if(n.done||r.controller.signal.aborted)break;if(n.value.type==="server.connected")r.connected=n.value;r.subscribers.forEach((o)=>o.push(n.value))}}catch(n){e={error:n}}finally{g(r);try{await l?.return?.()}catch(n){if(!("error"in e))e={error:n}}r.subscribers.forEach((n)=>n.finish(e))}}return{subscribe(r){return{[Symbol.asyncIterator](){let l=[],e=[],n=!1,o,i;function m(u,I=!0){if(o=u,I)e.length=0;if(r?.signal?.removeEventListener("abort",d),i?.subscribers.delete(y)&&!i.subscribers.size)g(i);l.splice(0).forEach((b)=>{if("error"in u)b.reject(u.error);else b.resolve({done:!0,value:void 0})})}function d(){m({})}let y={activity:r?.onActivity,finish(u){m(u,!1)},push(u){if(o)return;let I=l.shift();if(I){I.resolve({done:!1,value:u});return}if(e.length===4096){m({error:Error("Event subscriber exceeded its 4096-event capacity")});return}e.push(u)}};function f(){if(o)return;let u=!a;if(i=a??{controller:new AbortController,subscribers:new Set},a=i,i.subscribers.add(y),i.connected)y.push(i.connected);if(u)p(i)}return{next(){let u=e.shift();if(u)return Promise.resolve({done:!1,value:u});if(o){if("error"in o)return Promise.reject(o.error);return Promise.resolve({done:!0,value:void 0})}if(r?.signal?.aborted)return d(),Promise.resolve({done:!0,value:void 0});let I=Promise.withResolvers();if(l.push(I),!n)n=!0,r?.signal?.addEventListener("abort",d,{once:!0}),f();return I.promise},return(){return m({}),Promise.resolve({done:!0,value:void 0})}}}}}}}function k(t,a){return(s)=>{let g=(p,r)=>{if(!Object.hasOwn(s.events,p))throw Error(`Unknown RPC event: ${s.id}.${p}`);let l=U(s,p);return{[Symbol.asyncIterator](){let e=new AbortController,n=r?.signal?AbortSignal.any([e.signal,r.signal]):e.signal,o=async function*(){try{for await(let i of a.subscribe({signal:n})){if(n.aborted)return;if(i.type!==l)continue;yield i}}catch(i){if(!n.aborted)throw i}finally{e.abort()}}();return{next:()=>o.next(),return:()=>(e.abort(),o.return())}}}};return Object.assign(Object.fromEntries(Object.keys(s.methods).map((p)=>[p,async(r,l)=>{try{return(await t.rpc.call({rpcID:s.id,method:p,input:r,location:l?.location},{signal:l?.signal,headers:l?.headers})).output}catch(e){if(!O(e)&&!P(e))throw e;throw e.data===void 0?{type:e.type,message:e.message}:{type:e.type,message:e.message,data:e.data}}}])),{events:{subscribe:g,on:(p,r,l)=>{let e=new AbortController,n=l?.signal?AbortSignal.any([e.signal,l.signal]):e.signal,o=g(p,{signal:n});return(async()=>{for await(let i of o)await r(i)})().catch((i)=>console.error(i)),()=>e.abort()}}})}}function U(t,a){return`rpc.${t.id}.${a}`}function V(t){let a=F(t),s=T((g,p)=>a.event.subscribe({signal:g,onActivity:p}));return{...a,rpc:Object.assign(k(a,s),a.rpc),event:s}}export{c as ClientError,S as OpenCode,K as isAgentNotFoundError,ne as isCommandExecutionError,ee as isCommandNotFoundError,X as isConflictError,me as isFileNotFoundError,be as isForbiddenError,ie as isFormAlreadySettledError,se as isFormInvalidAnswerError,ae as isFormNotFoundError,oe as isInstructionEntryValueTooLargeError,ye as isIntegrationAttemptNotFoundError,ue as isIntegrationMethodNotFoundError,le as isIntegrationNotFoundError,H as isInvalidCursorError,_ as isInvalidRequestError,z as isLocationNotFoundError,pe as isMcpServerNotFoundError,Z as isMessageNotFoundError,ce as isPermissionNotFoundError,ge as isProjectNotFoundError,de as isProviderNotFoundError,Ie as isPtyNotFoundError,O as isRpcError,P as isRpcInternalError,B as isServiceUnavailableError,re as isSessionBusyError,Q as isSessionNotFoundError,fe as isShellNotFoundError,te as isSkillNotFoundError,W as isUnauthorizedError,Y as isUnknownError,Se as isVcsInitNotSupportedError,xe as isWorktreeError};
12
+ `)}if(y.done)return}}finally{try{await i.cancel()}catch{}i.releaseLock()}}});return{server:{info:(e)=>r({method:"GET",path:"/api/info",successStatus:200,declaredStatuses:[400,401],empty:!1},e),pair:(e)=>r({method:"POST",path:"/api/pair",successStatus:200,declaredStatuses:[400,401],empty:!1},e),connect:(e,n)=>r({method:"GET",path:`/auth/connect/${encodeURIComponent(e.code)}`,successStatus:200,declaredStatuses:[400,401],empty:!1},n)},location:{get:(e,n)=>r({method:"GET",path:"/api/location",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),reload:(e)=>r({method:"POST",path:"/api/location/reload",successStatus:204,declaredStatuses:[400,401,503],empty:!0},e)},agent:{list:(e,n)=>r({method:"GET",path:"/api/agent",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),get:(e,n)=>r({method:"GET",path:`/api/agent/${encodeURIComponent(e.agentID)}`,query:{location:e.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n)},plugin:{list:(e,n)=>r({method:"GET",path:"/api/plugin",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),check:(e,n)=>r({method:"POST",path:"/api/plugin/check",query:{location:e?.location},body:{target:e?.target},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),update:(e,n)=>r({method:"POST",path:"/api/plugin/update",query:{location:e.location},body:{targets:e.targets},successStatus:204,declaredStatuses:[400,401,404,503],empty:!0},n)},session:{list:(e,n)=>r({method:"GET",path:"/api/session",query:{limit:e?.limit,order:e?.order,search:e?.search,parentID:e?.parentID,directory:e?.directory,project:e?.project,subpath:e?.subpath,cursor:e?.cursor},successStatus:200,declaredStatuses:[400,401],empty:!1},n),stats:(e,n)=>r({method:"GET",path:"/api/experimental/session/stats",query:{from:e?.from,to:e?.to,project:e?.project,timezone:e?.timezone,tools:e?.tools},successStatus:200,declaredStatuses:[400,401],empty:!1},n).then((o)=>o.data),create:(e,n)=>r({method:"POST",path:"/api/session",body:{id:e?.id,parentID:e?.parentID,title:e?.title,agent:e?.agent,model:e?.model,location:e?.location,metadata:e?.metadata,permissions:e?.permissions},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n).then((o)=>o.data),import:(e,n)=>r({method:"POST",path:"/api/experimental/session/import",body:{info:e.info,messages:e.messages,location:e.location},successStatus:200,declaredStatuses:[400,401,404,409],empty:!1},n).then((o)=>o.data),export:(e,n)=>r({method:"GET",path:`/api/experimental/session/${encodeURIComponent(e.sessionID)}/export`,query:{sanitize:e.sanitize},successStatus:200,declaredStatuses:[400,401,404,500],empty:!1},n).then((o)=>o.data),active:(e)=>r({method:"GET",path:"/api/session/active",successStatus:200,declaredStatuses:[400,401],empty:!1},e).then((n)=>n.data),get:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}`,successStatus:200,declaredStatuses:[400,401,404],empty:!1},n).then((o)=>o.data),remove:(e,n)=>r({method:"DELETE",path:`/api/session/${encodeURIComponent(e.sessionID)}`,successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),fork:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/fork`,body:{before:e.before},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n).then((o)=>o.data),switchAgent:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/agent`,body:{agent:e.agent},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),switchModel:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/model`,body:{model:e.model},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),update:(e,n)=>r({method:"PATCH",path:`/api/session/${encodeURIComponent(e.sessionID)}`,body:{title:e.title,metadata:e.metadata,permissions:e.permissions},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),move:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/move`,body:{directory:e.directory,delivery:e.delivery},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),prompt:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/prompt`,body:{id:e.id,text:e.text,files:e.files,agents:e.agents,skills:e.skills,metadata:e.metadata,delivery:e.delivery,resume:e.resume},successStatus:200,declaredStatuses:[400,401,404,409],empty:!1},n).then((o)=>o.data),command:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/command`,body:{name:e.name,text:e.text,files:e.files,agents:e.agents,skills:e.skills,delivery:e.delivery},successStatus:204,declaredStatuses:[400,401,404,500],empty:!0},n),skill:(e,n)=>r({method:"POST",path:`/api/experimental/session/${encodeURIComponent(e.sessionID)}/skill`,body:{id:e.id,resume:e.resume},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),synthetic:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/synthetic`,body:{id:e.id,text:e.text,description:e.description,metadata:e.metadata,delivery:e.delivery,resume:e.resume},successStatus:200,declaredStatuses:[400,401,404,409],empty:!1},n).then((o)=>o.data),shell:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/shell`,body:{id:e.id,command:e.command},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),compact:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/compact`,body:{id:e.id,delivery:e.delivery},successStatus:200,declaredStatuses:[400,401,404,409],empty:!1},n).then((o)=>o.data),wait:(e,n)=>r({method:"POST",path:`/api/experimental/session/${encodeURIComponent(e.sessionID)}/wait`,successStatus:204,declaredStatuses:[400,401,404,503],empty:!0},n),revert:{stage:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/revert/stage`,body:{messageID:e.messageID,files:e.files},successStatus:200,declaredStatuses:[400,401,404,409,500],empty:!1},n).then((o)=>o.data),clear:(e,n)=>r({method:"DELETE",path:`/api/session/${encodeURIComponent(e.sessionID)}/revert`,successStatus:204,declaredStatuses:[400,401,404,409,500],empty:!0},n),commit:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/revert/commit`,successStatus:204,declaredStatuses:[400,401,404,409],empty:!0},n)},context:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/context`,successStatus:200,declaredStatuses:[400,401,404,500],empty:!1},n).then((o)=>o.data),diff:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/diff`,query:{from:e.from,to:e.to,context:e.context},successStatus:200,declaredStatuses:[400,401,404,500],empty:!1},n).then((o)=>o.data),inbox:{list:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/inbox`,successStatus:200,declaredStatuses:[400,401,404],empty:!1},n).then((o)=>o.data),cancel:(e,n)=>r({method:"DELETE",path:`/api/session/${encodeURIComponent(e.sessionID)}/inbox/${encodeURIComponent(e.inboxID)}`,successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),update:(e,n)=>r({method:"PATCH",path:`/api/session/${encodeURIComponent(e.sessionID)}/inbox/${encodeURIComponent(e.inboxID)}`,body:{delivery:e.delivery},successStatus:204,declaredStatuses:[400,401,404,409],empty:!0},n)},instructions:{entry:{list:(e,n)=>r({method:"GET",path:`/api/experimental/session/${encodeURIComponent(e.sessionID)}/instructions/entries`,successStatus:200,declaredStatuses:[400,401,404],empty:!1},n).then((o)=>o.data),put:(e,n)=>r({method:"PUT",path:`/api/experimental/session/${encodeURIComponent(e.sessionID)}/instructions/entries/${encodeURIComponent(e.key)}`,body:{value:e.value},successStatus:204,declaredStatuses:[400,401,404,413],empty:!0},n),remove:(e,n)=>r({method:"DELETE",path:`/api/experimental/session/${encodeURIComponent(e.sessionID)}/instructions/entries/${encodeURIComponent(e.key)}`,successStatus:204,declaredStatuses:[400,401,404],empty:!0},n)}},generate:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/generate`,body:{prompt:e.prompt},successStatus:200,declaredStatuses:[400,401,404,503],empty:!1},n).then((o)=>o.data),log:(e,n)=>l({method:"GET",path:`/api/experimental/session/${encodeURIComponent(e.sessionID)}/log`,query:{after:e.after,follow:e.follow},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),interrupt:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/interrupt`,query:{resume:e.resume},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),background:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/background`,successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),message:{get:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/message/${encodeURIComponent(e.messageID)}`,successStatus:200,declaredStatuses:[400,401,404],empty:!1},n).then((o)=>o.data)},form:{list:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/form`,successStatus:200,declaredStatuses:[400,401,404],empty:!1},n).then((o)=>o.data),create:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/form`,body:{id:e.id,title:e.title,metadata:e.metadata,fields:e.fields},successStatus:200,declaredStatuses:[400,401,404,409],empty:!1},n).then((o)=>o.data),get:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/form/${encodeURIComponent(e.formID)}`,successStatus:200,declaredStatuses:[400,401,404],empty:!1},n).then((o)=>o.data),reply:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/form/${encodeURIComponent(e.formID)}/reply`,body:{answer:e.answer},successStatus:204,declaredStatuses:[400,401,404,409],empty:!0},n),cancel:(e,n)=>r({method:"DELETE",path:`/api/session/${encodeURIComponent(e.sessionID)}/form/${encodeURIComponent(e.formID)}`,query:{message:e.message},successStatus:204,declaredStatuses:[400,401,404,409],empty:!0},n)},environment:(e,n)=>r({method:"PUT",path:`/api/session/${encodeURIComponent(e.sessionID)}/environment`,body:{variables:e.variables},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),view:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/view`,body:{idle:e.idle},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n)},message:{list:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/message`,query:{limit:e.limit,order:e.order,cursor:e.cursor,type:e.type},successStatus:200,declaredStatuses:[400,401,404,500],empty:!1},n)},model:{list:(e,n)=>r({method:"GET",path:"/api/model",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404,503],empty:!1},n),default:(e,n)=>r({method:"GET",path:"/api/model/default",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404,503],empty:!1},n)},generate:{text:(e,n)=>r({method:"POST",path:"/api/experimental/generate",body:{prompt:e.prompt,model:e.model},successStatus:200,declaredStatuses:[400,401,404,503],empty:!1},n).then((o)=>o.data)},provider:{list:(e,n)=>r({method:"GET",path:"/api/provider",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404,503],empty:!1},n),get:(e,n)=>r({method:"GET",path:`/api/provider/${encodeURIComponent(e.providerID)}`,query:{location:e.location},successStatus:200,declaredStatuses:[400,401,404,503],empty:!1},n)},integration:{list:(e,n)=>r({method:"GET",path:"/api/integration",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),get:(e,n)=>r({method:"GET",path:`/api/integration/${encodeURIComponent(e.integrationID)}`,query:{location:e.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),wellknown:{add:(e,n)=>r({method:"POST",path:"/api/experimental/integration/wellknown",query:{location:e.location},body:{url:e.url},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n)},connect:{key:(e,n)=>r({method:"POST",path:`/api/integration/${encodeURIComponent(e.integrationID)}/connect/key`,query:{location:e.location},body:{key:e.key,answer:e.answer,label:e.label},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),external:(e,n)=>r({method:"POST",path:`/api/integration/${encodeURIComponent(e.integrationID)}/connect/external`,query:{location:e.location},body:{methodID:e.methodID,answer:e.answer,label:e.label},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n)},oauth:{connect:(e,n)=>r({method:"POST",path:`/api/integration/${encodeURIComponent(e.integrationID)}/connect/oauth`,query:{location:e.location},body:{methodID:e.methodID,answer:e.answer,label:e.label},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),status:(e,n)=>r({method:"GET",path:`/api/integration/${encodeURIComponent(e.integrationID)}/connect/oauth/${encodeURIComponent(e.attemptID)}`,query:{location:e.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),complete:(e,n)=>r({method:"POST",path:`/api/integration/${encodeURIComponent(e.integrationID)}/connect/oauth/${encodeURIComponent(e.attemptID)}/complete`,query:{location:e.location},body:{code:e.code},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),cancel:(e,n)=>r({method:"DELETE",path:`/api/integration/${encodeURIComponent(e.integrationID)}/connect/oauth/${encodeURIComponent(e.attemptID)}`,query:{location:e.location},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n)},command:{connect:(e,n)=>r({method:"POST",path:`/api/integration/${encodeURIComponent(e.integrationID)}/connect/command`,query:{location:e.location},body:{methodID:e.methodID,label:e.label},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),status:(e,n)=>r({method:"GET",path:`/api/integration/${encodeURIComponent(e.integrationID)}/connect/command/${encodeURIComponent(e.attemptID)}`,query:{location:e.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),cancel:(e,n)=>r({method:"DELETE",path:`/api/integration/${encodeURIComponent(e.integrationID)}/connect/command/${encodeURIComponent(e.attemptID)}`,query:{location:e.location},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n)}},mcp:{list:(e,n)=>r({method:"GET",path:"/api/mcp",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),add:(e,n)=>r({method:"PUT",path:`/api/experimental/mcp/${encodeURIComponent(e.server)}`,query:{location:e.location},body:{config:e.config},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),remove:(e,n)=>r({method:"DELETE",path:`/api/experimental/mcp/${encodeURIComponent(e.server)}`,query:{location:e.location},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),connect:(e,n)=>r({method:"POST",path:`/api/experimental/mcp/${encodeURIComponent(e.server)}/connect`,query:{location:e.location},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),disconnect:(e,n)=>r({method:"POST",path:`/api/experimental/mcp/${encodeURIComponent(e.server)}/disconnect`,query:{location:e.location},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),resource:{catalog:(e,n)=>r({method:"GET",path:"/api/mcp/resource",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n)}},credential:{list:(e)=>r({method:"GET",path:"/api/credential",successStatus:200,declaredStatuses:[400,401],empty:!1},e).then((n)=>n.data),create:(e,n)=>r({method:"POST",path:"/api/credential",body:{id:e.id,integrationID:e.integrationID,label:e.label,value:e.value,activate:e.activate},successStatus:200,declaredStatuses:[400,401,409],empty:!1},n).then((o)=>o.data),update:(e,n)=>r({method:"PATCH",path:`/api/credential/${encodeURIComponent(e.credentialID)}`,body:{label:e.label},successStatus:204,declaredStatuses:[400,401],empty:!0},n),activate:(e,n)=>r({method:"POST",path:`/api/credential/${encodeURIComponent(e.credentialID)}/activate`,successStatus:204,declaredStatuses:[400,401],empty:!0},n),remove:(e,n)=>r({method:"DELETE",path:`/api/credential/${encodeURIComponent(e.credentialID)}`,successStatus:204,declaredStatuses:[400,401],empty:!0},n)},project:{list:(e)=>r({method:"GET",path:"/api/project",successStatus:200,declaredStatuses:[400,401,404],empty:!1},e),update:(e,n)=>r({method:"PATCH",path:`/api/project/${encodeURIComponent(e.projectID)}`,body:{canonical:e.canonical,name:e.name,icon:e.icon,commands:e.commands},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n)},form:{list:(e,n)=>r({method:"GET",path:"/api/form",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n)},permission:{request:{list:(e,n)=>r({method:"GET",path:"/api/permission/request",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n)},saved:{list:(e,n)=>r({method:"GET",path:"/api/permission/saved",query:{projectID:e?.projectID},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n).then((o)=>o.data),remove:(e,n)=>r({method:"DELETE",path:`/api/permission/saved/${encodeURIComponent(e.id)}`,successStatus:204,declaredStatuses:[400,401,404],empty:!0},n)},create:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/permission`,body:{id:e.id,action:e.action,resources:e.resources,save:e.save,metadata:e.metadata,source:e.source,agent:e.agent},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n).then((o)=>o.data),list:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/permission`,successStatus:200,declaredStatuses:[400,401,404],empty:!1},n).then((o)=>o.data),get:(e,n)=>r({method:"GET",path:`/api/session/${encodeURIComponent(e.sessionID)}/permission/${encodeURIComponent(e.requestID)}`,successStatus:200,declaredStatuses:[400,401,404],empty:!1},n).then((o)=>o.data),reply:(e,n)=>r({method:"POST",path:`/api/session/${encodeURIComponent(e.sessionID)}/permission/${encodeURIComponent(e.requestID)}/reply`,body:{decision:e.decision,message:e.message},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n)},file:{read:(e,n)=>r({method:"GET",path:`/api/fs/read/${M(e.path)}`,query:{location:e.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1,binary:!0},n),list:(e,n)=>r({method:"GET",path:"/api/fs/list",query:{location:e?.location,path:e?.path},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),find:(e,n)=>r({method:"GET",path:"/api/fs/find",query:{location:e.location,query:e.query,type:e.type,limit:e.limit},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),write:(e,n)=>r({method:"POST",path:"/api/experimental/fs/write",query:{location:e.location,path:e.path},body:e.payload,successStatus:200,declaredStatuses:[400,401,404],empty:!1,binaryBody:!0},n)},command:{list:(e,n)=>r({method:"GET",path:"/api/command",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n)},skill:{list:(e,n)=>r({method:"GET",path:"/api/skill",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n)},rpc:{call:(e,n)=>r({method:"POST",path:`/api/rpc/${encodeURIComponent(e.rpcID)}/${encodeURIComponent(e.method)}`,query:{location:e.location},body:{input:e.input},successStatus:200,declaredStatuses:[400,401,404,500],empty:!1},n)},event:{subscribe:(e)=>l({method:"GET",path:"/api/event",successStatus:200,declaredStatuses:[400,401],empty:!1},e)},pty:{list:(e,n)=>r({method:"GET",path:"/api/pty",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),create:(e,n)=>r({method:"POST",path:"/api/pty",query:{location:e?.location},body:{command:e?.command,args:e?.args,cwd:e?.cwd,title:e?.title,env:e?.env},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),get:(e,n)=>r({method:"GET",path:`/api/pty/${encodeURIComponent(e.ptyID)}`,query:{location:e.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),update:(e,n)=>r({method:"PUT",path:`/api/pty/${encodeURIComponent(e.ptyID)}`,query:{location:e.location},body:{title:e.title,size:e.size},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),remove:(e,n)=>r({method:"DELETE",path:`/api/pty/${encodeURIComponent(e.ptyID)}`,query:{location:e.location},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),connect:{token:(e,n)=>r({method:"POST",path:`/api/pty/${encodeURIComponent(e.ptyID)}/connect-token`,query:{location:e.location},headers:{"x-opencode-ticket":e["x-opencode-ticket"]},successStatus:200,declaredStatuses:[400,401,403,404],empty:!1},n)}},experimental:{persistentPty:{read:(e,n)=>r({method:"GET",path:`/api/experimental/session/${encodeURIComponent(e.sessionID)}/terminal/read`,query:{lines:e.lines},successStatus:200,declaredStatuses:[400,401,503],empty:!1},n).then((o)=>o.data),list:(e,n)=>r({method:"GET",path:`/api/experimental/session/${encodeURIComponent(e.sessionID)}/terminal`,successStatus:200,declaredStatuses:[400,401,503],empty:!1},n).then((o)=>o.data),create:(e,n)=>r({method:"POST",path:`/api/experimental/session/${encodeURIComponent(e.sessionID)}/terminal`,body:{command:e.command,args:e.args,cwd:e.cwd,title:e.title,env:e.env,size:e.size},successStatus:200,declaredStatuses:[400,401,503],empty:!1},n).then((o)=>o.data),shutdown:(e)=>r({method:"POST",path:"/api/experimental/persistent-pty/shutdown",successStatus:204,declaredStatuses:[400,401,503],empty:!0},e),handoff:(e)=>r({method:"POST",path:"/api/experimental/persistent-pty/handoff",successStatus:200,declaredStatuses:[400,401,503],empty:!1},e),get:(e,n)=>r({method:"GET",path:`/api/experimental/persistent-pty/${encodeURIComponent(e.ptyID)}`,successStatus:200,declaredStatuses:[400,401,404,503],empty:!1},n).then((o)=>o.data),update:(e,n)=>r({method:"PUT",path:`/api/experimental/persistent-pty/${encodeURIComponent(e.ptyID)}`,body:{attachmentID:e.attachmentID,size:e.size},successStatus:200,declaredStatuses:[400,401,404,503],empty:!1},n).then((o)=>o.data),snapshot:(e,n)=>r({method:"GET",path:`/api/experimental/persistent-pty/${encodeURIComponent(e.ptyID)}/snapshot`,successStatus:200,declaredStatuses:[400,401,404,503],empty:!1},n).then((o)=>o.data),remove:(e,n)=>r({method:"DELETE",path:`/api/experimental/persistent-pty/${encodeURIComponent(e.ptyID)}`,successStatus:204,declaredStatuses:[400,401,404,503],empty:!0},n),connectToken:(e,n)=>r({method:"POST",path:`/api/experimental/persistent-pty/${encodeURIComponent(e.ptyID)}/connect-token`,headers:{"x-opencode-ticket":e["x-opencode-ticket"]},successStatus:200,declaredStatuses:[400,401,403,404,503],empty:!1},n).then((o)=>o.data)}},shell:{list:(e,n)=>r({method:"GET",path:"/api/shell",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),create:(e,n)=>r({method:"POST",path:"/api/shell",query:{location:e.location},body:{command:e.command,cwd:e.cwd,timeout:e.timeout,metadata:e.metadata},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),get:(e,n)=>r({method:"GET",path:`/api/shell/${encodeURIComponent(e.id)}`,query:{location:e.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),output:(e,n)=>r({method:"GET",path:`/api/shell/${encodeURIComponent(e.id)}/output`,query:{location:e.location,cursor:e.cursor,limit:e.limit},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),remove:(e,n)=>r({method:"DELETE",path:`/api/shell/${encodeURIComponent(e.id)}`,query:{location:e.location},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n)},reference:{list:(e,n)=>r({method:"GET",path:"/api/reference",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n)},worktree:{list:(e,n)=>r({method:"GET",path:"/api/worktree",query:{projectID:e.projectID},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),create:(e,n)=>r({method:"POST",path:"/api/worktree",body:{projectID:e.projectID,from:e.from,branch:e.branch,directory:e.directory,name:e.name},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),remove:(e,n)=>r({method:"DELETE",path:"/api/worktree",body:{projectID:e.projectID,directory:e.directory,force:e.force},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n),refresh:(e,n)=>r({method:"POST",path:"/api/worktree/refresh",body:{projectID:e.projectID},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n)},vcs:{init:(e,n)=>r({method:"POST",path:"/api/vcs/init",query:{location:e?.location,provider:e?.provider},successStatus:204,declaredStatuses:[400,401,404,409,501,503],empty:!0},n),get:(e,n)=>r({method:"GET",path:"/api/vcs",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),base:(e,n)=>r({method:"GET",path:"/api/vcs/base",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404,503],empty:!1},n),status:(e,n)=>r({method:"GET",path:"/api/vcs/status",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),branch:{list:(e,n)=>r({method:"GET",path:"/api/vcs/branch",query:{location:e?.location,search:e?.search,limit:e?.limit},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n)},diff:(e,n)=>r({method:"GET",path:"/api/vcs/diff",query:{location:e.location,mode:e.mode,base:e.base,context:e.context},successStatus:200,declaredStatuses:[400,401,404,503],empty:!1},n)},debug:{location:{list:(e)=>r({method:"GET",path:"/api/debug/location",successStatus:200,declaredStatuses:[400,401],empty:!1},e),evict:(e,n)=>r({method:"DELETE",path:"/api/debug/location",query:{location:e?.location},successStatus:204,declaredStatuses:[400,401],empty:!0},n)}},migration:{v1:{status:(e)=>r({method:"GET",path:"/api/experimental/migration/v1",successStatus:200,declaredStatuses:[400,401],empty:!1},e)}},websearch:{providers:(e,n)=>r({method:"GET",path:"/api/websearch/provider",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404,503],empty:!1},n),query:(e,n)=>r({method:"POST",path:"/api/websearch",query:{location:e.location},body:{query:e.query,providerID:e.providerID},successStatus:200,declaredStatuses:[400,401,404,503],empty:!1},n)},config:{get:(e,n)=>r({method:"GET",path:"/api/config",query:{location:e?.location},successStatus:200,declaredStatuses:[400,401,404],empty:!1},n),shells:(e)=>r({method:"GET",path:"/api/config/shell",successStatus:200,declaredStatuses:[400,401,404],empty:!1},e),update:(e,n)=>r({method:"PATCH",path:"/api/experimental/config",body:{shell:e.shell},successStatus:204,declaredStatuses:[400,401,404],empty:!0},n)}}}function M(t){return t.split("/").map(encodeURIComponent).join("/")}function h(t,a,s){if(s===void 0)return;if(s===null){t.append(a,"null");return}if(Array.isArray(s)){for(let g of s)h(t,a,g);return}if(typeof s==="object"){for(let[g,p]of Object.entries(s))h(t,`${a}[${g}]`,p);return}t.append(a,String(s))}async function R(t){if(!D(t,"application/json")&&!t.headers.get("content-type")?.includes("+json")){try{await t.body?.cancel()}catch{}throw new c("UnsupportedContentType",{detail:t.headers.get("content-type")})}let a;try{a=await t.text()}catch(s){throw new c("Transport",{cause:s})}if(a==="")throw new c("MalformedResponse");try{return JSON.parse(a)}catch(s){throw new c("MalformedResponse",{cause:s})}}function N(t){let a=Object.assign(Error(t.message??t.data?.message),t);if(t._tag)a.name=t._tag;return a}function D(t,a){return t.headers.get("content-type")?.split(";",1)[0]?.trim().toLowerCase()===a}var _=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="InvalidRequestError",W=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="UnauthorizedError",z=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="LocationNotFoundError",B=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="ServiceUnavailableError",K=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="AgentNotFoundError",H=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="InvalidCursorError",Q=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="SessionNotFoundError",X=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="ConflictError",Y=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="UnknownError",Z=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="MessageNotFoundError",ee=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="CommandNotFoundError",ne=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="CommandExecutionError",te=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="SkillNotFoundError",re=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="SessionBusyError",oe=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="InstructionEntryValueTooLargeError",ae=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="FormNotFoundError",se=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="FormInvalidAnswerError",ie=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="FormAlreadySettledError",de=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="ProviderNotFoundError",le=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="IntegrationNotFoundError",ye=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="IntegrationAttemptNotFoundError",ue=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="IntegrationMethodNotFoundError",pe=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="McpServerNotFoundError",ge=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="ProjectNotFoundError",ce=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="PermissionNotFoundError",me=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="FileNotFoundError",O=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="RpcError",P=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="RpcInternalError",Ie=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="PtyNotFoundError",be=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="ForbiddenError",fe=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="ShellNotFoundError",xe=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="WorktreeError",Se=(t)=>typeof t==="object"&&t!==null&&("_tag"in t)&&t._tag==="VcsInitNotSupportedError";var S={};w(S,{OpenCode:()=>S,make:()=>V});function T(t){let a,s=4096;function g(r){if(r.connected=void 0,r.controller.abort(),a===r)a=void 0}async function p(r){let l,e={};try{if(r.controller.signal.aborted)return;l=t(r.controller.signal,()=>{r.subscribers.forEach((n)=>n.activity?.())})[Symbol.asyncIterator]();while(!r.controller.signal.aborted){let n=await l.next();if(n.done||r.controller.signal.aborted)break;if(n.value.type==="server.connected")r.connected=n.value;r.subscribers.forEach((o)=>o.push(n.value))}}catch(n){e={error:n}}finally{g(r);try{await l?.return?.()}catch(n){if(!("error"in e))e={error:n}}r.subscribers.forEach((n)=>n.finish(e))}}return{subscribe(r){return{[Symbol.asyncIterator](){let l=[],e=[],n=!1,o,i;function m(u,I=!0){if(o=u,I)e.length=0;if(r?.signal?.removeEventListener("abort",d),i?.subscribers.delete(y)&&!i.subscribers.size)g(i);l.splice(0).forEach((b)=>{if("error"in u)b.reject(u.error);else b.resolve({done:!0,value:void 0})})}function d(){m({})}let y={activity:r?.onActivity,finish(u){m(u,!1)},push(u){if(o)return;let I=l.shift();if(I){I.resolve({done:!1,value:u});return}if(e.length===4096){m({error:Error("Event subscriber exceeded its 4096-event capacity")});return}e.push(u)}};function f(){if(o)return;let u=!a;if(i=a??{controller:new AbortController,subscribers:new Set},a=i,i.subscribers.add(y),i.connected)y.push(i.connected);if(u)p(i)}return{next(){let u=e.shift();if(u)return Promise.resolve({done:!1,value:u});if(o){if("error"in o)return Promise.reject(o.error);return Promise.resolve({done:!0,value:void 0})}if(r?.signal?.aborted)return d(),Promise.resolve({done:!0,value:void 0});let I=Promise.withResolvers();if(l.push(I),!n)n=!0,r?.signal?.addEventListener("abort",d,{once:!0}),f();return I.promise},return(){return m({}),Promise.resolve({done:!0,value:void 0})}}}}}}}function k(t,a){return(s)=>{let g=(p,r)=>{if(!Object.hasOwn(s.events,p))throw Error(`Unknown RPC event: ${s.id}.${p}`);let l=U(s,p);return{[Symbol.asyncIterator](){let e=new AbortController,n=r?.signal?AbortSignal.any([e.signal,r.signal]):e.signal,o=async function*(){try{for await(let i of a.subscribe({signal:n})){if(n.aborted)return;if(i.type!==l)continue;yield i}}catch(i){if(!n.aborted)throw i}finally{e.abort()}}();return{next:()=>o.next(),return:()=>(e.abort(),o.return())}}}};return Object.assign(Object.fromEntries(Object.keys(s.methods).map((p)=>[p,async(r,l)=>{try{return(await t.rpc.call({rpcID:s.id,method:p,input:r,location:l?.location},{signal:l?.signal,headers:l?.headers})).output}catch(e){if(!O(e)&&!P(e))throw e;throw e.data===void 0?{type:e.type,message:e.message}:{type:e.type,message:e.message,data:e.data}}}])),{events:{subscribe:g,on:(p,r,l)=>{let e=new AbortController,n=l?.signal?AbortSignal.any([e.signal,l.signal]):e.signal,o=g(p,{signal:n});return(async()=>{for await(let i of o)await r(i)})().catch((i)=>console.error(i)),()=>e.abort()}}})}}function U(t,a){return`rpc.${t.id}.${a}`}function V(t){let a=F(t),s=T((g,p)=>a.event.subscribe({signal:g,onActivity:p}));return{...a,rpc:Object.assign(k(a,s),a.rpc),event:s}}export{c as ClientError,S as OpenCode,K as isAgentNotFoundError,ne as isCommandExecutionError,ee as isCommandNotFoundError,X as isConflictError,me as isFileNotFoundError,be as isForbiddenError,ie as isFormAlreadySettledError,se as isFormInvalidAnswerError,ae as isFormNotFoundError,oe as isInstructionEntryValueTooLargeError,ye as isIntegrationAttemptNotFoundError,ue as isIntegrationMethodNotFoundError,le as isIntegrationNotFoundError,H as isInvalidCursorError,_ as isInvalidRequestError,z as isLocationNotFoundError,pe as isMcpServerNotFoundError,Z as isMessageNotFoundError,ce as isPermissionNotFoundError,ge as isProjectNotFoundError,de as isProviderNotFoundError,Ie as isPtyNotFoundError,O as isRpcError,P as isRpcInternalError,B as isServiceUnavailableError,re as isSessionBusyError,Q as isSessionNotFoundError,fe as isShellNotFoundError,te as isSkillNotFoundError,W as isUnauthorizedError,Y as isUnknownError,Se as isVcsInitNotSupportedError,xe as isWorktreeError};
@@ -1,5 +1,7 @@
1
1
  import type { DiscoverOptions, Endpoint, EnsureOptions, StopOptions } from "../service.js";
2
+ import { headers } from "../service-probe.js";
2
3
  export * from "../service.js";
4
+ export { headers };
3
5
  /** Discover a healthy, compatible local service without starting one. */
4
6
  export declare function discover(options?: DiscoverOptions): Promise<{
5
7
  url: string;
@@ -13,10 +15,6 @@ export declare function discover(options?: DiscoverOptions): Promise<{
13
15
  export declare function ensure(options?: EnsureOptions): Promise<Endpoint>;
14
16
  /** Stop the registered local service. */
15
17
  export declare function stop(options?: StopOptions): Promise<void>;
16
- /** Create HTTP authentication headers for a service endpoint. */
17
- export declare function headers(endpoint: Endpoint): {
18
- authorization: string;
19
- } | undefined;
20
18
  /** Promise-based local service lifecycle operations. */
21
19
  export declare const Service: {
22
20
  discover: typeof discover;
package/client/service.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import { readFile, rm } from "node:fs/promises";
2
- import { homedir } from "node:os";
3
- import { join } from "node:path";
4
- import { contenderFailure, contenderFinished, spawnServiceContender, } from "../service-contender.js";
2
+ import { contenderPool, spawnServiceContender } from "../service-contender.js";
5
3
  import { defaultEnsureTiming, ensureTiming } from "../service-timing.js";
6
4
  import { matchesVersion } from "../service-version.js";
7
5
  import { PtyHandoff } from "../pty-handoff.js";
6
+ import { decide, fallback, headers, probeResult, same } from "../service-probe.js";
8
7
  export * from "../service.js";
8
+ export { headers };
9
9
  // Find, start, and stop the local opencode background service.
10
10
  //
11
11
  // The registration file is the complete discovery contract. This module is
@@ -26,12 +26,9 @@ export async function discover(options = {}) {
26
26
  export async function ensure(options = {}) {
27
27
  const timing = ensureTiming(options);
28
28
  const deadline = Date.now() + timing.promiseTimeout;
29
- const contenders = new Set();
29
+ const pool = contenderPool(timing);
30
30
  let timeouts;
31
31
  let announced = false;
32
- let lastSpawn = 0;
33
- let spawnDelay = timing.spawnDelay;
34
- let failure;
35
32
  const announce = (reason, previousVersion) => {
36
33
  if (announced)
37
34
  return;
@@ -52,7 +49,7 @@ export async function ensure(options = {}) {
52
49
  try {
53
50
  while (true) {
54
51
  if (Date.now() >= deadline)
55
- throw failure ?? new Error("Timed out waiting for the background service to start");
52
+ throw pool.failure() ?? new Error("Timed out waiting for the background service to start");
56
53
  const registration = await registered(options.file, timing.requestTimeout);
57
54
  if (registration.timedOut && registration.info !== undefined) {
58
55
  timeouts = {
@@ -64,74 +61,45 @@ export async function ensure(options = {}) {
64
61
  console.warn("Background service is unresponsive; recovery cannot preserve persistent terminals");
65
62
  await PtyHandoff.clear(options.file ?? fallback());
66
63
  await terminate(registration.info, options, timing);
67
- for (const item of contenders) {
68
- if (item.child.pid === registration.info.pid || contenderFinished(item)) {
69
- item.release();
70
- contenders.delete(item);
71
- }
72
- }
73
- failure = undefined;
64
+ pool.evict(registration.info.pid);
65
+ pool.recruitNow();
74
66
  timeouts = undefined;
75
- lastSpawn = Date.now() - spawnDelay;
76
67
  }
77
68
  }
78
69
  else
79
70
  timeouts = undefined;
80
71
  if (registration.service !== undefined) {
81
- spawnDelay = timing.spawnDelay;
72
+ pool.serviceAnswered();
82
73
  const service = registration.service;
83
- const versionMatches = matchesVersion(service.version, options);
84
- const compatible = service.compatible && versionMatches;
85
- if (!service.compatible && versionMatches)
86
- throw new Error("Background service uses an incompatible health protocol. Update this client or explicitly restart the service.");
87
- if (compatible && service.state === "ready") {
74
+ const decision = decide(service, options);
75
+ if (decision._tag === "fail")
76
+ throw decision.error;
77
+ if (decision._tag === "reuse") {
88
78
  await PtyHandoff.complete(options.file ?? fallback(), service.info);
89
79
  return service.endpoint;
90
80
  }
91
- if (compatible && service.state === "failed")
92
- throw new Error("Background service failed to start");
93
- if (!compatible) {
81
+ if (decision._tag === "replace") {
94
82
  announce("version-mismatch", service.version);
95
83
  if (service.state !== "ready")
96
84
  console.warn("Background service is not ready; replacement cannot preserve persistent terminals");
97
- await stop({
98
- file: options.file,
99
- pty: service.state === "ready" ? "handoff" : "clear",
100
- }).catch(() => undefined);
101
- for (const item of contenders) {
102
- if (item.child.pid === service.info.pid || contenderFinished(item)) {
103
- item.release();
104
- contenders.delete(item);
105
- }
106
- }
107
- failure = undefined;
108
- lastSpawn = 0;
85
+ await stop({ file: options.file, pty: decision.pty }).catch(() => undefined);
86
+ pool.evict(service.info.pid);
109
87
  }
110
88
  }
111
89
  else {
112
- if (lastSpawn === 0 && registration.info !== undefined)
113
- lastSpawn = Date.now();
114
- const finished = [...contenders].filter(contenderFinished);
115
- failure ??= finished.map(contenderFailure).find((error) => error !== undefined);
116
- if (finished.some((item) => item.child.exitCode === 0)) {
117
- spawnDelay = Math.min(spawnDelay * 2, timing.maxSpawnDelay);
118
- }
119
- finished.forEach((item) => contenders.delete(item));
120
- if (failure !== undefined && contenders.size === 0)
121
- throw failure;
122
- // Keep one candidate plus one lock probe for pre-lock stalls. After a failure, let the
123
- // survivors finish without recruiting replacements that could hide the error indefinitely.
124
- if (failure === undefined && contenders.size < 2 && Date.now() - lastSpawn >= spawnDelay) {
90
+ const failed = pool.reap();
91
+ if (failed !== undefined)
92
+ throw failed;
93
+ if (pool.shouldRecruit(registration.info !== undefined)) {
125
94
  announce("missing");
126
- contenders.add(await spawnContender());
127
- lastSpawn = Date.now();
95
+ pool.add(await spawnContender());
128
96
  }
129
97
  }
130
98
  await delay(timing.pollInterval);
131
99
  }
132
100
  }
133
101
  finally {
134
- contenders.forEach((contender) => contender.release());
102
+ pool.releaseAll();
135
103
  }
136
104
  }
137
105
  /** Stop the registered local service. */
@@ -144,17 +112,6 @@ export async function stop(options = {}) {
144
112
  if (info !== undefined)
145
113
  await terminate(info, options, ensureTiming(options));
146
114
  }
147
- function fallback() {
148
- return join(process.env["XDG_STATE_HOME"] ?? join(homedir(), ".local", "state"), "shuvcode", "service.json");
149
- }
150
- /** Create HTTP authentication headers for a service endpoint. */
151
- export function headers(endpoint) {
152
- if (endpoint.auth === undefined)
153
- return undefined;
154
- return {
155
- authorization: "Basic " + Buffer.from(endpoint.auth.username + ":" + endpoint.auth.password).toString("base64"),
156
- };
157
- }
158
115
  async function read(file) {
159
116
  const text = await readFile(file ?? fallback(), "utf8").catch(() => undefined);
160
117
  if (text === undefined)
@@ -166,64 +123,6 @@ async function read(file) {
166
123
  return undefined;
167
124
  }
168
125
  }
169
- async function probeResult(info, timeout = defaultEnsureTiming.requestTimeout) {
170
- const endpoint = {
171
- url: info.url,
172
- auth: info.password === undefined
173
- ? undefined
174
- : { type: "basic", username: "opencode", password: info.password },
175
- };
176
- const signal = AbortSignal.timeout(timeout);
177
- const result = await fetch(new URL("/api/info", info.url), { headers: headers(endpoint), signal })
178
- .then(async (response) => ({
179
- response,
180
- body: response.status === 404 ? undefined : (await response.json()),
181
- }))
182
- .then((value) => ({ value }), (cause) => ({ cause }));
183
- if ("cause" in result)
184
- return { service: undefined, timedOut: signal.aborted };
185
- const response = result.value.response;
186
- // A missing health endpoint identifies protocol incompatibility, not an older
187
- // version. Only an unmet version requirement lets ensure replace this owner.
188
- if (response.status === 404)
189
- return {
190
- service: {
191
- info,
192
- endpoint,
193
- version: info.version,
194
- state: "ready",
195
- compatible: false,
196
- },
197
- timedOut: false,
198
- };
199
- const serverInfo = decodeInfo(result.value.body);
200
- if (serverInfo !== undefined) {
201
- if (serverInfo.pid !== info.pid)
202
- return { service: undefined, timedOut: false };
203
- if (info.version !== undefined && serverInfo.version !== info.version)
204
- return { service: undefined, timedOut: false };
205
- return {
206
- service: {
207
- info,
208
- endpoint,
209
- version: serverInfo.version,
210
- state: response.ok ? "ready" : response.status === 500 ? "failed" : "waiting",
211
- compatible: true,
212
- },
213
- timedOut: false,
214
- };
215
- }
216
- return { service: undefined, timedOut: false };
217
- }
218
- function decodeInfo(input) {
219
- if (typeof input !== "object" || input === null)
220
- return;
221
- if (!("version" in input) || typeof input.version !== "string")
222
- return;
223
- if (!("pid" in input) || typeof input.pid !== "number" || !Number.isInteger(input.pid) || input.pid < 0)
224
- return;
225
- return { version: input.version, pid: input.pid };
226
- }
227
126
  async function registered(file, timeout) {
228
127
  const info = await read(file);
229
128
  if (info === undefined)
@@ -254,9 +153,6 @@ async function waitUntilStopped(pid, timing) {
254
153
  }
255
154
  return false;
256
155
  }
257
- function same(left, right) {
258
- return left.id === right.id && left.version === right.version && left.url === right.url && left.pid === right.pid;
259
- }
260
156
  async function terminate(info, options, timing) {
261
157
  const current = await read(options.file);
262
158
  if (current === undefined || !same(current, info))
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "import": "./client/index.js"
15
15
  }
16
16
  },
17
- "version": "2.0.23-shuv.1",
17
+ "version": "2.0.25-shuv.1",
18
18
  "license": "MIT",
19
19
  "repository": {
20
20
  "type": "git",
@@ -30,17 +30,17 @@
30
30
  "x64"
31
31
  ],
32
32
  "optionalDependencies": {
33
- "shuvcode-windows-x64": "2.0.23-shuv.1",
34
- "shuvcode-linux-arm64-musl": "2.0.23-shuv.1",
35
- "shuvcode-linux-x64-baseline-musl": "2.0.23-shuv.1",
36
- "shuvcode-darwin-arm64": "2.0.23-shuv.1",
37
- "shuvcode-linux-x64-musl": "2.0.23-shuv.1",
38
- "shuvcode-darwin-x64": "2.0.23-shuv.1",
39
- "shuvcode-linux-x64-baseline": "2.0.23-shuv.1",
40
- "shuvcode-windows-arm64": "2.0.23-shuv.1",
41
- "shuvcode-linux-arm64": "2.0.23-shuv.1",
42
- "shuvcode-darwin-x64-baseline": "2.0.23-shuv.1",
43
- "shuvcode-windows-x64-baseline": "2.0.23-shuv.1",
44
- "shuvcode-linux-x64": "2.0.23-shuv.1"
33
+ "shuvcode-windows-x64": "2.0.25-shuv.1",
34
+ "shuvcode-linux-arm64-musl": "2.0.25-shuv.1",
35
+ "shuvcode-linux-x64-baseline-musl": "2.0.25-shuv.1",
36
+ "shuvcode-darwin-arm64": "2.0.25-shuv.1",
37
+ "shuvcode-linux-x64-musl": "2.0.25-shuv.1",
38
+ "shuvcode-darwin-x64": "2.0.25-shuv.1",
39
+ "shuvcode-linux-x64-baseline": "2.0.25-shuv.1",
40
+ "shuvcode-windows-arm64": "2.0.25-shuv.1",
41
+ "shuvcode-linux-arm64": "2.0.25-shuv.1",
42
+ "shuvcode-darwin-x64-baseline": "2.0.25-shuv.1",
43
+ "shuvcode-windows-x64-baseline": "2.0.25-shuv.1",
44
+ "shuvcode-linux-x64": "2.0.25-shuv.1"
45
45
  }
46
46
  }