@inferencesh/sdk 0.11.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,6 +11,8 @@ import { PollManager } from '../http/poll';
11
11
  import { createLLMDeltaAccumulator } from '../delta';
12
12
  import { isAdHocConfig, extractClientToolHandlers } from './types';
13
13
  import * as api from './api';
14
+ import { buildMCPInputResult } from './mcp-input';
15
+ import { isInferenceError } from '../http/errors';
14
16
  // =============================================================================
15
17
  // Action Creators
16
18
  // =============================================================================
@@ -323,6 +325,23 @@ export function createActions(ctx) {
323
325
  throw error;
324
326
  }
325
327
  },
328
+ submitMCPInput: async (toolInvocationId, responses) => {
329
+ try {
330
+ await api.submitToolResult(client, toolInvocationId, buildMCPInputResult(responses));
331
+ }
332
+ catch (error) {
333
+ // A 400 means the answers were rejected and the call is still waiting:
334
+ // the caller shows it next to the form, the connection is fine.
335
+ if (isInferenceError(error) && error.statusCode === 400)
336
+ throw error;
337
+ console.error('[AgentSDK] Failed to submit MCP input:', error);
338
+ const err = error instanceof Error ? error : new Error('Failed to submit MCP input');
339
+ dispatch({ type: 'SET_CONNECTION_STATUS', payload: 'error' });
340
+ dispatch({ type: 'SET_ERROR', payload: err.message });
341
+ callbacks.onError?.(err);
342
+ throw error;
343
+ }
344
+ },
326
345
  approveTool: async (toolInvocationId) => {
327
346
  try {
328
347
  await api.approveTool(client, toolInvocationId);
@@ -48,3 +48,4 @@ export { useAgentChat, useAgentActions, useAgentClient, useAgentChatContext, use
48
48
  export { AgentChatContext, type AgentChatContextValue } from './context';
49
49
  export type { AgentClient, FileRef, AdHocAgentConfig, TemplateAgentConfig, AgentOptions, AgentChatState, AgentChatActions, ChatStatus, AgentChatProviderProps, ClientTool, ClientToolHandlerFn, } from './types';
50
50
  export { isAdHocConfig, isTemplateConfig, isClientTool, extractToolSchemas, extractClientToolHandlers, } from './types';
51
+ export { MCPMethodElicitationCreate, parseMCPInputState, elicitParams, isURLElicitation, buildMCPInputResult, type MCPInputState, type ElicitRequestParams, type ElicitRequestedSchema, type ElicitPropertySchema, } from './mcp-input';
@@ -51,3 +51,5 @@ export { useAgentChat, useAgentActions, useAgentClient, useAgentChatContext, use
51
51
  export { AgentChatContext } from './context';
52
52
  // Type guards and helpers
53
53
  export { isAdHocConfig, isTemplateConfig, isClientTool, extractToolSchemas, extractClientToolHandlers, } from './types';
54
+ // MCP input requests
55
+ export { MCPMethodElicitationCreate, parseMCPInputState, elicitParams, isURLElicitation, buildMCPInputResult, } from './mcp-input';
@@ -0,0 +1,57 @@
1
+ /**
2
+ * MCP input requests on agent tool invocations.
3
+ *
4
+ * When a remote MCP server answers a tool call with `input_required`, the agent
5
+ * runtime parks the invocation in `awaiting_input` and stores an MCPInputState in
6
+ * its `data`. The UI renders each input request, collects an ElicitResult per
7
+ * key, and submits them with `submitMCPInput`; the runtime then re-sends the
8
+ * tool call with those responses.
9
+ */
10
+ import type { ElicitResult, InputRequest } from '../types';
11
+ export declare const MCPMethodElicitationCreate = "elicitation/create";
12
+ /** Stored in ToolInvocationDTO.data while an MCP tool call waits for the user. */
13
+ export interface MCPInputState {
14
+ input_required: true;
15
+ input_requests: Record<string, InputRequest>;
16
+ request_state?: string;
17
+ /** 1 for the first request; goes up each time the server asks again. */
18
+ round: number;
19
+ }
20
+ /** One property of a form-mode requestedSchema (MCP restricts these to flat primitives). */
21
+ export interface ElicitPropertySchema {
22
+ type?: 'string' | 'number' | 'integer' | 'boolean';
23
+ title?: string;
24
+ description?: string;
25
+ default?: unknown;
26
+ format?: 'email' | 'uri' | 'date' | 'date-time' | string;
27
+ minLength?: number;
28
+ maxLength?: number;
29
+ minimum?: number;
30
+ maximum?: number;
31
+ enum?: string[];
32
+ enumNames?: string[];
33
+ oneOf?: {
34
+ const: string;
35
+ title?: string;
36
+ }[];
37
+ }
38
+ export interface ElicitRequestedSchema {
39
+ type?: 'object';
40
+ properties?: Record<string, ElicitPropertySchema>;
41
+ required?: string[];
42
+ }
43
+ /** params of an elicitation/create request. */
44
+ export interface ElicitRequestParams {
45
+ mode?: 'form' | 'url';
46
+ message: string;
47
+ requestedSchema?: ElicitRequestedSchema;
48
+ url?: string;
49
+ }
50
+ /** Parses an invocation's data into MCPInputState, or null when it isn't one. */
51
+ export declare function parseMCPInputState(data: unknown): MCPInputState | null;
52
+ /** Returns the elicitation params of an input request, or null for other methods. */
53
+ export declare function elicitParams(request: InputRequest): ElicitRequestParams | null;
54
+ /** URL mode sends the user to a page; form mode asks for fields. Mode defaults to form. */
55
+ export declare function isURLElicitation(params: ElicitRequestParams): boolean;
56
+ /** Builds the tool result string the runtime expects: {<key>: {action, content?}}. */
57
+ export declare function buildMCPInputResult(responses: Record<string, ElicitResult>): string;
@@ -0,0 +1,58 @@
1
+ /**
2
+ * MCP input requests on agent tool invocations.
3
+ *
4
+ * When a remote MCP server answers a tool call with `input_required`, the agent
5
+ * runtime parks the invocation in `awaiting_input` and stores an MCPInputState in
6
+ * its `data`. The UI renders each input request, collects an ElicitResult per
7
+ * key, and submits them with `submitMCPInput`; the runtime then re-sends the
8
+ * tool call with those responses.
9
+ */
10
+ export const MCPMethodElicitationCreate = 'elicitation/create';
11
+ /** Parses an invocation's data into MCPInputState, or null when it isn't one. */
12
+ export function parseMCPInputState(data) {
13
+ let value = data;
14
+ if (typeof value === 'string') {
15
+ try {
16
+ value = JSON.parse(value);
17
+ }
18
+ catch {
19
+ return null;
20
+ }
21
+ }
22
+ if (!value || typeof value !== 'object')
23
+ return null;
24
+ const state = value;
25
+ if (state.input_required !== true)
26
+ return null;
27
+ if (!state.input_requests || typeof state.input_requests !== 'object')
28
+ return null;
29
+ if (Object.keys(state.input_requests).length === 0)
30
+ return null;
31
+ return {
32
+ input_required: true,
33
+ input_requests: state.input_requests,
34
+ request_state: state.request_state,
35
+ round: typeof state.round === 'number' ? state.round : 1,
36
+ };
37
+ }
38
+ /** Returns the elicitation params of an input request, or null for other methods. */
39
+ export function elicitParams(request) {
40
+ if (request.method !== MCPMethodElicitationCreate || !request.params)
41
+ return null;
42
+ const params = request.params;
43
+ return { ...params, message: params.message ?? '' };
44
+ }
45
+ /** URL mode sends the user to a page; form mode asks for fields. Mode defaults to form. */
46
+ export function isURLElicitation(params) {
47
+ return params.mode === 'url' || (!params.mode && !!params.url);
48
+ }
49
+ /** Builds the tool result string the runtime expects: {<key>: {action, content?}}. */
50
+ export function buildMCPInputResult(responses) {
51
+ const out = {};
52
+ for (const [key, response] of Object.entries(responses)) {
53
+ out[key] = response.action === 'accept' && response.content
54
+ ? { action: response.action, content: response.content }
55
+ : { action: response.action };
56
+ }
57
+ return JSON.stringify(out);
58
+ }
@@ -4,7 +4,7 @@
4
4
  * Public types for the Agent chat module.
5
5
  */
6
6
  import type { Dispatch } from 'react';
7
- import type { AgentRunDTO, AgentVersionDTO, ChatDTO, ChatMessageDTO, AgentTool, AgentConfigInput as GeneratedAgentConfig, CoreAppConfigInput as CoreAppConfig, FileRef } from '../types';
7
+ import type { AgentRunDTO, AgentVersionDTO, ChatDTO, ChatMessageDTO, AgentTool, AgentConfigInput as GeneratedAgentConfig, CoreAppConfigInput as CoreAppConfig, FileRef, ElicitResult } from '../types';
8
8
  import type { HttpClient } from '../http/client';
9
9
  import type { StreamableManager } from '../http/streamable';
10
10
  import type { PollManager } from '../http/poll';
@@ -126,6 +126,8 @@ export interface AgentChatActions {
126
126
  clearError: () => void;
127
127
  /** Submit a tool result (for widgets/awaiting input) - usually called automatically by SDK */
128
128
  submitToolResult: (toolInvocationId: string, result: string) => Promise<void>;
129
+ /** Answer an MCP tool call's input requests (AwaitingInput status with MCPInputState data) */
130
+ submitMCPInput: (toolInvocationId: string, responses: Record<string, ElicitResult>) => Promise<void>;
129
131
  /** Approve a tool (for HIL approval - AwaitingApproval status) */
130
132
  approveTool: (toolInvocationId: string) => Promise<void>;
131
133
  /** Reject a tool (for HIL approval - AwaitingApproval status) */
package/dist/types.d.ts CHANGED
@@ -2692,9 +2692,14 @@ export interface ElicitationCapability {
2692
2692
  }
2693
2693
  /**
2694
2694
  * ClientCapabilities advertises what a client can do.
2695
+ * Extensions carries the extensions the client supports, keyed by identifier
2696
+ * (e.g. ExtensionTasks), each with its extension-defined settings object.
2695
2697
  */
2696
2698
  export interface ClientCapabilities {
2697
2699
  elicitation?: ElicitationCapability;
2700
+ extensions?: {
2701
+ [key: string]: any;
2702
+ };
2698
2703
  }
2699
2704
  /**
2700
2705
  * InputRequest is a single server-to-client request inside an InputRequiredResult.
@@ -2723,7 +2728,7 @@ export interface ElicitResult {
2723
2728
  * ResultType is the kind of result a response carries, required on every result
2724
2729
  * from 2026-07-28 onward.
2725
2730
  */
2726
- export type ResultType = "complete" | "input_required";
2731
+ export type ResultType = "complete" | "input_required" | "task";
2727
2732
  /**
2728
2733
  * ResultTypeComplete marks an ordinary, finished result.
2729
2734
  */
@@ -2733,6 +2738,11 @@ export declare const ResultTypeComplete: ResultType;
2733
2738
  * Recognised so the outbound client never mistakes one for tool output.
2734
2739
  */
2735
2740
  export declare const ResultTypeInputRequired: ResultType;
2741
+ /**
2742
+ * ResultTypeTask marks a CreateTaskResult: the server accepted the request
2743
+ * as a task under the tasks extension and the result arrives via tasks/get.
2744
+ */
2745
+ export declare const ResultTypeTask: ResultType;
2736
2746
  /**
2737
2747
  * CacheScope says who may reuse a cached result, per MCP 2026-07-28 (SEP-2549).
2738
2748
  * Analogous to HTTP Cache-Control public/private; the spec defines exactly these.
@@ -5624,7 +5634,25 @@ export type ToolParameterProperties = {
5624
5634
  [key: string]: ToolParameterProperty;
5625
5635
  };
5626
5636
  export interface ToolParameterProperty {
5627
- type: ToolParamType;
5637
+ /**
5638
+ * Type is the JSON Schema type of the value. Empty when AnyOf is set: the
5639
+ * value then has one of several shapes, and naming a single type would be
5640
+ * telling the model something untrue about what it may send.
5641
+ */
5642
+ type?: ToolParamType;
5643
+ /**
5644
+ * AnyOf lists the shapes a value may take, each described as a property of
5645
+ * its own. Anthropic and OpenAI both accept anyOf in tool schemas. Before
5646
+ * this field existed the converter picked one branch and dropped the rest,
5647
+ * so an app that accepted "401" or 401 could only tell the model about one.
5648
+ */
5649
+ anyOf?: ToolParameterProperty[];
5650
+ /**
5651
+ * Enum is the closed set of values a scalar may take, kept as data so a
5652
+ * consumer choosing arguments does not have to parse it back out of the
5653
+ * description.
5654
+ */
5655
+ enum?: any[];
5628
5656
  title: string;
5629
5657
  description: string;
5630
5658
  properties?: ToolParameterProperties;
package/dist/types.js CHANGED
@@ -438,6 +438,11 @@ export const ResultTypeComplete = "complete";
438
438
  * Recognised so the outbound client never mistakes one for tool output.
439
439
  */
440
440
  export const ResultTypeInputRequired = "input_required";
441
+ /**
442
+ * ResultTypeTask marks a CreateTaskResult: the server accepted the request
443
+ * as a task under the tasks extension and the result arrives via tasks/get.
444
+ */
445
+ export const ResultTypeTask = "task";
441
446
  /**
442
447
  * CacheScopePublic marks a response as free of user-specific data, so any
443
448
  * client or shared intermediary may cache it across authorization contexts.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inferencesh/sdk",
3
- "version": "0.11.0",
3
+ "version": "0.13.0",
4
4
  "description": "Official JavaScript/TypeScript SDK for inference.sh - Run AI models with a simple API",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",