@cadraos/sdk 0.3.14-p46.3 → 0.3.14

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.
Files changed (52) hide show
  1. package/README.md +104 -53
  2. package/dist/ai-functions/react/index.cjs +176 -0
  3. package/dist/ai-functions/react/index.cjs.map +1 -0
  4. package/dist/ai-functions/react/index.d.cts +129 -0
  5. package/dist/ai-functions/react/index.d.ts +129 -0
  6. package/dist/ai-functions/react/index.js +153 -0
  7. package/dist/ai-functions/react/index.js.map +1 -0
  8. package/dist/ai-functions/server/index.cjs +296 -0
  9. package/dist/ai-functions/server/index.cjs.map +1 -0
  10. package/dist/ai-functions/server/index.d.cts +334 -0
  11. package/dist/ai-functions/server/index.d.ts +334 -0
  12. package/dist/ai-functions/server/index.js +284 -0
  13. package/dist/ai-functions/server/index.js.map +1 -0
  14. package/dist/board-host/index.cjs +217 -129
  15. package/dist/board-host/index.cjs.map +1 -1
  16. package/dist/board-host/index.d.cts +96 -1
  17. package/dist/board-host/index.d.ts +96 -1
  18. package/dist/board-host/index.js +218 -131
  19. package/dist/board-host/index.js.map +1 -1
  20. package/dist/board-host/server/index.d.cts +44 -0
  21. package/dist/board-host/server/index.d.ts +44 -0
  22. package/dist/chat/index.cjs +299 -17
  23. package/dist/chat/index.cjs.map +1 -1
  24. package/dist/chat/index.d.cts +225 -0
  25. package/dist/chat/index.d.ts +225 -0
  26. package/dist/chat/index.js +299 -17
  27. package/dist/chat/index.js.map +1 -1
  28. package/dist/index.cjs +221 -3
  29. package/dist/index.cjs.map +1 -1
  30. package/dist/index.d.cts +286 -1
  31. package/dist/index.d.ts +286 -1
  32. package/dist/index.js +215 -4
  33. package/dist/index.js.map +1 -1
  34. package/dist/kanban/engine/index.cjs +774 -683
  35. package/dist/kanban/engine/index.cjs.map +1 -1
  36. package/dist/kanban/engine/index.d.cts +90 -1
  37. package/dist/kanban/engine/index.d.ts +90 -1
  38. package/dist/kanban/engine/index.js +774 -684
  39. package/dist/kanban/engine/index.js.map +1 -1
  40. package/dist/kanban/index.cjs +214 -3
  41. package/dist/kanban/index.cjs.map +1 -1
  42. package/dist/kanban/index.d.cts +252 -0
  43. package/dist/kanban/index.d.ts +252 -0
  44. package/dist/kanban/index.js +214 -3
  45. package/dist/kanban/index.js.map +1 -1
  46. package/dist/teams/index.cjs +214 -3
  47. package/dist/teams/index.cjs.map +1 -1
  48. package/dist/teams/index.d.cts +225 -0
  49. package/dist/teams/index.d.ts +225 -0
  50. package/dist/teams/index.js +214 -3
  51. package/dist/teams/index.js.map +1 -1
  52. package/package.json +21 -1
@@ -3665,6 +3665,14 @@ var CadraError = class extends Error {
3665
3665
  details;
3666
3666
  /** Request ID from server (for debugging) */
3667
3667
  requestId;
3668
+ /**
3669
+ * The server's own `error.code` exactly as sent on the wire (e.g.
3670
+ * `FUNCTION_NOT_PUBLISHED`, `DUPLICATE_REQUEST`, `VARIABLE_TYPE`).
3671
+ * Populated by `parseApiError` for EVERY status. `code` keeps its historic
3672
+ * per-class values (`conflict`, `server_error`, `validation_error`, …) for
3673
+ * compatibility; branch on `serverCode` when you need the precise reason.
3674
+ */
3675
+ serverCode;
3668
3676
  constructor(message, code, status, details, requestId) {
3669
3677
  super(message);
3670
3678
  this.name = "CadraError";
@@ -3742,6 +3750,12 @@ function parseApiError(status, body, requestId) {
3742
3750
  const message = errorBody?.error?.message ?? "An error occurred";
3743
3751
  const code = errorBody?.error?.code ?? "unknown_error";
3744
3752
  const details = errorBody?.error?.details;
3753
+ const serverCode = typeof errorBody?.error?.code === "string" ? errorBody.error.code : void 0;
3754
+ const error = buildApiError(status, message, code, details, requestId);
3755
+ if (serverCode !== void 0) error.serverCode = serverCode;
3756
+ return error;
3757
+ }
3758
+ function buildApiError(status, message, code, details, requestId) {
3745
3759
  switch (status) {
3746
3760
  case 400:
3747
3761
  case 422: {
@@ -3777,6 +3791,42 @@ function parseApiError(status, body, requestId) {
3777
3791
  }
3778
3792
  }
3779
3793
 
3794
+ // src/errors/ai-function-errors.ts
3795
+ var AiFunctionDuplicateError = class extends ConflictError {
3796
+ /** The existing run's execution id. */
3797
+ executionId;
3798
+ /** The existing run's status (`running`, a terminal status, or `abandoned`). */
3799
+ runStatus;
3800
+ constructor(message, details, requestId) {
3801
+ super(message, details, requestId);
3802
+ this.name = "AiFunctionDuplicateError";
3803
+ this.serverCode = "DUPLICATE_REQUEST";
3804
+ this.executionId = typeof details?.executionId === "string" ? details.executionId : void 0;
3805
+ this.runStatus = typeof details?.status === "string" ? details.status : void 0;
3806
+ }
3807
+ };
3808
+ var AiFunctionChargedError = class extends CadraError {
3809
+ constructor(source) {
3810
+ super(source.message, source.code, source.status, source.details, source.requestId);
3811
+ this.name = "AiFunctionChargedError";
3812
+ this.serverCode = source.serverCode;
3813
+ }
3814
+ };
3815
+ var AiFunctionParameterError = class extends ValidationError {
3816
+ functionKey;
3817
+ issues;
3818
+ constructor(functionKey, issues) {
3819
+ super(
3820
+ `Invalid parameters for AI function "${functionKey}": ` + issues.map((i) => `${i.name} (${i.code})`).join(", "),
3821
+ issues.map((i) => ({ field: i.name, message: i.code })),
3822
+ { functionKey, issues }
3823
+ );
3824
+ this.name = "AiFunctionParameterError";
3825
+ this.functionKey = functionKey;
3826
+ this.issues = issues;
3827
+ }
3828
+ };
3829
+
3780
3830
  // src/utils/retry.ts
3781
3831
  var DEFAULT_RETRY_CONFIG = {
3782
3832
  maxRetries: 3,
@@ -3895,7 +3945,8 @@ var HttpClient = class {
3895
3945
  headers["Idempotency-Key"] = options.idempotencyKey;
3896
3946
  }
3897
3947
  const controller = new AbortController();
3898
- const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
3948
+ const timeoutMs = options.timeoutMs ?? this.config.timeout;
3949
+ const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
3899
3950
  try {
3900
3951
  const doFetch = this.config.fetch ?? fetch;
3901
3952
  const response = await doFetch(url, {
@@ -3931,7 +3982,7 @@ var HttpClient = class {
3931
3982
  } catch (error) {
3932
3983
  clearTimeout(timeoutId);
3933
3984
  if (error instanceof Error && error.name === "AbortError") {
3934
- throw new TimeoutError(`Request timed out after ${this.config.timeout}ms`);
3985
+ throw new TimeoutError(`Request timed out after ${options.timeoutMs ?? this.config.timeout}ms`);
3935
3986
  }
3936
3987
  if (error instanceof TypeError && error.message.includes("fetch")) {
3937
3988
  throw new NetworkError(`Network error: ${error.message}`);
@@ -3963,7 +4014,8 @@ var HttpClient = class {
3963
4014
  path,
3964
4015
  body,
3965
4016
  idempotencyKey: options?.idempotencyKey,
3966
- skipRetry: options?.skipRetry
4017
+ skipRetry: options?.skipRetry,
4018
+ timeoutMs: options?.timeoutMs
3967
4019
  });
3968
4020
  }
3969
4021
  /**
@@ -4712,6 +4764,10 @@ var ExecutionStreamControllerImpl = class {
4712
4764
  toolName,
4713
4765
  result: data.result,
4714
4766
  durationMs: data.durationMs ?? 0,
4767
+ // CAD-243: pass the producer's failure verdict through.
4768
+ ...data.isError === true ? { isError: true } : {},
4769
+ ...typeof data.status === "string" ? { status: data.status } : {},
4770
+ ...typeof data.error === "string" ? { error: data.error } : {},
4715
4771
  forwardedFrom: event.data._forwardedFrom,
4716
4772
  // CAD-87 S1-001 EventIdentity → (execId, seq) reducer dedup (S1-003).
4717
4773
  sourceExecutionId: data.sourceExecutionId ?? data.executionId,
@@ -6950,6 +7006,156 @@ var RemoteRunnersAPI = class extends BaseResourceAPI {
6950
7006
  }
6951
7007
  };
6952
7008
 
7009
+ // src/resources/ai-functions.ts
7010
+ var AI_FUNCTION_RUN_TIMEOUT_MS = 6e4;
7011
+ var AI_FUNCTION_DESCRIPTOR_TTL_MS = 6e4;
7012
+ function checkAiFunctionParameters(parameters, variables) {
7013
+ const issues = [];
7014
+ const declared = /* @__PURE__ */ new Set();
7015
+ for (const p of parameters) {
7016
+ declared.add(p.name);
7017
+ const has = Object.prototype.hasOwnProperty.call(variables, p.name);
7018
+ const value = has ? variables[p.name] : void 0;
7019
+ if (value === void 0 || value === null) {
7020
+ if (p.required) issues.push({ name: p.name, code: "missing" });
7021
+ continue;
7022
+ }
7023
+ switch (p.type) {
7024
+ case "number":
7025
+ if (typeof value !== "number" || !Number.isFinite(value)) {
7026
+ issues.push({ name: p.name, code: "type" });
7027
+ }
7028
+ break;
7029
+ case "boolean":
7030
+ if (typeof value !== "boolean") issues.push({ name: p.name, code: "type" });
7031
+ break;
7032
+ case "enum":
7033
+ if (typeof value !== "string") issues.push({ name: p.name, code: "type" });
7034
+ else if (p.options && !p.options.includes(value)) {
7035
+ issues.push({ name: p.name, code: "option" });
7036
+ }
7037
+ break;
7038
+ case "string":
7039
+ case "text":
7040
+ if (typeof value !== "string") issues.push({ name: p.name, code: "type" });
7041
+ else if (typeof p.maxLength === "number" && value.length > p.maxLength) {
7042
+ issues.push({ name: p.name, code: "too_long" });
7043
+ }
7044
+ break;
7045
+ case "image":
7046
+ if (typeof value !== "string") issues.push({ name: p.name, code: "type" });
7047
+ break;
7048
+ }
7049
+ }
7050
+ for (const name of Object.keys(variables)) {
7051
+ if (!declared.has(name)) issues.push({ name, code: "unknown" });
7052
+ }
7053
+ return issues;
7054
+ }
7055
+ var AiFunctionsAPI = class extends BaseResourceAPI {
7056
+ descriptorCache = /* @__PURE__ */ new Map();
7057
+ constructor(http) {
7058
+ super(http, "/api/v1/ai-functions");
7059
+ }
7060
+ /**
7061
+ * List the functions this org can call — the index (D27a). Each entry carries
7062
+ * the live version's typed parameters; never prompt text.
7063
+ */
7064
+ async list() {
7065
+ const data = await this.httpGet("");
7066
+ const functions = Array.isArray(data) ? data : data?.functions ?? [];
7067
+ for (const d of functions) this.cacheDescriptor(d);
7068
+ return functions;
7069
+ }
7070
+ /**
7071
+ * Get one function's descriptor by key (D27a).
7072
+ * `NotFoundError` (`FUNCTION_NOT_FOUND`) / `ConflictError` (`FUNCTION_NOT_PUBLISHED`).
7073
+ */
7074
+ async get(functionKey) {
7075
+ const data = await this.httpGet(
7076
+ `/${encodeURIComponent(functionKey)}`
7077
+ );
7078
+ const descriptor = data && typeof data === "object" && "function" in data && !("functionKey" in data) ? data.function : data;
7079
+ this.cacheDescriptor(descriptor, functionKey);
7080
+ return descriptor;
7081
+ }
7082
+ /**
7083
+ * Read one of this org's own runs (safe projection, §6.5).
7084
+ */
7085
+ async getRun(executionId) {
7086
+ return this.httpGet(`/runs/${encodeURIComponent(executionId)}`);
7087
+ }
7088
+ /** Forget cached descriptors (one key, or all). */
7089
+ clearDescriptorCache(functionKey) {
7090
+ if (functionKey) this.descriptorCache.delete(functionKey);
7091
+ else this.descriptorCache.clear();
7092
+ }
7093
+ async run(refOrKey, parametersOrOptions, shorthandOpts) {
7094
+ let ref;
7095
+ let options;
7096
+ if (typeof refOrKey === "string") {
7097
+ ref = { functionKey: refOrKey };
7098
+ options = { ...shorthandOpts ?? {}, variables: parametersOrOptions };
7099
+ } else {
7100
+ ref = refOrKey;
7101
+ options = parametersOrOptions;
7102
+ }
7103
+ const variables = options.variables ?? {};
7104
+ const functionKey = "functionKey" in ref ? ref.functionKey : void 0;
7105
+ const shouldCheck = functionKey !== void 0 && options.version === void 0 && options.validate !== false;
7106
+ if (shouldCheck) {
7107
+ const descriptor = await this.getCachedDescriptor(functionKey);
7108
+ const issues = checkAiFunctionParameters(descriptor.parameters, variables);
7109
+ if (issues.length > 0) {
7110
+ throw new AiFunctionParameterError(functionKey, issues);
7111
+ }
7112
+ }
7113
+ const body = {
7114
+ ref,
7115
+ variables,
7116
+ version: options.version,
7117
+ idempotencyKey: options.idempotencyKey ?? generateExecutionId(),
7118
+ params: options.params
7119
+ };
7120
+ try {
7121
+ return await this.httpPost("/run", body, {
7122
+ skipRetry: true,
7123
+ timeoutMs: AI_FUNCTION_RUN_TIMEOUT_MS
7124
+ });
7125
+ } catch (error) {
7126
+ throw this.mapRunError(error, functionKey);
7127
+ }
7128
+ }
7129
+ // ── internals ──────────────────────────────────────────────────────────────
7130
+ cacheDescriptor(descriptor, key) {
7131
+ if (!descriptor || typeof descriptor !== "object") return;
7132
+ const cacheKey = key ?? descriptor.functionKey;
7133
+ if (!cacheKey) return;
7134
+ this.descriptorCache.set(cacheKey, {
7135
+ descriptor,
7136
+ expiresAt: Date.now() + AI_FUNCTION_DESCRIPTOR_TTL_MS
7137
+ });
7138
+ }
7139
+ async getCachedDescriptor(functionKey) {
7140
+ const hit = this.descriptorCache.get(functionKey);
7141
+ if (hit && hit.expiresAt > Date.now()) return hit.descriptor;
7142
+ return this.get(functionKey);
7143
+ }
7144
+ mapRunError(error, functionKey) {
7145
+ if (!(error instanceof CadraError)) return error;
7146
+ if (error.serverCode === "DUPLICATE_REQUEST") {
7147
+ return new AiFunctionDuplicateError(error.message, error.details, error.requestId);
7148
+ }
7149
+ if (error.details?.charged === true) {
7150
+ return new AiFunctionChargedError(error);
7151
+ }
7152
+ if (functionKey && error.serverCode?.startsWith("VARIABLE_")) {
7153
+ this.descriptorCache.delete(functionKey);
7154
+ }
7155
+ return error;
7156
+ }
7157
+ };
7158
+
6953
7159
  // src/client.ts
6954
7160
  var DEFAULT_BASE_URL = "https://api.cadraos.com";
6955
7161
  var DEFAULT_TIMEOUT = 3e4;
@@ -6996,6 +7202,10 @@ var CadraClient = class {
6996
7202
  * Remote runner operations (list)
6997
7203
  */
6998
7204
  remoteRunners;
7205
+ /**
7206
+ * AI function operations (list, get, run, getRun) — p93
7207
+ */
7208
+ aiFunctions;
6999
7209
  /**
7000
7210
  * Create a new AI SaaS client
7001
7211
  *
@@ -7085,6 +7295,7 @@ var CadraClient = class {
7085
7295
  this.kanban = new KanbanAPI(this.httpClient, getStreamConfig);
7086
7296
  this.remoteAgents = new RemoteAgentsAPI(this.httpClient, getStreamConfig);
7087
7297
  this.remoteRunners = new RemoteRunnersAPI(this.httpClient);
7298
+ this.aiFunctions = new AiFunctionsAPI(this.httpClient);
7088
7299
  }
7089
7300
  /**
7090
7301
  * Validate client options