@inferencesh/sdk 0.6.48 → 0.6.50

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.
@@ -139,8 +139,18 @@ export function createActions(ctx) {
139
139
  checkTurnEnd(chatData);
140
140
  }
141
141
  });
142
+ // Token-by-token streaming state, reset at every assistant-message boundary.
143
+ const deltaAccum = createLLMDeltaAccumulator();
142
144
  // Listen for ChatMessage updates
143
145
  manager.addEventListener('chat_messages', (message, fields) => {
146
+ // A new assistant message starts a new accumulation. The accumulator is
147
+ // cumulative and shared across the whole connection, so without this the
148
+ // next message's deltas merge into the previous message's state — and
149
+ // because concat with "" is a no-op, a turn that is only tool calls
150
+ // would render the previous message's text as its own.
151
+ if (message.role === 'assistant' && !getState().messages.some(m => m.id === message.id)) {
152
+ deltaAccum.reset();
153
+ }
144
154
  updateMessage(message, fields);
145
155
  });
146
156
  // Listen for AgentRun updates (state transitions, output)
@@ -152,8 +162,6 @@ export function createActions(ctx) {
152
162
  if (currentChat)
153
163
  checkTurnEnd({ ...currentChat, active_run: run });
154
164
  });
155
- // Listen for LLM delta events (token-by-token streaming)
156
- const deltaAccum = createLLMDeltaAccumulator();
157
165
  manager.addEventListener('delta', (evt) => {
158
166
  if (evt && evt.delta) {
159
167
  deltaAccum.apply(evt.delta);
@@ -9,6 +9,9 @@ export interface InternalToolDefinition {
9
9
  description: string;
10
10
  tools: string[];
11
11
  scope: string;
12
+ /** What this category resolves to when the agent's flag is unset. Opt-in
13
+ * categories default false; render switches from this rather than assume. */
14
+ default_enabled: boolean;
12
15
  }
13
16
  /** Options for creating an agent */
14
17
  export interface AgentOptions {
@@ -0,0 +1,72 @@
1
+ import { HttpClient } from '../http/client';
2
+ import type { Response } from '../http/response';
3
+ import { ArtifactDTO, ArtifactVersionDTO, ArtifactCreateRequest, ArtifactUpdateRequest, ArtifactPublishRequest, ArtifactContentResponse, CursorListRequest, CursorListResponse } from '../types';
4
+ /**
5
+ * Artifacts API — small self-contained HTML/Markdown pages published to a
6
+ * URL, versioned, permissioned, and shareable.
7
+ */
8
+ export declare class ArtifactsAPI {
9
+ private readonly http;
10
+ constructor(http: HttpClient);
11
+ /**
12
+ * List artifacts with cursor-based pagination
13
+ */
14
+ list(params?: Partial<CursorListRequest>): Promise<Response<CursorListResponse<ArtifactDTO>>>;
15
+ /**
16
+ * Get an artifact by ID or short ID
17
+ */
18
+ get(id: string): Promise<Response<ArtifactDTO>>;
19
+ /**
20
+ * Get an artifact by namespace/name
21
+ */
22
+ getByName(namespace: string, name: string): Promise<Response<ArtifactDTO>>;
23
+ /**
24
+ * Publish an artifact. Creates it, or publishes a new version when an
25
+ * artifact with the same name already exists in your namespace.
26
+ */
27
+ publish(data: ArtifactCreateRequest): Promise<Response<ArtifactDTO>>;
28
+ /**
29
+ * Update metadata (title, description, favicon, shared version pin)
30
+ */
31
+ update(id: string, data: ArtifactUpdateRequest): Promise<Response<ArtifactDTO>>;
32
+ /**
33
+ * Publish a new version of an existing artifact
34
+ */
35
+ publishVersion(id: string, data: ArtifactPublishRequest): Promise<Response<ArtifactDTO>>;
36
+ /**
37
+ * Delete an artifact
38
+ */
39
+ delete(id: string): Promise<Response<void>>;
40
+ /**
41
+ * List versions (newest first)
42
+ */
43
+ listVersions(id: string, params?: Partial<CursorListRequest>): Promise<Response<CursorListResponse<ArtifactVersionDTO>>>;
44
+ /**
45
+ * Get version metadata (md5, size, hash — no body)
46
+ */
47
+ getVersion(id: string, versionId: string): Promise<Response<ArtifactVersionDTO>>;
48
+ /**
49
+ * Get the page source. Omit versionId for the viewer-facing version.
50
+ */
51
+ getContent(id: string, versionId?: string): Promise<Response<ArtifactContentResponse>>;
52
+ /**
53
+ * Pin the version viewers see. Pass an empty string to always share latest.
54
+ */
55
+ setSharedVersion(id: string, versionId: string): Promise<Response<ArtifactDTO>>;
56
+ /**
57
+ * Transfer ownership
58
+ */
59
+ transferOwnership(id: string, newTeamId: string): Promise<Response<ArtifactDTO>>;
60
+ /**
61
+ * Update visibility (private, team, org, unlisted, public)
62
+ */
63
+ updateVisibility(id: string, visibility: string): Promise<Response<ArtifactDTO>>;
64
+ /**
65
+ * URL of the rendered page (wrapped document under the artifact CSP).
66
+ * Fetch it with credentials and load into a sandboxed iframe via srcdoc.
67
+ */
68
+ renderUrl(id: string, options?: {
69
+ versionId?: string;
70
+ theme?: 'dark' | 'light';
71
+ }): string;
72
+ }
@@ -0,0 +1,116 @@
1
+ /** Encode UTF-8 page source as base64 so edge firewalls accept <script> in JSON bodies. */
2
+ function encodeContent(content) {
3
+ if (typeof Buffer !== 'undefined') {
4
+ return Buffer.from(content, 'utf8').toString('base64');
5
+ }
6
+ const bytes = new TextEncoder().encode(content);
7
+ let binary = '';
8
+ for (let i = 0; i < bytes.length; i += 0x8000) {
9
+ binary += String.fromCharCode(...bytes.subarray(i, i + 0x8000));
10
+ }
11
+ return btoa(binary);
12
+ }
13
+ /**
14
+ * Artifacts API — small self-contained HTML/Markdown pages published to a
15
+ * URL, versioned, permissioned, and shareable.
16
+ */
17
+ export class ArtifactsAPI {
18
+ constructor(http) {
19
+ this.http = http;
20
+ }
21
+ /**
22
+ * List artifacts with cursor-based pagination
23
+ */
24
+ async list(params) {
25
+ return this.http.request('post', '/artifacts/list', { data: params });
26
+ }
27
+ /**
28
+ * Get an artifact by ID or short ID
29
+ */
30
+ async get(id) {
31
+ return this.http.request('get', `/artifacts/${id}`);
32
+ }
33
+ /**
34
+ * Get an artifact by namespace/name
35
+ */
36
+ async getByName(namespace, name) {
37
+ return this.http.request('get', `/artifacts/${namespace}/${name}`);
38
+ }
39
+ /**
40
+ * Publish an artifact. Creates it, or publishes a new version when an
41
+ * artifact with the same name already exists in your namespace.
42
+ */
43
+ async publish(data) {
44
+ const body = { ...data, content: encodeContent(data.content), content_encoding: 'base64' };
45
+ return this.http.request('post', '/artifacts', { data: body });
46
+ }
47
+ /**
48
+ * Update metadata (title, description, favicon, shared version pin)
49
+ */
50
+ async update(id, data) {
51
+ return this.http.request('post', `/artifacts/${id}`, { data });
52
+ }
53
+ /**
54
+ * Publish a new version of an existing artifact
55
+ */
56
+ async publishVersion(id, data) {
57
+ const body = { ...data, content: encodeContent(data.content), content_encoding: 'base64' };
58
+ return this.http.request('post', `/artifacts/${id}/versions`, { data: body });
59
+ }
60
+ /**
61
+ * Delete an artifact
62
+ */
63
+ async delete(id) {
64
+ return this.http.request('delete', `/artifacts/${id}`);
65
+ }
66
+ /**
67
+ * List versions (newest first)
68
+ */
69
+ async listVersions(id, params) {
70
+ return this.http.request('post', `/artifacts/${id}/versions/list`, { data: params });
71
+ }
72
+ /**
73
+ * Get version metadata (md5, size, hash — no body)
74
+ */
75
+ async getVersion(id, versionId) {
76
+ return this.http.request('get', `/artifacts/${id}/versions/${versionId}`);
77
+ }
78
+ /**
79
+ * Get the page source. Omit versionId for the viewer-facing version.
80
+ */
81
+ async getContent(id, versionId) {
82
+ const path = versionId ? `/artifacts/${id}/versions/${versionId}/content` : `/artifacts/${id}/content`;
83
+ return this.http.request('get', path);
84
+ }
85
+ /**
86
+ * Pin the version viewers see. Pass an empty string to always share latest.
87
+ */
88
+ async setSharedVersion(id, versionId) {
89
+ return this.http.request('post', `/artifacts/${id}`, { data: { shared_version_id: versionId } });
90
+ }
91
+ /**
92
+ * Transfer ownership
93
+ */
94
+ async transferOwnership(id, newTeamId) {
95
+ return this.http.request('post', `/artifacts/${id}/transfer`, { data: { team_id: newTeamId } });
96
+ }
97
+ /**
98
+ * Update visibility (private, team, org, unlisted, public)
99
+ */
100
+ async updateVisibility(id, visibility) {
101
+ return this.http.request('post', `/artifacts/${id}/visibility`, { data: { visibility } });
102
+ }
103
+ /**
104
+ * URL of the rendered page (wrapped document under the artifact CSP).
105
+ * Fetch it with credentials and load into a sandboxed iframe via srcdoc.
106
+ */
107
+ renderUrl(id, options) {
108
+ const params = new URLSearchParams();
109
+ if (options?.versionId)
110
+ params.set('version', options.versionId);
111
+ if (options?.theme)
112
+ params.set('theme', options.theme);
113
+ const qs = params.toString();
114
+ return `${this.http.getBaseUrl()}/artifacts/${id}/render${qs ? `?${qs}` : ''}`;
115
+ }
116
+ }
package/dist/delta.d.ts CHANGED
@@ -8,6 +8,14 @@ export declare class DeltaAccumulator {
8
8
  private tags;
9
9
  private registry;
10
10
  constructor(tags: FieldTags, registry?: FieldTagsRegistry);
11
+ /**
12
+ * Discard everything accumulated so far. Required at a message boundary: the
13
+ * accumulator is cumulative, so without a reset the next message's deltas
14
+ * merge into the previous message's state. Concat makes that invisible for
15
+ * text — appending "" leaves the old text in place, so a tool-call-only turn
16
+ * serves the previous message's answer as its own.
17
+ */
18
+ reset(): void;
11
19
  seed(output: Record<string, any>): void;
12
20
  apply(delta: Record<string, any>): void;
13
21
  toOutput(): Record<string, any>;
package/dist/delta.js CHANGED
@@ -57,6 +57,16 @@ export class DeltaAccumulator {
57
57
  this.tags = tags;
58
58
  this.registry = registry;
59
59
  }
60
+ /**
61
+ * Discard everything accumulated so far. Required at a message boundary: the
62
+ * accumulator is cumulative, so without a reset the next message's deltas
63
+ * merge into the previous message's state. Concat makes that invisible for
64
+ * text — appending "" leaves the old text in place, so a tool-call-only turn
65
+ * serves the previous message's answer as its own.
66
+ */
67
+ reset() {
68
+ this.state = {};
69
+ }
60
70
  seed(output) {
61
71
  for (const [key, value] of Object.entries(output)) {
62
72
  if (value != null)
package/dist/index.d.ts CHANGED
@@ -15,6 +15,7 @@ export { FlowsAPI } from './api/flows';
15
15
  export { FlowRunsAPI } from './api/flow-runs';
16
16
  export { EnginesAPI } from './api/engines';
17
17
  export { KnowledgeAPI, SkillsAPI } from './api/knowledge';
18
+ export { ArtifactsAPI } from './api/artifacts';
18
19
  export { TeamsAPI, type MeResponse } from './api/teams';
19
20
  export { SecretsAPI } from './api/secrets';
20
21
  export { ApiKeysAPI } from './api/api-keys';
@@ -42,6 +43,7 @@ import { FlowsAPI } from './api/flows';
42
43
  import { FlowRunsAPI } from './api/flow-runs';
43
44
  import { EnginesAPI } from './api/engines';
44
45
  import { KnowledgeAPI, SkillsAPI } from './api/knowledge';
46
+ import { ArtifactsAPI } from './api/artifacts';
45
47
  import { TeamsAPI } from './api/teams';
46
48
  import { SecretsAPI } from './api/secrets';
47
49
  import { ApiKeysAPI } from './api/api-keys';
@@ -91,6 +93,7 @@ export declare class Inference {
91
93
  readonly flowRuns: FlowRunsAPI;
92
94
  readonly engines: EnginesAPI;
93
95
  readonly knowledge: KnowledgeAPI;
96
+ readonly artifacts: ArtifactsAPI;
94
97
  readonly skills: SkillsAPI;
95
98
  readonly teams: TeamsAPI;
96
99
  readonly secrets: SecretsAPI;
package/dist/index.js CHANGED
@@ -17,6 +17,7 @@ export { FlowsAPI } from './api/flows';
17
17
  export { FlowRunsAPI } from './api/flow-runs';
18
18
  export { EnginesAPI } from './api/engines';
19
19
  export { KnowledgeAPI, SkillsAPI } from './api/knowledge';
20
+ export { ArtifactsAPI } from './api/artifacts';
20
21
  export { TeamsAPI } from './api/teams';
21
22
  export { SecretsAPI } from './api/secrets';
22
23
  export { ApiKeysAPI } from './api/api-keys';
@@ -48,6 +49,7 @@ import { FlowsAPI } from './api/flows';
48
49
  import { FlowRunsAPI } from './api/flow-runs';
49
50
  import { EnginesAPI } from './api/engines';
50
51
  import { KnowledgeAPI, SkillsAPI } from './api/knowledge';
52
+ import { ArtifactsAPI } from './api/artifacts';
51
53
  import { TeamsAPI } from './api/teams';
52
54
  import { SecretsAPI } from './api/secrets';
53
55
  import { ApiKeysAPI } from './api/api-keys';
@@ -89,6 +91,7 @@ export class Inference {
89
91
  this.flowRuns = new FlowRunsAPI(this.http);
90
92
  this.engines = new EnginesAPI(this.http);
91
93
  this.knowledge = new KnowledgeAPI(this.http);
94
+ this.artifacts = new ArtifactsAPI(this.http);
92
95
  this.skills = new SkillsAPI(this.http);
93
96
  this.teams = new TeamsAPI(this.http);
94
97
  this.secrets = new SecretsAPI(this.http);