@slashfi/agents-sdk 0.89.1 → 0.89.3

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.
@@ -47,7 +47,14 @@ import type {
47
47
  RegistryConfiguration,
48
48
  RegistryConsumer,
49
49
  } from "./registry-consumer.js";
50
- import type { CallAgentResponse, SecuritySchemeSummary } from "./types.js";
50
+ import type {
51
+ CallAgentErrorResponse,
52
+ CallAgentExecuteToolResponse,
53
+ CallAgentListResourcesResponse,
54
+ CallAgentReadResourcesResponse,
55
+ CallAgentResponse,
56
+ SecuritySchemeSummary,
57
+ } from "./types.js";
51
58
 
52
59
  const CONFIG_PATH = "consumer-config.json";
53
60
  const REGISTRY_CACHE_PATH = "registry-cache.json";
@@ -367,6 +374,33 @@ export interface AuthStartResult {
367
374
  fields?: AuthChallengeField[];
368
375
  }
369
376
 
377
+ export type AdkRefCallResult =
378
+ | CallAgentExecuteToolResponse
379
+ | CallAgentErrorResponse;
380
+ export type AdkRefResourcesResult =
381
+ | CallAgentListResourcesResponse
382
+ | CallAgentErrorResponse;
383
+ export type AdkRefReadResult =
384
+ | CallAgentReadResourcesResponse
385
+ | CallAgentErrorResponse;
386
+
387
+ type AdkRefActionResult =
388
+ | AdkRefCallResult
389
+ | AdkRefResourcesResult
390
+ | AdkRefReadResult;
391
+
392
+ function toAdkRefActionResult<T extends AdkRefActionResult>(
393
+ result: CallAgentResponse,
394
+ expectedKey: "result" | "resources",
395
+ code: string,
396
+ error: string,
397
+ ): T {
398
+ if (result.success === false) return result as T;
399
+ if (expectedKey in result) return result as T;
400
+
401
+ return { success: false, error, code } as T;
402
+ }
403
+
370
404
  /**
371
405
  * Type slot for adk.ref.call() type safety.
372
406
  * Empty by default — populated by `adk sync` which generates `adk.d.ts`.
@@ -391,13 +425,13 @@ type AdkRefCallFn = keyof AdkAgentRegistry extends never
391
425
  name: string,
392
426
  tool: string,
393
427
  params?: Record<string, unknown>,
394
- ) => Promise<CallAgentResponse>
428
+ ) => Promise<AdkRefCallResult>
395
429
  : // Registry populated — strict typed overload
396
430
  <A extends AgentPath, T extends ToolsOf<A>>(
397
431
  name: A,
398
432
  tool: T,
399
433
  params: ParamsOf<A, T>,
400
- ) => Promise<CallAgentResponse>;
434
+ ) => Promise<AdkRefCallResult>;
401
435
 
402
436
  export interface AdkRefApi {
403
437
  add(entry: RefAddInput): Promise<{ security: SecuritySchemeSummary | null }>;
@@ -410,8 +444,8 @@ export interface AdkRefApi {
410
444
  options?: { full?: boolean },
411
445
  ): Promise<AgentInspection | null>;
412
446
  call: AdkRefCallFn;
413
- resources(name: string): Promise<CallAgentResponse>;
414
- read(name: string, uris: string[]): Promise<CallAgentResponse>;
447
+ resources(name: string): Promise<AdkRefResourcesResult>;
448
+ read(name: string, uris: string[]): Promise<AdkRefReadResult>;
415
449
  /** Check auth status — what's needed vs what's stored */
416
450
  authStatus(name: string): Promise<RefAuthStatus>;
417
451
  /**
@@ -2137,7 +2171,7 @@ export function createAdk(fs: FsStore, options: AdkOptions = {}): Adk {
2137
2171
  name: string,
2138
2172
  tool: string,
2139
2173
  params?: Record<string, unknown>,
2140
- ): Promise<CallAgentResponse> {
2174
+ ): Promise<AdkRefCallResult> {
2141
2175
  const config = await readConfig();
2142
2176
  const entry = findRef(config.refs ?? [], name);
2143
2177
  if (!entry) throw new Error(`Ref "${name}" not found`);
@@ -2231,14 +2265,24 @@ export function createAdk(fs: FsStore, options: AdkOptions = {}): Adk {
2231
2265
  if (accessToken && isUnauthorized(result)) {
2232
2266
  const refreshed = await ref.refreshToken(name);
2233
2267
  if (refreshed) {
2234
- return doCall(refreshed.accessToken);
2268
+ return toAdkRefActionResult<AdkRefCallResult>(
2269
+ await doCall(refreshed.accessToken),
2270
+ "result",
2271
+ "unexpected_ref_call_response",
2272
+ "Expected execute_tool response from ref.call",
2273
+ );
2235
2274
  }
2236
2275
  }
2237
2276
 
2238
- return result;
2277
+ return toAdkRefActionResult<AdkRefCallResult>(
2278
+ result,
2279
+ "result",
2280
+ "unexpected_ref_call_response",
2281
+ "Expected execute_tool response from ref.call",
2282
+ );
2239
2283
  },
2240
2284
 
2241
- async resources(name: string): Promise<CallAgentResponse> {
2285
+ async resources(name: string): Promise<AdkRefResourcesResult> {
2242
2286
  const config = await readConfig();
2243
2287
  const entry = findRef(config.refs ?? [], name);
2244
2288
  if (!entry) throw new Error(`Ref "${name}" not found`);
@@ -2246,13 +2290,18 @@ export function createAdk(fs: FsStore, options: AdkOptions = {}): Adk {
2246
2290
  const consumer = await buildConsumerForRef(entry);
2247
2291
  const reg = resolveRegistryForRef(consumer, entry);
2248
2292
 
2249
- return consumer.callRegistry(reg, {
2250
- action: "list_resources",
2251
- path: entry.sourceRegistry?.agentPath ?? entry.ref,
2252
- });
2293
+ return toAdkRefActionResult<AdkRefResourcesResult>(
2294
+ await consumer.callRegistry(reg, {
2295
+ action: "list_resources",
2296
+ path: entry.sourceRegistry?.agentPath ?? entry.ref,
2297
+ }),
2298
+ "resources",
2299
+ "unexpected_ref_resources_response",
2300
+ "Expected list_resources response from ref.resources",
2301
+ );
2253
2302
  },
2254
2303
 
2255
- async read(name: string, uris: string[]): Promise<CallAgentResponse> {
2304
+ async read(name: string, uris: string[]): Promise<AdkRefReadResult> {
2256
2305
  const config = await readConfig();
2257
2306
  const entry = findRef(config.refs ?? [], name);
2258
2307
  if (!entry) throw new Error(`Ref "${name}" not found`);
@@ -2260,11 +2309,16 @@ export function createAdk(fs: FsStore, options: AdkOptions = {}): Adk {
2260
2309
  const consumer = await buildConsumerForRef(entry);
2261
2310
  const reg = resolveRegistryForRef(consumer, entry);
2262
2311
 
2263
- return consumer.callRegistry(reg, {
2264
- action: "read_resources",
2265
- path: entry.sourceRegistry?.agentPath ?? entry.ref,
2266
- uris,
2267
- });
2312
+ return toAdkRefActionResult<AdkRefReadResult>(
2313
+ await consumer.callRegistry(reg, {
2314
+ action: "read_resources",
2315
+ path: entry.sourceRegistry?.agentPath ?? entry.ref,
2316
+ uris,
2317
+ }),
2318
+ "resources",
2319
+ "unexpected_ref_read_response",
2320
+ "Expected read_resources response from ref.read",
2321
+ );
2268
2322
  },
2269
2323
 
2270
2324
  async authStatus(name: string): Promise<RefAuthStatus> {
@@ -2442,6 +2496,21 @@ export function createAdk(fs: FsStore, options: AdkOptions = {}): Adk {
2442
2496
  present: configKeys.includes("token"),
2443
2497
  resolvable: await canResolve("token"),
2444
2498
  };
2499
+ } else if (security.type === "form") {
2500
+ // Form-based refs collect structured user input at connect time
2501
+ // (for example database host/user/password), then store the encoded
2502
+ // form payload in the canonical credential slot that `ref.call`
2503
+ // already reads and forwards to registry executors as
2504
+ // `params.accessToken`. Cache that derived credential requirement
2505
+ // instead of the individual form fields so host-side connected checks
2506
+ // answer the same question as the call path: "does this ref carry
2507
+ // the opaque credential blob needed to invoke it?"
2508
+ fields.access_token = {
2509
+ required: true,
2510
+ automated: false,
2511
+ present: configKeys.includes("access_token"),
2512
+ resolvable: await canResolve("access_token"),
2513
+ };
2445
2514
  }
2446
2515
 
2447
2516
  const complete = Object.values(fields).every(
package/src/index.ts CHANGED
@@ -85,6 +85,7 @@ export type {
85
85
  ToolSelectionContext,
86
86
  IntegrationConfig,
87
87
  ApiKeySecurityScheme,
88
+ FormSecurityScheme,
88
89
  HttpSecurityScheme,
89
90
  NoneSecurityScheme,
90
91
  OAuth2SecurityScheme,
package/src/types.ts CHANGED
@@ -243,6 +243,17 @@ export interface HttpSecurityScheme {
243
243
  scheme: "bearer" | "basic";
244
244
  }
245
245
 
246
+ /**
247
+ * Form-based authentication. Consumers collect arbitrary structured fields
248
+ * (for example database connection settings), then store the encoded form
249
+ * payload in the ref's `access_token` credential slot. At call time ADK
250
+ * forwards that value as `params.accessToken` to the registry executor.
251
+ */
252
+ export interface FormSecurityScheme {
253
+ type: "form";
254
+ [key: string]: unknown;
255
+ }
256
+
246
257
  /**
247
258
  * No authentication required.
248
259
  */
@@ -285,6 +296,7 @@ export type SecurityScheme =
285
296
  | OAuth2SecurityScheme
286
297
  | ApiKeySecurityScheme
287
298
  | HttpSecurityScheme
299
+ | FormSecurityScheme
288
300
  | NoneSecurityScheme;
289
301
 
290
302
  /**