@flowy-agent-store/client 0.1.0-beta.7 → 0.1.0-beta.9

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/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { AgentDetail, AgentRunInput, AgentSummary, AnswerDecisionInput, CancelRunInput, ClientCapabilities, ClientInfo, ConnectorCallResult, ConnectorDetail, ConnectorProbeResult, ConnectorStatusView, ConnectorSummary, ContextUsage, ConversationCreateInput, ConversationEvent, ConversationMessage, ConversationMessagesPage, ConversationMessagesQuery, ConversationModelOptions, ConversationSendReceipt, ConversationUpdateInput, ConversationView, ExpertPack, ImportDetail, ImportRequest, ImportResult, ImportSummary, InitializeResult, InstallOutcome, InstallRequest, InstallResult, InstallStatus, MarketplaceAddRequest, MarketplaceDetail, MarketplaceRefreshResult, MarketplaceRemoveResult, MarketplaceSummary, MentionRef, ModelSummary, OAuthStartResult, OAuthStatusView, ProviderWithModel, RunEvent, RunEventsQuery, RunPlan, RunReceipt, RunResult, RunStatus, RunView, ServerNotification, SkillDetail, SkillFileContent, SkillFileList, SkillSummary, SteerRunInput, StoreInstallResult, StoreItem, StoreItemKind, StoreList, TeamDetail, TeamRunInput, TeamRunReceipt, TeamSummary, WorkspaceRevokeResult, WorkspaceView } from "@flowy-agent-store/protocol";
1
+ import { AgentDetail, AgentRunInput, AgentSummary, AnswerDecisionInput, CancelRunInput, ClientCapabilities, ClientInfo, ConnectorCallResult, ConnectorCredential, ConnectorDetail, ConnectorProbeResult, ConnectorRegistration, ConnectorStatusView, ConnectorSummary, ContextUsage, ConversationCreateInput, ConversationEvent, ConversationMessage, ConversationMessagesPage, ConversationMessagesQuery, ConversationModelOptions, ConversationSendReceipt, ConversationUpdateInput, ConversationView, ExpertPack, ImportDetail, ImportRequest, ImportResult, ImportSummary, InitializeResult, InstallOutcome, InstallRequest, InstallResult, InstallStatus, MarketSettings, MarketSettingsPatch, MarketplaceAddRequest, MarketplaceDetail, MarketplaceRefreshResult, MarketplaceRemoveResult, MarketplaceSummary, MentionRef, ModelSummary, OAuthStartResult, OAuthStatusView, ProviderWithModel, RunEvent, RunEventsQuery, RunPlan, RunReceipt, RunResult, RunStatus, RunView, ServerNotification, SkillDetail, SkillFileContent, SkillFileList, SkillSummary, SteerRunInput, StoreInstallResult, StoreItem, StoreItemKind, StoreList, TeamDetail, TeamRunInput, TeamRunReceipt, TeamSummary, WorkspaceRevokeResult, WorkspaceView } from "@flowy-agent-store/protocol";
2
2
  //#region src/transport.d.ts
3
3
  export type NotificationListener = (notification: ServerNotification) => void;
4
4
  /**
@@ -374,6 +374,28 @@ export declare class ConversationSubscription {
374
374
  }
375
375
  //#endregion
376
376
  //#region src/connectors.d.ts
377
+ export interface WaitForAuthOptions {
378
+ /** Overall budget in ms; defaults to `DEFAULT_AUTH_TIMEOUT_MS` (120s). */
379
+ timeoutMs?: number;
380
+ /** Poll interval in ms; defaults to 500. The read is a local DB projection. */
381
+ pollMs?: number;
382
+ }
383
+ /**
384
+ * How a completed wait ended.
385
+ *
386
+ * `error` carries the host's own sentence. It is the shape of every failure that
387
+ * happens *after* `authStart` acknowledged the browser step — the state stays
388
+ * `not_authenticated` (there is no "failed" state on the wire), so the reason is
389
+ * the only signal there is.
390
+ */
391
+ export type WaitForAuthOutcome = {
392
+ state: "authenticated";
393
+ } | {
394
+ state: "error";
395
+ error: string;
396
+ } | {
397
+ state: "timeout";
398
+ };
377
399
  export declare class ConnectorClient {
378
400
  private readonly transport;
379
401
  constructor(transport: Transport);
@@ -397,13 +419,86 @@ export declare class ConnectorClient {
397
419
  * the last segment of its wire method.
398
420
  */
399
421
  test(connectorId: string): Promise<ConnectorProbeResult>;
400
- /** Check the current OAuth state for a connector. */
422
+ /**
423
+ * Check the current OAuth state for a connector.
424
+ *
425
+ * Read `error` too: a flow that failed after the browser step is reported as
426
+ * `state: "not_authenticated"` **plus** `error`, because the wire has no
427
+ * failing state to flip to. {@link waitForAuth} is the loop that does this.
428
+ */
401
429
  authStatus(connectorId: string): Promise<OAuthStatusView>;
430
+ /**
431
+ * The credential form a connector needs filled in, as **this caller** sees it
432
+ * (doc `34` §6.1).
433
+ *
434
+ * `mode` says which kind of authentication applies (`none` / `oauth` / `token`),
435
+ * `status` whether anything is still missing, and `missing` names the keys.
436
+ * `fields` is everything needed to render the form — labels, placeholders,
437
+ * descriptions and the marketplace's "where do I get a key" link, in both
438
+ * languages. No secret ever comes back: only `plain` fields carry a `value`.
439
+ */
440
+ credentials(connectorId: string): Promise<ConnectorCredential>;
441
+ /**
442
+ * Store what the user typed and get the new state back.
443
+ *
444
+ * Only keys the connector's own declaration names are accepted — the form is
445
+ * the whole write surface. `secret` fields go to the host's credential store
446
+ * under the caller's own namespace, `plain` fields into the connector's
447
+ * configuration, so a shared host never resolves one user's token for another.
448
+ */
449
+ setCredentials(connectorId: string, values: Record<string, string>): Promise<ConnectorCredential>;
450
+ /**
451
+ * Forget stored credentials. `keys` omitted = every secret field of this
452
+ * connector. Idempotent: clearing what is not there succeeds.
453
+ */
454
+ clearCredentials(connectorId: string, keys?: string[]): Promise<ConnectorCredential>;
455
+ /**
456
+ * Register a connector this host never imported — your own MCP server, handed
457
+ * over together with the template that says what it needs (doc `34` §6.5).
458
+ *
459
+ * The **template is the whole declaration**: whatever `${secret:NAME}` the URL,
460
+ * headers or env name becomes that connector's credential form, so there is no
461
+ * `token-schema.json` to ship and nothing to install from a marketplace. The
462
+ * connector's own non-secret settings travel in `values`.
463
+ *
464
+ * Secrets do **not** travel here: hand them over with {@link setCredentials},
465
+ * which keeps exactly one write surface for values. The returned detail already
466
+ * carries the credential block, so `missing` tells you which keys are still
467
+ * needed.
468
+ *
469
+ * Re-registering the same name updates it; a builtin server's name is refused.
470
+ * The row is created **disabled** — enabling it still requires a probe that
471
+ * passes — and this method is on the installation-owner-only surface, because
472
+ * choosing where the host reaches is the owner's call.
473
+ */
474
+ register(registration: ConnectorRegistration): Promise<ConnectorDetail>;
402
475
  /**
403
476
  * Kick off the OAuth browser flow on the trusted host. Returns the start
404
- * acknowledgement immediately; poll `authStatus` until `authenticated`.
477
+ * acknowledgement immediately; follow it with {@link waitForAuth}.
478
+ *
479
+ * `state: "error"` here is a failure that happened **before** the browser was
480
+ * opened (endpoint discovery, client identity, binding the callback, launching
481
+ * the browser): nothing was shown to the user, so `error` is the whole story
482
+ * and there is nothing to wait for.
405
483
  */
406
484
  authStart(connectorId: string): Promise<OAuthStartResult>;
485
+ /**
486
+ * Wait for an authorization that was started (in the browser, or by a
487
+ * previous `authStart`) to finish — and **report why** when it does not.
488
+ *
489
+ * A hand-rolled `while (state !== "authenticated") poll()` loop ends in "it
490
+ * never became authenticated", with the reason sitting unread in the status it
491
+ * already fetched: a token exchange the authorization server refused (a
492
+ * throttling gateway answers `slow_down`), a callback timeout, a CSRF/path
493
+ * mismatch. Those land in `authStatus().error` *only*, and the state stays
494
+ * `not_authenticated` — there is no failing state on the wire.
495
+ *
496
+ * Resolves for every domain outcome (`authenticated` / `error` / `timeout`);
497
+ * rejects only when the status read itself fails (transport or protocol), the
498
+ * same rule as `connector/call`. The wait is bounded by `timeoutMs`; a caller
499
+ * that needs to stop earlier can race the returned promise.
500
+ */
501
+ waitForAuth(connectorId: string, options?: WaitForAuthOptions): Promise<WaitForAuthOutcome>;
407
502
  /** Revoke the OAuth token for a connector. */
408
503
  logout(connectorId: string): Promise<void>;
409
504
  /**
@@ -621,6 +716,20 @@ export interface StoreClientOptions {
621
716
  /** First readiness poll interval in ms; doubles up to `readyPollMaxMs`. */
622
717
  readyPollMs?: number;
623
718
  readyPollMaxMs?: number;
719
+ /**
720
+ * Minimum gap between two *real probes* of the same connector while waiting
721
+ * for readiness, in ms. Defaults to `DEFAULT_READY_PROBE_MS`.
722
+ *
723
+ * A connector's readiness cannot be read: the status is derived from the last
724
+ * probe, so someone has to run one — but a probe is a real connection
725
+ * (`initialize` + `tools/list`) that also resolves the stored token, which
726
+ * means a refresh request when that token is near expiry, plus one more on a
727
+ * 401. Probing once per poll (the poll starts at `readyPollMs` = 400ms) turned
728
+ * a 30s readiness budget into ~10 connections and up to ~20 token requests
729
+ * against the connector's authorization server — with nobody having asked for
730
+ * anything. Between probes the loop reads the (free, local) status instead.
731
+ */
732
+ readyProbeMs?: number;
624
733
  }
625
734
  export interface StoreOperationOutcome {
626
735
  /** The snapshot the operation acted on; `null` when nothing was imported. */
@@ -634,6 +743,18 @@ export interface StoreOperationOutcome {
634
743
  components: InstallOutcome[];
635
744
  /** Every reported component reached the requested state. */
636
745
  ok: boolean;
746
+ /**
747
+ * The server's own failure lines, verbatim.
748
+ *
749
+ * `ok: false` alone is not an answer: the host explains *why* (a digest
750
+ * conflict means the market changed content without raising the version; a
751
+ * `preset_update_failed` names the component). Dropping these is what made a
752
+ * refused import unexplainable in the UI (`18` §11 D10), so they are carried
753
+ * rather than folded into `ok`.
754
+ */
755
+ errors: string[];
756
+ /** The server's non-fatal notes, verbatim (e.g. a component left disabled). */
757
+ warnings: string[];
637
758
  /**
638
759
  * `undefined` when readiness was not checked. `true` when every component is
639
760
  * usable now; `false` when it is not (see `readyIssue`).
@@ -642,6 +763,16 @@ export interface StoreOperationOutcome {
642
763
  readyIssue?: StoreReadyIssue;
643
764
  /** The component that needs attention, when `readyIssue` is set. */
644
765
  readyComponentId?: string;
766
+ /** `update()` only: the version that was installed before this call. */
767
+ fromVersion?: string;
768
+ /** `update()` only: the version now installed. */
769
+ toVersion?: string;
770
+ /**
771
+ * `update()` only: how many components of the replaced snapshot were actually
772
+ * released. `0` means the previous installation was not touched — an update
773
+ * that failed, or a no-op.
774
+ */
775
+ releasedCount?: number;
645
776
  }
646
777
  /**
647
778
  * The slice of `AppServerClient` this layer orchestrates.
@@ -653,6 +784,7 @@ export interface StoreOperationOutcome {
653
784
  export interface StoreHost {
654
785
  listStore(): Promise<StoreList>;
655
786
  installStoreEntry(marketplaceId: string, entryName: string): Promise<StoreInstallResult>;
787
+ updateStoreEntry(marketplaceId: string, entryName: string): Promise<StoreInstallResult>;
656
788
  getInstallStatus(snapshotId: string): Promise<InstallStatus>;
657
789
  disableInstall(snapshotId: string, componentIds: string[]): Promise<InstallStatus>;
658
790
  enableInstall(snapshotId: string, componentIds: string[]): Promise<InstallStatus>;
@@ -676,6 +808,7 @@ export declare class StoreClient {
676
808
  private readonly readyTimeoutMs;
677
809
  private readonly readyPollMs;
678
810
  private readonly readyPollMaxMs;
811
+ private readonly readyProbeMs;
679
812
  constructor(host: StoreHost, options?: StoreClientOptions);
680
813
  /** Every item across enabled marketplaces, with install state. */
681
814
  list(): Promise<StoreItem[]>;
@@ -696,13 +829,25 @@ export declare class StoreClient {
696
829
  /**
697
830
  * What a caller can offer for an item's pending update.
698
831
  *
699
- * `"none"` means there is nothing to do; `"uninstall_reinstall"` means the
700
- * entry is installed at a different version and the only path the wire offers
701
- * is to release it and install again (the version-aware re-import then picks
702
- * up the current version). `"unknown"` is returned rather than guessing when
703
- * the item carries no snapshot to release.
832
+ * `"none"` means there is nothing to do; `"update"` means the entry is
833
+ * installed at a different version and `update()` is the action that lands it
834
+ * (`store/update-entry`, `36` D3); `"unknown"` is returned rather than
835
+ * guessing when the item carries no snapshot to replace.
704
836
  */
705
- updateHint(item: StoreItem): "none" | "uninstall_reinstall" | "unknown";
837
+ updateHint(item: StoreItem): "none" | "update" | "unknown";
838
+ /**
839
+ * Upgrade an installed item to the version its marketplace advertises.
840
+ *
841
+ * The host does the ordering: new version installed first, previous one
842
+ * released only when that succeeded. So a failure resolves `ok: false` with
843
+ * the previous installation still in place (`releasedCount === 0`) — the
844
+ * caller never has to reason about a half-upgraded item.
845
+ *
846
+ * Refuses before the round trip when there is nothing to replace: an item that
847
+ * is not installed (`not_installed`) or is already current is not a failure of
848
+ * *this* call, and `updateHint()` is the way to ask first.
849
+ */
850
+ update(item: StoreItem, options?: InstallOptions): Promise<StoreOperationOutcome>;
706
851
  /**
707
852
  * Import (when needed) and install one store item, then wait until it is
708
853
  * usable.
@@ -744,6 +889,10 @@ export declare class StoreClient {
744
889
  * unknown kind is reported ready rather than blocking: this layer cannot judge
745
890
  * a component it does not understand, and a false timeout on a future kind
746
891
  * would be worse than passing it through.
892
+ *
893
+ * `allowProbe` gates the one kind whose readiness needs a real connection (a
894
+ * connector); the other kinds answer from local reads, so the cadence does not
895
+ * apply to them.
747
896
  */
748
897
  private readiness;
749
898
  }
@@ -886,10 +1035,34 @@ export declare class AppServerClient {
886
1035
  refreshMarketplace(marketplaceId: string): Promise<MarketplaceRefreshResult>;
887
1036
  /** Import one discovered marketplace entry (provenance linked). */
888
1037
  importMarketplaceEntry(marketplaceId: string, entryName: string): Promise<ImportResult>;
1038
+ /**
1039
+ * The host's market policy: sweep cadence, auto-upgrade kind whitelist and the
1040
+ * last sweep's reading (doc `37` §3.2).
1041
+ *
1042
+ * Host-level rather than per-market: it answers "when does the sweep run and
1043
+ * what may it touch", while {@link setMarketplaceAutoUpdate} answers "which
1044
+ * market participates".
1045
+ */
1046
+ getMarketSettings(): Promise<MarketSettings>;
1047
+ /**
1048
+ * Update the host's market policy. An absent field is left alone; the host
1049
+ * writes the value into its `config.toml` and answers with the file re-read,
1050
+ * so a caller can never see an optimistic echo.
1051
+ */
1052
+ setMarketSettings(patch: MarketSettingsPatch): Promise<MarketSettings>;
889
1053
  /** All store items across enabled marketplaces (display + install state). */
890
1054
  listStore(): Promise<StoreList>;
891
1055
  /** One-click install: import (when missing) + register in one call. */
892
1056
  installStoreEntry(marketplaceId: string, entryName: string): Promise<StoreInstallResult>;
1057
+ /**
1058
+ * Upgrade an installed entry to the version its marketplace advertises.
1059
+ *
1060
+ * The host installs the new version before releasing the old one, so a failure
1061
+ * leaves the previous installation usable (`released_count: 0` is the machine
1062
+ * readable form of that). Refused for an entry that is not installed — this is
1063
+ * never a second way to install something.
1064
+ */
1065
+ updateStoreEntry(marketplaceId: string, entryName: string): Promise<StoreInstallResult>;
893
1066
  }
894
1067
  //#endregion
895
1068
  //#region src/conversation-handle.d.ts
package/dist/index.mjs CHANGED
@@ -275,7 +275,7 @@ var WebSocketTransport = class {
275
275
  /** Header the server mints the per-call connection id under. */
276
276
  const CONNECTION_HEADER = "x-app-server-connection-id";
277
277
  /** Protocol version this binding announces on the one-shot handshake. */
278
- const PROTOCOL_VERSION = "fp-8";
278
+ const PROTOCOL_VERSION = "fp-13";
279
279
  /**
280
280
  * Protocol method → REST route. Verified from handler bodies, not from the
281
281
  * route list (a route existing does not prove which method it mirrors).
@@ -470,6 +470,26 @@ const HTTP_ROUTES = {
470
470
  path: "/connectors/:connector_id/auth-logout",
471
471
  source: "connector_auth_logout_route() -> connector_auth_logout_impl"
472
472
  },
473
+ "connector/credential/get": {
474
+ verb: "GET",
475
+ path: "/connectors/:connector_id/credential",
476
+ source: "connector_credential_get_route() -> connector_credential_get_impl"
477
+ },
478
+ "connector/credential/set": {
479
+ verb: "POST",
480
+ path: "/connectors/:connector_id/credential",
481
+ source: "connector_credential_set_route() -> connector_credential_set_impl"
482
+ },
483
+ "connector/credential/clear": {
484
+ verb: "POST",
485
+ path: "/connectors/:connector_id/credential/clear",
486
+ source: "connector_credential_clear_route() -> connector_credential_clear_impl"
487
+ },
488
+ "connector/register": {
489
+ verb: "POST",
490
+ path: "/connectors",
491
+ source: "register_connector_route() -> register_connector_impl"
492
+ },
473
493
  "import/run": {
474
494
  verb: "POST",
475
495
  path: "/imports",
@@ -550,6 +570,17 @@ const HTTP_ROUTES = {
550
570
  path: "/markets/:marketplace_id/entries/:entry_name/import",
551
571
  source: "market_entry_import_route() -> market_entry_import_impl"
552
572
  },
573
+ "market/settings": {
574
+ verb: "GET",
575
+ path: "/market-settings",
576
+ source: "market_settings_route() -> market_settings_impl"
577
+ },
578
+ "market/settings-set": {
579
+ verb: "POST",
580
+ path: "/market-settings",
581
+ body: ["auto_update_interval_hours", "entry_auto_update_kinds"],
582
+ source: "market_settings_set_route() -> market_settings_set_impl"
583
+ },
553
584
  "store/list": {
554
585
  verb: "GET",
555
586
  path: "/store",
@@ -559,6 +590,11 @@ const HTTP_ROUTES = {
559
590
  verb: "POST",
560
591
  path: "/store/:marketplace_id/entries/:entry_name/install",
561
592
  source: "store_install_entry_route() -> store_install_entry_impl"
593
+ },
594
+ "store/update-entry": {
595
+ verb: "POST",
596
+ path: "/store/:marketplace_id/entries/:entry_name/update",
597
+ source: "store_update_entry_route() -> store_update_entry_impl"
562
598
  }
563
599
  };
564
600
  /** Methods that are WebSocket-only by design — named so the error explains itself. */
@@ -1079,6 +1115,13 @@ var ConversationSubscription = class {
1079
1115
  };
1080
1116
  //#endregion
1081
1117
  //#region src/connectors.ts
1118
+ /**
1119
+ * How long {@link ConnectorClient.waitForAuth} waits by default: the host's own
1120
+ * callback window is 120s, so a shorter client budget would give up on flows the
1121
+ * host is still willing to finish.
1122
+ */
1123
+ const DEFAULT_AUTH_TIMEOUT_MS = 12e4;
1124
+ const DEFAULT_AUTH_POLL_MS = 500;
1082
1125
  var ConnectorClient = class {
1083
1126
  transport;
1084
1127
  constructor(transport) {
@@ -1112,17 +1155,117 @@ var ConnectorClient = class {
1112
1155
  test(connectorId) {
1113
1156
  return this.transport.request("connector/test", { connector_id: connectorId });
1114
1157
  }
1115
- /** Check the current OAuth state for a connector. */
1158
+ /**
1159
+ * Check the current OAuth state for a connector.
1160
+ *
1161
+ * Read `error` too: a flow that failed after the browser step is reported as
1162
+ * `state: "not_authenticated"` **plus** `error`, because the wire has no
1163
+ * failing state to flip to. {@link waitForAuth} is the loop that does this.
1164
+ */
1116
1165
  authStatus(connectorId) {
1117
1166
  return this.transport.request("connector/auth/status", { connector_id: connectorId });
1118
1167
  }
1119
1168
  /**
1169
+ * The credential form a connector needs filled in, as **this caller** sees it
1170
+ * (doc `34` §6.1).
1171
+ *
1172
+ * `mode` says which kind of authentication applies (`none` / `oauth` / `token`),
1173
+ * `status` whether anything is still missing, and `missing` names the keys.
1174
+ * `fields` is everything needed to render the form — labels, placeholders,
1175
+ * descriptions and the marketplace's "where do I get a key" link, in both
1176
+ * languages. No secret ever comes back: only `plain` fields carry a `value`.
1177
+ */
1178
+ credentials(connectorId) {
1179
+ return this.transport.request("connector/credential/get", { connector_id: connectorId });
1180
+ }
1181
+ /**
1182
+ * Store what the user typed and get the new state back.
1183
+ *
1184
+ * Only keys the connector's own declaration names are accepted — the form is
1185
+ * the whole write surface. `secret` fields go to the host's credential store
1186
+ * under the caller's own namespace, `plain` fields into the connector's
1187
+ * configuration, so a shared host never resolves one user's token for another.
1188
+ */
1189
+ setCredentials(connectorId, values) {
1190
+ return this.transport.request("connector/credential/set", {
1191
+ connector_id: connectorId,
1192
+ values
1193
+ });
1194
+ }
1195
+ /**
1196
+ * Forget stored credentials. `keys` omitted = every secret field of this
1197
+ * connector. Idempotent: clearing what is not there succeeds.
1198
+ */
1199
+ clearCredentials(connectorId, keys) {
1200
+ return this.transport.request("connector/credential/clear", {
1201
+ connector_id: connectorId,
1202
+ ...keys ? { keys } : {}
1203
+ });
1204
+ }
1205
+ /**
1206
+ * Register a connector this host never imported — your own MCP server, handed
1207
+ * over together with the template that says what it needs (doc `34` §6.5).
1208
+ *
1209
+ * The **template is the whole declaration**: whatever `${secret:NAME}` the URL,
1210
+ * headers or env name becomes that connector's credential form, so there is no
1211
+ * `token-schema.json` to ship and nothing to install from a marketplace. The
1212
+ * connector's own non-secret settings travel in `values`.
1213
+ *
1214
+ * Secrets do **not** travel here: hand them over with {@link setCredentials},
1215
+ * which keeps exactly one write surface for values. The returned detail already
1216
+ * carries the credential block, so `missing` tells you which keys are still
1217
+ * needed.
1218
+ *
1219
+ * Re-registering the same name updates it; a builtin server's name is refused.
1220
+ * The row is created **disabled** — enabling it still requires a probe that
1221
+ * passes — and this method is on the installation-owner-only surface, because
1222
+ * choosing where the host reaches is the owner's call.
1223
+ */
1224
+ register(registration) {
1225
+ return this.transport.request("connector/register", registration);
1226
+ }
1227
+ /**
1120
1228
  * Kick off the OAuth browser flow on the trusted host. Returns the start
1121
- * acknowledgement immediately; poll `authStatus` until `authenticated`.
1229
+ * acknowledgement immediately; follow it with {@link waitForAuth}.
1230
+ *
1231
+ * `state: "error"` here is a failure that happened **before** the browser was
1232
+ * opened (endpoint discovery, client identity, binding the callback, launching
1233
+ * the browser): nothing was shown to the user, so `error` is the whole story
1234
+ * and there is nothing to wait for.
1122
1235
  */
1123
1236
  authStart(connectorId) {
1124
1237
  return this.transport.request("connector/auth/start", { connector_id: connectorId });
1125
1238
  }
1239
+ /**
1240
+ * Wait for an authorization that was started (in the browser, or by a
1241
+ * previous `authStart`) to finish — and **report why** when it does not.
1242
+ *
1243
+ * A hand-rolled `while (state !== "authenticated") poll()` loop ends in "it
1244
+ * never became authenticated", with the reason sitting unread in the status it
1245
+ * already fetched: a token exchange the authorization server refused (a
1246
+ * throttling gateway answers `slow_down`), a callback timeout, a CSRF/path
1247
+ * mismatch. Those land in `authStatus().error` *only*, and the state stays
1248
+ * `not_authenticated` — there is no failing state on the wire.
1249
+ *
1250
+ * Resolves for every domain outcome (`authenticated` / `error` / `timeout`);
1251
+ * rejects only when the status read itself fails (transport or protocol), the
1252
+ * same rule as `connector/call`. The wait is bounded by `timeoutMs`; a caller
1253
+ * that needs to stop earlier can race the returned promise.
1254
+ */
1255
+ async waitForAuth(connectorId, options = {}) {
1256
+ const deadline = Date.now() + (options.timeoutMs ?? DEFAULT_AUTH_TIMEOUT_MS);
1257
+ const pollMs = options.pollMs ?? DEFAULT_AUTH_POLL_MS;
1258
+ for (;;) {
1259
+ const status = await this.authStatus(connectorId);
1260
+ if (status.state === "authenticated") return { state: "authenticated" };
1261
+ if (status.error) return {
1262
+ state: "error",
1263
+ error: status.error
1264
+ };
1265
+ if (Date.now() >= deadline) return { state: "timeout" };
1266
+ await new Promise((resolve) => setTimeout(resolve, pollMs));
1267
+ }
1268
+ }
1126
1269
  /** Revoke the OAuth token for a connector. */
1127
1270
  logout(connectorId) {
1128
1271
  return this.transport.request("connector/auth/logout", { connector_id: connectorId }).then(() => void 0);
@@ -1542,6 +1685,7 @@ var StoreError = class extends Error {
1542
1685
  const DEFAULT_READY_TIMEOUT_MS = 3e4;
1543
1686
  const DEFAULT_READY_POLL_MS = 400;
1544
1687
  const DEFAULT_READY_POLL_MAX_MS = 4e3;
1688
+ const DEFAULT_READY_PROBE_MS = 5e3;
1545
1689
  /** Every string a `LocalizedText` carries, for haystack building. */
1546
1690
  function localizedValues(text) {
1547
1691
  if (typeof text === "string") return [text];
@@ -1583,11 +1727,13 @@ var StoreClient = class {
1583
1727
  readyTimeoutMs;
1584
1728
  readyPollMs;
1585
1729
  readyPollMaxMs;
1730
+ readyProbeMs;
1586
1731
  constructor(host, options = {}) {
1587
1732
  this.host = host;
1588
1733
  this.readyTimeoutMs = options.readyTimeoutMs ?? DEFAULT_READY_TIMEOUT_MS;
1589
1734
  this.readyPollMs = options.readyPollMs ?? DEFAULT_READY_POLL_MS;
1590
1735
  this.readyPollMaxMs = options.readyPollMaxMs ?? DEFAULT_READY_POLL_MAX_MS;
1736
+ this.readyProbeMs = options.readyProbeMs ?? DEFAULT_READY_PROBE_MS;
1591
1737
  }
1592
1738
  /** Every item across enabled marketplaces, with install state. */
1593
1739
  async list() {
@@ -1619,15 +1765,45 @@ var StoreClient = class {
1619
1765
  /**
1620
1766
  * What a caller can offer for an item's pending update.
1621
1767
  *
1622
- * `"none"` means there is nothing to do; `"uninstall_reinstall"` means the
1623
- * entry is installed at a different version and the only path the wire offers
1624
- * is to release it and install again (the version-aware re-import then picks
1625
- * up the current version). `"unknown"` is returned rather than guessing when
1626
- * the item carries no snapshot to release.
1768
+ * `"none"` means there is nothing to do; `"update"` means the entry is
1769
+ * installed at a different version and `update()` is the action that lands it
1770
+ * (`store/update-entry`, `36` D3); `"unknown"` is returned rather than
1771
+ * guessing when the item carries no snapshot to replace.
1627
1772
  */
1628
1773
  updateHint(item) {
1629
1774
  if (!item.installed || !item.update_available) return "none";
1630
- return item.snapshot_id ? "uninstall_reinstall" : "unknown";
1775
+ return item.snapshot_id ? "update" : "unknown";
1776
+ }
1777
+ /**
1778
+ * Upgrade an installed item to the version its marketplace advertises.
1779
+ *
1780
+ * The host does the ordering: new version installed first, previous one
1781
+ * released only when that succeeded. So a failure resolves `ok: false` with
1782
+ * the previous installation still in place (`releasedCount === 0`) — the
1783
+ * caller never has to reason about a half-upgraded item.
1784
+ *
1785
+ * Refuses before the round trip when there is nothing to replace: an item that
1786
+ * is not installed (`not_installed`) or is already current is not a failure of
1787
+ * *this* call, and `updateHint()` is the way to ask first.
1788
+ */
1789
+ async update(item, options = {}) {
1790
+ this.assertUsable(item, options.signal);
1791
+ this.requireSnapshot(item);
1792
+ const result = await this.host.updateStoreEntry(item.marketplace_id, item.entry_name);
1793
+ const components = result.outcomes ?? [];
1794
+ const outcome = {
1795
+ snapshotId: result.snapshot_id,
1796
+ reused: result.reused,
1797
+ components,
1798
+ ok: result.errors.length === 0 && components.every((component) => component.ok),
1799
+ errors: result.errors,
1800
+ warnings: result.warnings,
1801
+ fromVersion: result.previous_version ?? void 0,
1802
+ toVersion: result.version,
1803
+ releasedCount: result.released_count ?? 0
1804
+ };
1805
+ if (options.waitForReady === false) return outcome;
1806
+ return this.awaitReady(outcome, options);
1631
1807
  }
1632
1808
  /**
1633
1809
  * Import (when needed) and install one store item, then wait until it is
@@ -1641,7 +1817,9 @@ var StoreClient = class {
1641
1817
  snapshotId: result.snapshot_id,
1642
1818
  reused: result.reused,
1643
1819
  components,
1644
- ok: result.errors.length === 0 && components.every((component) => component.ok)
1820
+ ok: result.errors.length === 0 && components.every((component) => component.ok),
1821
+ errors: result.errors,
1822
+ warnings: result.warnings
1645
1823
  };
1646
1824
  if (options.waitForReady === false) return outcome;
1647
1825
  return this.awaitReady(outcome, options);
@@ -1660,7 +1838,9 @@ var StoreClient = class {
1660
1838
  snapshotId,
1661
1839
  reused: true,
1662
1840
  components: [],
1663
- ok: true
1841
+ ok: true,
1842
+ errors: [],
1843
+ warnings: []
1664
1844
  };
1665
1845
  const status = await this.host.uninstallInstall(snapshotId, componentIds);
1666
1846
  return this.outcomeFromStatus(snapshotId, status, false);
@@ -1680,7 +1860,9 @@ var StoreClient = class {
1680
1860
  snapshotId,
1681
1861
  reused: true,
1682
1862
  components: [],
1683
- ok: true
1863
+ ok: true,
1864
+ errors: [],
1865
+ warnings: []
1684
1866
  };
1685
1867
  const status = enabled ? await this.host.enableInstall(snapshotId, componentIds) : await this.host.disableInstall(snapshotId, componentIds);
1686
1868
  return this.outcomeFromStatus(snapshotId, status, false);
@@ -1699,11 +1881,14 @@ var StoreClient = class {
1699
1881
  }
1700
1882
  outcomeFromStatus(snapshotId, status, reused) {
1701
1883
  const components = status.outcomes ?? [];
1884
+ const errors = status.errors ?? [];
1702
1885
  return {
1703
1886
  snapshotId,
1704
1887
  reused,
1705
1888
  components,
1706
- ok: (status.errors ?? []).length === 0 && components.every((component) => component.ok)
1889
+ ok: errors.length === 0 && components.every((component) => component.ok),
1890
+ errors,
1891
+ warnings: []
1707
1892
  };
1708
1893
  }
1709
1894
  /**
@@ -1721,11 +1906,15 @@ var StoreClient = class {
1721
1906
  if (connectors.length > 0) await this.host.enableInstall(snapshotId, connectors.map((component) => component.id));
1722
1907
  const deadline = Date.now() + (options.timeoutMs ?? this.readyTimeoutMs);
1723
1908
  let interval = this.readyPollMs;
1909
+ let nextProbeAt = 0;
1724
1910
  let last = status.components;
1725
1911
  for (;;) {
1912
+ const now = Date.now();
1913
+ const allowProbe = now >= nextProbeAt;
1914
+ if (allowProbe) nextProbeAt = now + this.readyProbeMs;
1726
1915
  const blocked = (await Promise.all(last.filter((component) => component.state !== "not-installed").map(async (component) => ({
1727
1916
  component,
1728
- verdict: await this.readiness(component)
1917
+ verdict: await this.readiness(component, allowProbe)
1729
1918
  })))).find((entry) => !entry.verdict.ready);
1730
1919
  if (!blocked) return {
1731
1920
  ...outcome,
@@ -1755,8 +1944,12 @@ var StoreClient = class {
1755
1944
  * unknown kind is reported ready rather than blocking: this layer cannot judge
1756
1945
  * a component it does not understand, and a false timeout on a future kind
1757
1946
  * would be worse than passing it through.
1947
+ *
1948
+ * `allowProbe` gates the one kind whose readiness needs a real connection (a
1949
+ * connector); the other kinds answer from local reads, so the cadence does not
1950
+ * apply to them.
1758
1951
  */
1759
- async readiness(component) {
1952
+ async readiness(component, allowProbe) {
1760
1953
  try {
1761
1954
  switch (component.kind) {
1762
1955
  case "skill": return (await this.host.skills.list()).some((skill) => skill.name === component.name) ? { ready: true } : { ready: false };
@@ -1765,8 +1958,9 @@ var StoreClient = class {
1765
1958
  await this.host.teams.get(component.id);
1766
1959
  return { ready: true };
1767
1960
  case "connector": {
1768
- if ((await this.host.connectors.test(component.id)).success) return { ready: true };
1961
+ if (allowProbe && (await this.host.connectors.test(component.id)).success) return { ready: true };
1769
1962
  const status = await this.host.connectors.status(component.id);
1963
+ if (status.status === "connected") return { ready: true };
1770
1964
  if (status.status === "authorization_required" || status.status === "reauthorization_required") return {
1771
1965
  ready: false,
1772
1966
  terminal: "authorization_required"
@@ -2042,6 +2236,25 @@ var AppServerClient = class {
2042
2236
  entry_name: entryName
2043
2237
  });
2044
2238
  }
2239
+ /**
2240
+ * The host's market policy: sweep cadence, auto-upgrade kind whitelist and the
2241
+ * last sweep's reading (doc `37` §3.2).
2242
+ *
2243
+ * Host-level rather than per-market: it answers "when does the sweep run and
2244
+ * what may it touch", while {@link setMarketplaceAutoUpdate} answers "which
2245
+ * market participates".
2246
+ */
2247
+ async getMarketSettings() {
2248
+ return this.transport.request("market/settings", {});
2249
+ }
2250
+ /**
2251
+ * Update the host's market policy. An absent field is left alone; the host
2252
+ * writes the value into its `config.toml` and answers with the file re-read,
2253
+ * so a caller can never see an optimistic echo.
2254
+ */
2255
+ async setMarketSettings(patch) {
2256
+ return this.transport.request("market/settings-set", patch);
2257
+ }
2045
2258
  /** All store items across enabled marketplaces (display + install state). */
2046
2259
  async listStore() {
2047
2260
  return this.transport.request("store/list", {});
@@ -2053,6 +2266,20 @@ var AppServerClient = class {
2053
2266
  entry_name: entryName
2054
2267
  });
2055
2268
  }
2269
+ /**
2270
+ * Upgrade an installed entry to the version its marketplace advertises.
2271
+ *
2272
+ * The host installs the new version before releasing the old one, so a failure
2273
+ * leaves the previous installation usable (`released_count: 0` is the machine
2274
+ * readable form of that). Refused for an entry that is not installed — this is
2275
+ * never a second way to install something.
2276
+ */
2277
+ async updateStoreEntry(marketplaceId, entryName) {
2278
+ return this.transport.request("store/update-entry", {
2279
+ marketplace_id: marketplaceId,
2280
+ entry_name: entryName
2281
+ });
2282
+ }
2056
2283
  };
2057
2284
  //#endregion
2058
2285
  //#region src/conversation-handle.ts