@capybara-hq/plugin-sdk 0.1.0-rc.36 → 0.1.0-rc.37

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.
@@ -756,13 +756,31 @@ function request(o) {
756
756
  validated.limits = { mode: "sandbox" };
757
757
  // Reuse v2's pure value guards; inserted mode is never returned or used as authority.
758
758
  parseLegacyDeviceFrame(JSON.stringify({ type: "req", id, op: native, args: validated, deadlineMs }), "kernel");
759
- if (native === "writeFile" &&
760
- (typeof a.dataB64 !== "string" ||
761
- !/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(a.dataB64)))
759
+ if (native === "writeFile" && (typeof a.dataB64 !== "string" || !isBase64(a.dataB64)))
762
760
  throw new DeviceProtocolError("Invalid base64 payload");
763
761
  }
764
762
  return freeze({ type: "req", id, op: op, args: a, deadlineMs });
765
763
  }
764
+ /**
765
+ * Padded standard base64: whole quartets of `A-Z a-z 0-9 + /`, the last one possibly ending in
766
+ * `=` or `==`. One linear pass: a regex with a repeated group exhausts the engine's backtracking
767
+ * stack on payloads of a few megabytes.
768
+ */
769
+ function isBase64(value) {
770
+ if (value.length % 4 !== 0)
771
+ return false;
772
+ const padding = value.endsWith("==") ? 2 : value.endsWith("=") ? 1 : 0;
773
+ for (let i = 0; i < value.length - padding; i++) {
774
+ const c = value.charCodeAt(i);
775
+ if (!((c >= 65 && c <= 90) ||
776
+ (c >= 97 && c <= 122) ||
777
+ (c >= 48 && c <= 57) ||
778
+ c === 43 ||
779
+ c === 47))
780
+ return false;
781
+ }
782
+ return true;
783
+ }
766
784
  /** Strictly parses one protocol 3 frame; throws {@link DeviceProtocolError}. */
767
785
  export function parseDeviceFrame(raw, from, maxFrameBytes) {
768
786
  if (maxFrameBytes !== undefined &&
@@ -900,7 +918,7 @@ export function parseOperationResult(op, result, request) {
900
918
  if (integer(o.offset) !== offset ||
901
919
  typeof o.dataB64 !== "string" ||
902
920
  o.dataB64.length > 87384 ||
903
- !/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(o.dataB64))
921
+ !isBase64(o.dataB64))
904
922
  throw new DeviceProtocolError("Invalid output range or base64");
905
923
  const decoded = atob(o.dataB64);
906
924
  if (btoa(decoded) !== o.dataB64 ||
package/dist/hooks.d.ts CHANGED
@@ -41,9 +41,10 @@ export interface HookScope {
41
41
  * `WebFetch` tool, `review` is the command-review classifier's call (`review` purpose, no run
42
42
  * step; absent = no classifier), `suggestion` is the prompt suggestion side request after a
43
43
  * completed web run (`runId` the run, `step` 0, `attempt` 1; a denial skips it and is recorded only
44
- * in the audit log).
44
+ * in the audit log), `vision` is the call that reads an image for a model without vision, made by
45
+ * the `Read` tool (also for a pasted image, read by its `file_id`; the `vision` purpose's model).
45
46
  */
46
- export type ModelCallPurpose = "step" | "compaction" | "title" | "web_fetch" | "review" | "image" | "suggestion";
47
+ export type ModelCallPurpose = "step" | "compaction" | "title" | "web_fetch" | "review" | "image" | "vision" | "suggestion";
47
48
  /**
48
49
  * What a reported or requested model call was for: the {@link ModelCallPurpose} values, or
49
50
  * `embedding` for an embedding call an extension made through `ctx.models` (`usage.report`, and
@@ -91,7 +92,7 @@ export type HookModelRequest = Omit<ModelRequest, "messages"> & {
91
92
  * denial skips the title and is recorded only in the audit log), once for each `WebFetch`
92
93
  * extraction call (`purpose: "web_fetch"`) and once for each prompt suggestion call
93
94
  * (`purpose: "suggestion"`, `step` 0, `attempt` 1; a denial skips the suggestion and is recorded
94
- * only in the audit log).
95
+ * only in the audit log) and once for each vision call (`purpose: "vision"`).
95
96
  * `request` is the request as sent, except that images and documents are placeholders
96
97
  * ({@link HookMediaPlaceholder}): no media bytes, no attachment ids.
97
98
  */
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const SDK_VERSION = "0.1.0-rc.36";
1
+ export declare const SDK_VERSION = "0.1.0-rc.37";
2
2
  export * from "./agent-template.js";
3
3
  export * from "./bootstrap.js";
4
4
  export * from "./cards.js";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export const SDK_VERSION = "0.1.0-rc.36";
1
+ export const SDK_VERSION = "0.1.0-rc.37";
2
2
  export * from "./agent-template.js";
3
3
  export * from "./bootstrap.js";
4
4
  export * from "./cards.js";
package/dist/model.d.ts CHANGED
@@ -69,7 +69,7 @@ export interface ModelInfo {
69
69
  * Whether `document` blocks are accepted (default false). Images are governed by `vision`. When
70
70
  * the model does not support them the kernel replaces media blocks with English text
71
71
  * placeholders
72
- * (e.g. `[Attached image "<name>" — this model cannot view images.]`; `text/*` documents are
72
+ * (e.g. `[Attached image "<name>" — this model cannot view images. Read with file_id <id> sends it to the organization's vision model, if one is set.]`; `text/*` documents are
73
73
  * inlined as truncated text instead),
74
74
  * and never sends the bytes to it.
75
75
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/plugin-sdk",
3
- "version": "0.1.0-rc.36",
3
+ "version": "0.1.0-rc.37",
4
4
  "description": "Capybara plugin SDK: the types and pure functions plugins are written against",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {