@apifuse/provider-sdk 2.2.0-beta.29 → 2.2.0-beta.30

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.
@@ -728,6 +728,12 @@ function createProviderContext(
728
728
  request: requestContext,
729
729
  credential,
730
730
  state: requestState,
731
+ onTelemetry: (event) =>
732
+ (options.logger ?? defaultProviderServerLogger)({
733
+ level: "info",
734
+ event: "provider_choice_token",
735
+ ...event,
736
+ }),
731
737
  }),
732
738
  });
733
739
  wrappedContext = context;
@@ -948,6 +954,18 @@ export type ProviderServerLogEvent =
948
954
  providerId: string;
949
955
  missingSecrets: string[];
950
956
  }
957
+ | {
958
+ level: "info";
959
+ event: "provider_choice_token";
960
+ providerId: string;
961
+ purpose: string;
962
+ operation: "parse" | "consume";
963
+ format: "word" | "legacy";
964
+ outcome: "success" | "not-found" | "invalid" | "unsupported" | "error";
965
+ consumeMode: "never" | "on-parse" | "explicit";
966
+ consumed: boolean;
967
+ replay: boolean;
968
+ }
951
969
  | {
952
970
  level: "warn";
953
971
  event: "provider_cleanup_failed";
package/src/types.ts CHANGED
@@ -1892,6 +1892,28 @@ export interface ProviderChoiceBindingOptions {
1892
1892
  credentialKeys?: readonly string[];
1893
1893
  }
1894
1894
 
1895
+ export type ProviderChoiceConsumeMode = "never" | "on-parse" | "explicit";
1896
+
1897
+ export type ProviderChoiceConsumeResult =
1898
+ | { readonly status: "consumed" }
1899
+ | { readonly status: "already-consumed" }
1900
+ | { readonly status: "unsupported" };
1901
+
1902
+ export type ProviderChoiceExplicitParseResult =
1903
+ | {
1904
+ readonly status: "active";
1905
+ readonly payload: Record<string, unknown>;
1906
+ /** Stable, opaque key for provider-owned idempotency records. */
1907
+ readonly replayKey: string;
1908
+ /** Atomically claims a word token. Legacy managed tokens report unsupported. */
1909
+ consume(): Promise<ProviderChoiceConsumeResult>;
1910
+ }
1911
+ | {
1912
+ readonly status: "consumed";
1913
+ /** Use this key to read the provider-owned result before returning an error. */
1914
+ readonly replayKey: string;
1915
+ };
1916
+
1895
1917
  export type ProviderChoiceStorageOptions =
1896
1918
  | {
1897
1919
  readonly mode: "inline";
@@ -1925,6 +1947,8 @@ export interface ProviderChoiceIssueOptions<
1925
1947
  ttlMs: number;
1926
1948
  nowMs?: number;
1927
1949
  bind?: ProviderChoiceBindingOptions;
1950
+ /** Server storage only: standard emits four words; high emits five. */
1951
+ strength?: "standard" | "high";
1928
1952
  storage?: ProviderChoiceStorageOptions;
1929
1953
  }
1930
1954
 
@@ -1937,6 +1961,8 @@ export interface ProviderChoiceParseOptions {
1937
1961
  futureToleranceMs?: number;
1938
1962
  bind?: ProviderChoiceBindingOptions;
1939
1963
  storage?: ProviderChoiceStorageOptions;
1964
+ /** Defaults to never, matching legacy managed-token parse semantics. */
1965
+ consume?: ProviderChoiceConsumeMode;
1940
1966
  }
1941
1967
 
1942
1968
  export interface ProviderChoiceContext {
@@ -1964,6 +1990,9 @@ export interface ProviderChoiceContext {
1964
1990
  issue<TPayload extends Record<string, unknown>>(
1965
1991
  options: ProviderChoiceIssueOptions<TPayload>,
1966
1992
  ): string | Promise<string>;
1993
+ parse(
1994
+ options: ProviderChoiceParseOptions & { readonly consume: "explicit" },
1995
+ ): Promise<ProviderChoiceExplicitParseResult>;
1967
1996
  parse(
1968
1997
  options: ProviderChoiceParseOptions & {
1969
1998
  readonly storage?: { readonly mode: "inline" };
@@ -1985,7 +2014,11 @@ export interface ProviderChoiceContext {
1985
2014
  >;
1986
2015
  },
1987
2016
  ): Record<string, unknown> | Promise<Record<string, unknown>>;
1988
- parse(options: ProviderChoiceParseOptions): Record<string, unknown>;
2017
+ parse(
2018
+ options: ProviderChoiceParseOptions,
2019
+ ):
2020
+ | Record<string, unknown>
2021
+ | Promise<Record<string, unknown> | ProviderChoiceExplicitParseResult>;
1989
2022
  }
1990
2023
 
1991
2024
  export interface ContextScratchpad {