@runtypelabs/sdk 2.2.0 → 4.0.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.
package/dist/index.mjs CHANGED
@@ -11,9 +11,12 @@ var __export = (target, all) => {
11
11
  // src/stream-utils.ts
12
12
  var stream_utils_exports = {};
13
13
  __export(stream_utils_exports, {
14
+ flowErrorMessage: () => flowErrorMessage,
14
15
  parseFinalBuffer: () => parseFinalBuffer,
15
16
  parseSSEChunk: () => parseSSEChunk,
16
17
  processStream: () => processStream,
18
+ stepDeltaText: () => stepDeltaText,
19
+ stepDisplayName: () => stepDisplayName,
17
20
  streamEvents: () => streamEvents
18
21
  });
19
22
  function parseSSEChunk(chunk, buffer) {
@@ -134,7 +137,7 @@ async function processStream(response, callbacks = {}) {
134
137
  try {
135
138
  const event = JSON.parse(eventStr);
136
139
  handleEvent(event, callbacks, results, flowSummary);
137
- } catch (parseError) {
140
+ } catch {
138
141
  console.warn("Failed to parse SSE event:", eventStr);
139
142
  }
140
143
  }
@@ -144,7 +147,7 @@ async function processStream(response, callbacks = {}) {
144
147
  try {
145
148
  const event = JSON.parse(finalEvent);
146
149
  handleEvent(event, callbacks, results, flowSummary);
147
- } catch (parseError) {
150
+ } catch {
148
151
  }
149
152
  }
150
153
  } catch (error) {
@@ -166,6 +169,15 @@ async function processStream(response, callbacks = {}) {
166
169
  success: flowSummary.success ?? true
167
170
  };
168
171
  }
172
+ function stepDeltaText(event) {
173
+ return event.text ?? event.delta ?? "";
174
+ }
175
+ function stepDisplayName(event) {
176
+ return event.name ?? event.stepName ?? "";
177
+ }
178
+ function flowErrorMessage(event) {
179
+ return typeof event.error === "string" ? event.error : JSON.stringify(event.error);
180
+ }
169
181
  function handleEvent(event, callbacks, results, summary) {
170
182
  switch (event.type) {
171
183
  case "flow_start":
@@ -178,24 +190,26 @@ function handleEvent(event, callbacks, results, summary) {
178
190
  callbacks.onStepStart?.(event);
179
191
  break;
180
192
  case "step_delta":
181
- callbacks.onStepDelta?.(event.text, event);
193
+ callbacks.onStepDelta?.(stepDeltaText(event), event);
182
194
  break;
183
- case "step_complete":
184
- results.set(event.name, event.result);
195
+ case "step_complete": {
196
+ results.set(stepDisplayName(event), event.result);
185
197
  callbacks.onStepComplete?.(event.result, event);
186
198
  break;
199
+ }
187
200
  case "flow_complete":
188
201
  summary.totalSteps = event.totalSteps;
189
202
  summary.successfulSteps = event.successfulSteps;
190
203
  summary.failedSteps = event.failedSteps;
191
204
  summary.executionTime = event.executionTime;
192
- summary.success = event.failedSteps === 0;
205
+ summary.success = event.success ?? (event.failedSteps ?? 0) === 0;
193
206
  callbacks.onFlowComplete?.(event);
194
207
  break;
195
- case "flow_error":
208
+ case "flow_error": {
196
209
  summary.success = false;
197
- callbacks.onError?.(new Error(event.error));
210
+ callbacks.onError?.(new Error(flowErrorMessage(event)));
198
211
  break;
212
+ }
199
213
  case "flow_await":
200
214
  break;
201
215
  case "step_await":
@@ -953,22 +967,24 @@ var RuntypeFlowBuilder = class {
953
967
  onFlowComplete: (event) => callbacks?.onFlowComplete?.(event),
954
968
  onError: (error) => callbacks?.onError?.(error)
955
969
  };
956
- const { streamEvents: streamEvents2 } = await Promise.resolve().then(() => (init_stream_utils(), stream_utils_exports));
970
+ const { streamEvents: streamEvents2, stepDeltaText: stepDeltaText2, stepDisplayName: stepDisplayName2, flowErrorMessage: flowErrorMessage2 } = await Promise.resolve().then(() => (init_stream_utils(), stream_utils_exports));
957
971
  try {
958
972
  for await (const event of streamEvents2(response)) {
959
973
  const awaitEvent = event;
960
974
  if (awaitEvent.type === "flow_await") {
975
+ const prev = pausedState;
961
976
  pausedState = {
962
- toolName: awaitEvent.toolName || "",
963
- parameters: awaitEvent.parameters,
964
- executionId: awaitEvent.executionId || ""
977
+ toolName: awaitEvent.toolName || prev?.toolName || "",
978
+ parameters: awaitEvent.parameters ?? prev?.parameters,
979
+ executionId: awaitEvent.executionId || prev?.executionId || ""
965
980
  };
966
981
  }
967
982
  if (awaitEvent.type === "step_await") {
983
+ const prev = pausedState;
968
984
  pausedState = {
969
- toolName: awaitEvent.toolName || "",
970
- parameters: awaitEvent.parameters,
971
- executionId: awaitEvent.executionId || ""
985
+ toolName: awaitEvent.toolName || prev?.toolName || "",
986
+ parameters: awaitEvent.parameters ?? prev?.parameters,
987
+ executionId: awaitEvent.executionId || prev?.executionId || ""
972
988
  };
973
989
  }
974
990
  switch (event.type) {
@@ -979,10 +995,10 @@ var RuntypeFlowBuilder = class {
979
995
  wrappedCallbacks.onStepStart?.(event);
980
996
  break;
981
997
  case "step_delta":
982
- wrappedCallbacks.onStepDelta?.(event.text, event);
998
+ wrappedCallbacks.onStepDelta?.(stepDeltaText2(event), event);
983
999
  break;
984
1000
  case "step_complete": {
985
- accumulatedSummary.results?.set(event.name, event.result);
1001
+ accumulatedSummary.results?.set(stepDisplayName2(event), event.result);
986
1002
  wrappedCallbacks.onStepComplete?.(event.result, event);
987
1003
  break;
988
1004
  }
@@ -990,7 +1006,7 @@ var RuntypeFlowBuilder = class {
990
1006
  wrappedCallbacks.onFlowComplete?.(event);
991
1007
  break;
992
1008
  case "flow_error":
993
- wrappedCallbacks.onError?.(new Error(event.error));
1009
+ wrappedCallbacks.onError?.(new Error(flowErrorMessage2(event)));
994
1010
  break;
995
1011
  }
996
1012
  }
@@ -1652,6 +1668,175 @@ var PromptsNamespace = class {
1652
1668
  }
1653
1669
  };
1654
1670
 
1671
+ // src/skills-namespace.ts
1672
+ var SkillProposalsNamespace = class {
1673
+ constructor(getClient) {
1674
+ this.getClient = getClient;
1675
+ }
1676
+ /**
1677
+ * List pending skill proposals for the authenticated owner.
1678
+ *
1679
+ * @example
1680
+ * ```typescript
1681
+ * const pending = await Runtype.skills.proposals.list()
1682
+ * ```
1683
+ */
1684
+ async list() {
1685
+ const client = this.getClient();
1686
+ const res = await client.get("/skill-proposals");
1687
+ return res.data;
1688
+ }
1689
+ /**
1690
+ * Approve a pending proposal — publishes the proposed skill version.
1691
+ *
1692
+ * @example
1693
+ * ```typescript
1694
+ * const proposal = await Runtype.skills.proposals.approve('skprop_123')
1695
+ * ```
1696
+ */
1697
+ async approve(proposalId) {
1698
+ const client = this.getClient();
1699
+ const res = await client.post(
1700
+ `/skill-proposals/${proposalId}/approve`
1701
+ );
1702
+ return res.proposal;
1703
+ }
1704
+ /**
1705
+ * Reject a pending proposal with an optional reason.
1706
+ *
1707
+ * @example
1708
+ * ```typescript
1709
+ * await Runtype.skills.proposals.reject('skprop_123', 'Capabilities too broad')
1710
+ * ```
1711
+ */
1712
+ async reject(proposalId, reason) {
1713
+ const client = this.getClient();
1714
+ const res = await client.post(
1715
+ `/skill-proposals/${proposalId}/reject`,
1716
+ reason !== void 0 ? { reason } : {}
1717
+ );
1718
+ return res.proposal;
1719
+ }
1720
+ };
1721
+ var SkillsNamespace = class {
1722
+ constructor(getClient) {
1723
+ this.getClient = getClient;
1724
+ this.proposals = new SkillProposalsNamespace(getClient);
1725
+ }
1726
+ /**
1727
+ * Create a skill from a SKILL.md string (`markdown`) or a structured manifest
1728
+ * (`frontmatter` + `body`). Pass `publish: true` to publish the first version
1729
+ * immediately; otherwise it lands as a draft.
1730
+ */
1731
+ async create(input) {
1732
+ const client = this.getClient();
1733
+ return client.post("/skills", input);
1734
+ }
1735
+ /**
1736
+ * List skills for the authenticated owner, optionally filtered by status.
1737
+ *
1738
+ * @example
1739
+ * ```typescript
1740
+ * const active = await Runtype.skills.list({ status: 'active' })
1741
+ * ```
1742
+ */
1743
+ async list(params) {
1744
+ const client = this.getClient();
1745
+ const res = await client.get("/skills", params);
1746
+ return res.data;
1747
+ }
1748
+ /**
1749
+ * Get a skill and its full version history.
1750
+ *
1751
+ * @example
1752
+ * ```typescript
1753
+ * const { skill, versions } = await Runtype.skills.get('skill_123')
1754
+ * ```
1755
+ */
1756
+ async get(skillId) {
1757
+ const client = this.getClient();
1758
+ return client.get(`/skills/${skillId}`);
1759
+ }
1760
+ /**
1761
+ * Append a new version to an existing skill from an updated manifest. Pass
1762
+ * `publish: true` to publish the new version immediately.
1763
+ */
1764
+ async update(skillId, input) {
1765
+ const client = this.getClient();
1766
+ const res = await client.put(`/skills/${skillId}`, input);
1767
+ return res.version;
1768
+ }
1769
+ /**
1770
+ * Delete a skill (and its versions + bindings, via cascade).
1771
+ */
1772
+ async delete(skillId) {
1773
+ const client = this.getClient();
1774
+ await client.delete(`/skills/${skillId}`);
1775
+ }
1776
+ /**
1777
+ * List a skill's versions, newest first.
1778
+ */
1779
+ async listVersions(skillId) {
1780
+ const client = this.getClient();
1781
+ const res = await client.get(`/skills/${skillId}/versions`);
1782
+ return res.data;
1783
+ }
1784
+ /**
1785
+ * Publish a specific version of a skill.
1786
+ *
1787
+ * @example
1788
+ * ```typescript
1789
+ * await Runtype.skills.publishVersion('skill_123', 'skillver_456')
1790
+ * ```
1791
+ */
1792
+ async publishVersion(skillId, versionId) {
1793
+ const client = this.getClient();
1794
+ await client.post(`/skills/${skillId}/versions/${versionId}/publish`);
1795
+ }
1796
+ /**
1797
+ * Import a single SKILL.md document. The imported skill lands with
1798
+ * `trustLevel: 'imported'` and a draft version.
1799
+ *
1800
+ * @example
1801
+ * ```typescript
1802
+ * const { skill } = await Runtype.skills.import(skillMarkdown)
1803
+ * ```
1804
+ */
1805
+ async import(markdown) {
1806
+ const client = this.getClient();
1807
+ return client.post("/skills/import", { markdown });
1808
+ }
1809
+ /**
1810
+ * Bind a skill to an agent. Both the agent and the skill must be owned by the
1811
+ * caller.
1812
+ */
1813
+ async bind(input) {
1814
+ const client = this.getClient();
1815
+ const res = await client.post("/skills/bind", input);
1816
+ return res.binding;
1817
+ }
1818
+ /**
1819
+ * Remove a skill binding by its binding id.
1820
+ */
1821
+ async unbind(bindingId) {
1822
+ const client = this.getClient();
1823
+ await client.delete(`/skills/bindings/${bindingId}`);
1824
+ }
1825
+ /**
1826
+ * List an agent's skill bindings.
1827
+ *
1828
+ * @example
1829
+ * ```typescript
1830
+ * const bindings = await Runtype.skills.listBindings('agent_123')
1831
+ * ```
1832
+ */
1833
+ async listBindings(agentId) {
1834
+ const client = this.getClient();
1835
+ const res = await client.get("/skills/bindings", { agentId });
1836
+ return res.data;
1837
+ }
1838
+ };
1839
+
1655
1840
  // src/transform.ts
1656
1841
  function transformResponse(data) {
1657
1842
  return data;
@@ -1699,6 +1884,7 @@ var RuntypeClient = class {
1699
1884
  /**
1700
1885
  * Generic GET request
1701
1886
  */
1887
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- accepts typed list-param interfaces (no index signature); `unknown` would reject them
1702
1888
  async get(path, params) {
1703
1889
  const url = this.buildUrl(path, params);
1704
1890
  const response = await this.makeRequest(url, {
@@ -1719,6 +1905,29 @@ var RuntypeClient = class {
1719
1905
  });
1720
1906
  return this.transformResponse(response);
1721
1907
  }
1908
+ /**
1909
+ * Generic PUT request
1910
+ */
1911
+ async put(path, data) {
1912
+ const url = this.buildUrl(path);
1913
+ const response = await this.makeRequest(url, {
1914
+ method: "PUT",
1915
+ headers: this.headers,
1916
+ body: data ? JSON.stringify(data) : void 0
1917
+ });
1918
+ return this.transformResponse(response);
1919
+ }
1920
+ /**
1921
+ * Generic DELETE request
1922
+ */
1923
+ async delete(path) {
1924
+ const url = this.buildUrl(path);
1925
+ const response = await this.makeRequest(url, {
1926
+ method: "DELETE",
1927
+ headers: this.headers
1928
+ });
1929
+ return this.transformResponse(response);
1930
+ }
1722
1931
  /**
1723
1932
  * Generic request that returns raw Response for streaming
1724
1933
  */
@@ -1745,6 +1954,7 @@ var RuntypeClient = class {
1745
1954
  /**
1746
1955
  * Build full URL with query parameters
1747
1956
  */
1957
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- mirrors get()'s permissive params type
1748
1958
  buildUrl(path, params) {
1749
1959
  const base = this.baseUrl.endsWith("/") ? this.baseUrl : `${this.baseUrl}/`;
1750
1960
  const relPath = path.startsWith("/") ? path.slice(1) : path;
@@ -1970,6 +2180,25 @@ var Runtype = class {
1970
2180
  static get prompts() {
1971
2181
  return new PromptsNamespace(() => this.getClient());
1972
2182
  }
2183
+ /**
2184
+ * Skills namespace - Manage Agent Skills (admin/control plane)
2185
+ *
2186
+ * @example
2187
+ * ```typescript
2188
+ * // Create a published skill from a SKILL.md document
2189
+ * const { skill } = await Runtype.skills.create({ markdown: skillMd, publish: true })
2190
+ *
2191
+ * // Bind it to an agent
2192
+ * await Runtype.skills.bind({ agentId: 'agent_123', skillId: skill.id })
2193
+ *
2194
+ * // Review agent-authored proposals
2195
+ * const pending = await Runtype.skills.proposals.list()
2196
+ * await Runtype.skills.proposals.approve(pending[0].id)
2197
+ * ```
2198
+ */
2199
+ static get skills() {
2200
+ return new SkillsNamespace(() => this.getClient());
2201
+ }
1973
2202
  };
1974
2203
 
1975
2204
  // src/generated-tool-gate.ts
@@ -4162,12 +4391,6 @@ var ToolsEndpoint = class {
4162
4391
  async test(id, data) {
4163
4392
  return this.client.post(`/tools/${id}/test`, data);
4164
4393
  }
4165
- /**
4166
- * Get tool executions for a specific tool
4167
- */
4168
- async getExecutions(toolId, params) {
4169
- return this.client.get(`/tools/${toolId}/executions`, params);
4170
- }
4171
4394
  /**
4172
4395
  * Get AI SDK compatible tool schemas
4173
4396
  */
@@ -8211,7 +8434,7 @@ var RuntypeClient2 = class {
8211
8434
  onFlowComplete: (event) => callbacks?.onFlowComplete?.(event),
8212
8435
  onError: (error) => callbacks?.onError?.(error)
8213
8436
  };
8214
- const { streamEvents: streamEvents2 } = await Promise.resolve().then(() => (init_stream_utils(), stream_utils_exports));
8437
+ const { streamEvents: streamEvents2, stepDeltaText: stepDeltaText2, stepDisplayName: stepDisplayName2, flowErrorMessage: flowErrorMessage2 } = await Promise.resolve().then(() => (init_stream_utils(), stream_utils_exports));
8215
8438
  const summary = {
8216
8439
  results: /* @__PURE__ */ new Map(),
8217
8440
  success: true
@@ -8220,19 +8443,23 @@ var RuntypeClient2 = class {
8220
8443
  for await (const event of streamEvents2(response)) {
8221
8444
  if (event.type === "flow_await") {
8222
8445
  const pausedEvent = event;
8223
- pausedState = {
8224
- ...pausedState ?? {},
8225
- toolName: pausedEvent.toolName,
8226
- executionId: pausedEvent.executionId
8446
+ const prev = pausedState;
8447
+ const next = {
8448
+ toolName: pausedEvent.toolName ?? prev?.toolName ?? "",
8449
+ executionId: pausedEvent.executionId ?? prev?.executionId ?? "",
8450
+ parameters: prev?.parameters
8227
8451
  };
8452
+ pausedState = next;
8228
8453
  }
8229
8454
  if (event.type === "step_await") {
8230
8455
  const pausedEvent = event;
8231
- pausedState = {
8232
- toolName: pausedEvent.toolName,
8456
+ const prev = pausedState;
8457
+ const next = {
8458
+ toolName: typeof pausedEvent.toolName === "string" ? pausedEvent.toolName : prev?.toolName ?? "",
8233
8459
  parameters: pausedEvent.parameters,
8234
- executionId: pausedEvent.executionId
8460
+ executionId: typeof pausedEvent.executionId === "string" ? pausedEvent.executionId : prev?.executionId ?? ""
8235
8461
  };
8462
+ pausedState = next;
8236
8463
  }
8237
8464
  switch (event.type) {
8238
8465
  case "flow_start":
@@ -8242,10 +8469,10 @@ var RuntypeClient2 = class {
8242
8469
  wrappedCallbacks.onStepStart?.(event);
8243
8470
  break;
8244
8471
  case "step_delta":
8245
- wrappedCallbacks.onStepDelta?.(event.text, event);
8472
+ wrappedCallbacks.onStepDelta?.(stepDeltaText2(event), event);
8246
8473
  break;
8247
8474
  case "step_complete": {
8248
- summary.results?.set(event.name, event.result);
8475
+ summary.results?.set(stepDisplayName2(event), event.result);
8249
8476
  wrappedCallbacks.onStepComplete?.(event.result, event);
8250
8477
  break;
8251
8478
  }
@@ -8253,7 +8480,7 @@ var RuntypeClient2 = class {
8253
8480
  wrappedCallbacks.onFlowComplete?.(event);
8254
8481
  break;
8255
8482
  case "flow_error":
8256
- wrappedCallbacks.onError?.(new Error(event.error));
8483
+ wrappedCallbacks.onError?.(new Error(flowErrorMessage2(event)));
8257
8484
  break;
8258
8485
  }
8259
8486
  }
@@ -9112,6 +9339,8 @@ export {
9112
9339
  STEP_TYPE_TO_METHOD,
9113
9340
  SchedulesEndpoint,
9114
9341
  SecretsEndpoint,
9342
+ SkillProposalsNamespace,
9343
+ SkillsNamespace,
9115
9344
  SurfacesEndpoint,
9116
9345
  ToolsEndpoint,
9117
9346
  UsersEndpoint,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runtypelabs/sdk",
3
- "version": "2.2.0",
3
+ "version": "4.0.0",
4
4
  "type": "module",
5
5
  "description": "TypeScript SDK for the Runtype API with fluent methods. Use it to quickly realize AI products, agents, and workflows.",
6
6
  "main": "dist/index.cjs",
@@ -24,9 +24,10 @@
24
24
  ],
25
25
  "dependencies": {},
26
26
  "devDependencies": {
27
+ "openapi-typescript": "^7.13.0",
27
28
  "tsup": "^8.0.2",
28
29
  "typescript": "^5.3.3",
29
- "vitest": "^4.0.18"
30
+ "vitest": "^4.1.0"
30
31
  },
31
32
  "keywords": [
32
33
  "runtype",
@@ -64,6 +65,8 @@
64
65
  "typecheck": "tsc --noEmit",
65
66
  "clean": "rm -rf dist",
66
67
  "test": "vitest run",
67
- "test:watch": "vitest watch"
68
+ "test:watch": "vitest watch",
69
+ "generate:types": "openapi-typescript ../../apps/api/openapi/public/v1/openapi.json -o src/generated/openapi-types.ts",
70
+ "generate:types:check": "pnpm run generate:types && git diff --exit-code src/generated/openapi-types.ts"
68
71
  }
69
72
  }