@inferencesh/sdk 0.39.3 → 0.39.4

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/CHANGELOG.md CHANGED
@@ -7,6 +7,35 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.39.4] - 2026-11-13
11
+
12
+ ### Fixed
13
+ - `AgentChatProvider` uses a replaced `client` prop. The chat actions were created once with the first client, so after the client changed (a new API key, another account) sending, uploading, approvals and the stream kept calling the API as the old one. The actions are now rebuilt for the new client, the old client's stream is stopped and the open chat is reopened with the new one. Pass a stable client (`useMemo`): a client created on every render restarts the stream on every render.
14
+ - `elicitParams` drops malformed MCP elicitation params and schema parts instead of passing them on.
15
+
16
+ ## [0.39.3] - 2026-11-12
17
+
18
+ ### Changed
19
+ - Types regenerated from the API: chat strictness (`ChatStrictness`, `ChatStrictnessDTO`, `ChatSettingsDTO.strictness`, run end reason `content_flagged`), sandbox snapshots kept in object storage, task `start_timeout`.
20
+
21
+ ## [0.39.2] - 2026-11-10
22
+
23
+ ### Added
24
+ - Sandboxes: `exec` (waits for the result), `listFiles`, `readFile`, `readTextFile`, `writeFile`, `deleteFile`, `limits`. Files move through file storage (`writeFile` uploads then imports, `readFile` exports then downloads; the storage copy is deleted).
25
+
26
+ ### Changed
27
+ - `sandboxes.limits()` follows the entitlement-built DTO: `limits[]` of `ResourceUsage`; `running` and `vcpus` are removed.
28
+ - A problem body under a 200 response throws like a refused response.
29
+
30
+ ## [0.39.1] - 2026-11-10
31
+
32
+ ### Changed
33
+ - Types regenerated from the API: sandbox limits, image upgrade, snapshots, ports, exec wait, sandbox files, plan limits, engine capacity policy, credential scheme hosts, sandbox idle default (15 minutes); proxy endpoints carry `remotes:write`.
34
+
35
+ ## [0.39.0] - 2026-11-07
36
+
37
+ **Breaking:** task errors are typed.
38
+
10
39
  ### Changed
11
40
  - `tasks.run()` and `tasks.watch().done` reject with `TaskCancelledError` when the task is cancelled and `TaskFailedError` when it fails, instead of a plain `Error`. Both carry the task as `error.task`. A task cancelled after its app returned a result now ends cancelled with that result as its `output`, so a caller that cancels reads the partial result from `error.task.output`. Messages are unchanged (`task cancelled`, the task's error). `isTaskCancelledError` and `isTaskFailedError` are the type guards.
12
41
 
@@ -6,4 +6,16 @@
6
6
  */
7
7
  import type { ActionsContext, ActionsResult } from './types.js';
8
8
  export declare function createActions(ctx: ActionsContext): ActionsResult;
9
+ /** Actions and the context they were created with. */
10
+ export interface BoundActions {
11
+ ctx: ActionsContext;
12
+ result: ActionsResult;
13
+ }
14
+ /**
15
+ * The actions for ctx: the bound ones while ctx is the same object, new ones
16
+ * once it is replaced. Actions keep the client of the context they were
17
+ * created with, so reusing them after the client changed would keep calling
18
+ * the API as the old client.
19
+ */
20
+ export declare function actionsFor(bound: BoundActions | null, ctx: ActionsContext): BoundActions;
9
21
  export declare function getClientToolHandlers(config: import('./types.js').AgentOptions | null): Map<string, import('./types.js').ClientToolHandlerFn>;
@@ -631,6 +631,17 @@ export function createActions(ctx) {
631
631
  };
632
632
  return { publicActions, internalActions };
633
633
  }
634
+ /**
635
+ * The actions for ctx: the bound ones while ctx is the same object, new ones
636
+ * once it is replaced. Actions keep the client of the context they were
637
+ * created with, so reusing them after the client changed would keep calling
638
+ * the API as the old client.
639
+ */
640
+ export function actionsFor(bound, ctx) {
641
+ if (bound && bound.ctx === ctx)
642
+ return bound;
643
+ return { ctx, result: createActions(ctx) };
644
+ }
634
645
  // =============================================================================
635
646
  // Helper: Extract client tool handlers from config
636
647
  // =============================================================================
@@ -65,7 +65,12 @@ export interface ElicitRequestParams {
65
65
  }
66
66
  /** Parses an invocation's data into MCPInputState, or null when it isn't one. */
67
67
  export declare function parseMCPInputState(data: unknown): MCPInputState | null;
68
- /** Returns the elicitation params of an input request, or null for other methods. */
68
+ /**
69
+ * Returns the elicitation params of an input request, or null for other
70
+ * methods and for params that are not an object. The fields are the server's:
71
+ * a message or url that is not a string, and the parts of requestedSchema that
72
+ * do not have the declared shape, are dropped.
73
+ */
69
74
  export declare function elicitParams(request: InputRequest): ElicitRequestParams | null;
70
75
  /** URL mode sends the user to a page; form mode asks for fields. Mode defaults to form. */
71
76
  export declare function isURLElicitation(params: ElicitRequestParams): boolean;
@@ -35,12 +35,89 @@ export function parseMCPInputState(data) {
35
35
  round: typeof state.round === 'number' ? state.round : 1,
36
36
  };
37
37
  }
38
- /** Returns the elicitation params of an input request, or null for other methods. */
38
+ function isRecord(value) {
39
+ return !!value && typeof value === 'object' && !Array.isArray(value);
40
+ }
41
+ function stringArray(value) {
42
+ return Array.isArray(value) ? value.filter((v) => typeof v === 'string') : undefined;
43
+ }
44
+ function choiceArray(value) {
45
+ if (!Array.isArray(value))
46
+ return undefined;
47
+ return value.filter((c) => isRecord(c) && typeof c.const === 'string');
48
+ }
49
+ /** Sets key to value, or removes it when value is undefined. */
50
+ function setOrDrop(target, key, value) {
51
+ if (value === undefined)
52
+ Reflect.deleteProperty(target, key);
53
+ else
54
+ target[key] = value;
55
+ }
56
+ function cleanProperty(raw) {
57
+ const property = { ...raw };
58
+ if ('enum' in property)
59
+ setOrDrop(property, 'enum', stringArray(property.enum));
60
+ if ('enumNames' in property)
61
+ setOrDrop(property, 'enumNames', stringArray(property.enumNames));
62
+ if ('oneOf' in property)
63
+ setOrDrop(property, 'oneOf', choiceArray(property.oneOf));
64
+ if ('items' in property) {
65
+ if (isRecord(property.items)) {
66
+ const items = { ...property.items };
67
+ if ('enum' in items)
68
+ setOrDrop(items, 'enum', stringArray(items.enum));
69
+ if ('anyOf' in items)
70
+ setOrDrop(items, 'anyOf', choiceArray(items.anyOf));
71
+ property.items = items;
72
+ }
73
+ else {
74
+ delete property.items;
75
+ }
76
+ }
77
+ return property;
78
+ }
79
+ /**
80
+ * The schema comes from the MCP server as it sent it. Whatever does not have
81
+ * the shape ElicitRequestedSchema declares is dropped, so a consumer can
82
+ * iterate properties, required and each property's choices without checking.
83
+ */
84
+ function cleanRequestedSchema(raw) {
85
+ if (!isRecord(raw))
86
+ return undefined;
87
+ const schema = { ...raw };
88
+ if ('properties' in schema) {
89
+ if (isRecord(schema.properties)) {
90
+ const properties = {};
91
+ for (const [name, property] of Object.entries(schema.properties)) {
92
+ if (isRecord(property))
93
+ properties[name] = cleanProperty(property);
94
+ }
95
+ schema.properties = properties;
96
+ }
97
+ else {
98
+ delete schema.properties;
99
+ }
100
+ }
101
+ if ('required' in schema)
102
+ setOrDrop(schema, 'required', stringArray(schema.required));
103
+ return schema;
104
+ }
105
+ /**
106
+ * Returns the elicitation params of an input request, or null for other
107
+ * methods and for params that are not an object. The fields are the server's:
108
+ * a message or url that is not a string, and the parts of requestedSchema that
109
+ * do not have the declared shape, are dropped.
110
+ */
39
111
  export function elicitParams(request) {
40
- if (request.method !== MCPMethodElicitationCreate || !request.params)
112
+ if (request.method !== MCPMethodElicitationCreate || !isRecord(request.params))
41
113
  return null;
42
- const params = request.params;
43
- return { ...params, message: params.message ?? '' };
114
+ const params = { ...request.params };
115
+ params.message = typeof params.message === 'string' ? params.message : '';
116
+ if ('url' in params && typeof params.url !== 'string')
117
+ delete params.url;
118
+ if ('requestedSchema' in params)
119
+ setOrDrop(params, 'requestedSchema', cleanRequestedSchema(params.requestedSchema));
120
+ return params;
44
121
  }
45
122
  /** URL mode sends the user to a page; form mode asks for fields. Mode defaults to form. */
46
123
  export function isURLElicitation(params) {
@@ -8,7 +8,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
8
8
  import { useReducer, useRef, useEffect, useMemo } from 'react';
9
9
  import { AgentChatContext } from './context.js';
10
10
  import { chatReducer, initialState } from './reducer.js';
11
- import { createActions, getClientToolHandlers } from './actions.js';
11
+ import { actionsFor, getClientToolHandlers } from './actions.js';
12
12
  import { fetchAgentInfo } from './api.js';
13
13
  import { isTemplateConfig } from './types.js';
14
14
  function mergeHandlers(base, extra) {
@@ -88,11 +88,12 @@ export function AgentChatProvider({ client, agentConfig, chatId, clientToolHandl
88
88
  useEffect(() => {
89
89
  actionsContext.callbacks = callbacksRef.current;
90
90
  }, [actionsContext, onChatCreated, onStatusChange, onError, onTurnEnd]);
91
+ // One set of actions per client: actions call the API with the client they
92
+ // were created with, so a replaced client (another key, another account)
93
+ // gets new ones and the old client is not used again.
91
94
  const actionsResultRef = useRef(null);
92
- if (!actionsResultRef.current) {
93
- actionsResultRef.current = createActions(actionsContext);
94
- }
95
- const { publicActions, internalActions } = actionsResultRef.current;
95
+ actionsResultRef.current = actionsFor(actionsResultRef.current, actionsContext);
96
+ const { publicActions, internalActions } = actionsResultRef.current.result;
96
97
  // Fetch agent info for template configs (example_prompts, description)
97
98
  const agentRef = isTemplateConfig(agentConfig) ? agentConfig.agent : null;
98
99
  useEffect(() => {
@@ -111,12 +112,22 @@ export function AgentChatProvider({ client, agentConfig, chatId, clientToolHandl
111
112
  internalActions.setChatId(chatId);
112
113
  }
113
114
  }, [chatId, state.chatId, internalActions]);
114
- // Cleanup on unmount
115
+ // Cleanup on unmount, and when the client is replaced: the stream was
116
+ // opened with the old client's credentials.
115
117
  useEffect(() => {
116
118
  return () => {
117
119
  internalActions.stopStream();
118
120
  };
119
121
  }, [internalActions]);
122
+ // A replaced client reopens the open chat with its own credentials.
123
+ const streamingActionsRef = useRef(internalActions);
124
+ useEffect(() => {
125
+ if (streamingActionsRef.current === internalActions)
126
+ return;
127
+ streamingActionsRef.current = internalActions;
128
+ if (chatIdRef.current)
129
+ internalActions.streamChat(chatIdRef.current);
130
+ }, [internalActions]);
120
131
  const contextValue = useMemo(() => ({
121
132
  state,
122
133
  actions: publicActions,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inferencesh/sdk",
3
- "version": "0.39.3",
3
+ "version": "0.39.4",
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",