@capybara-hq/plugin-sdk 0.1.0-rc.5 → 0.1.0-rc.51

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 (134) hide show
  1. package/README.md +1 -1
  2. package/agent-docs/agent-templates.md +14 -2
  3. package/agent-docs/concepts.md +14 -5
  4. package/agent-docs/connector-templates.md +4 -1
  5. package/agent-docs/extension-points/channel.md +1 -1
  6. package/agent-docs/extension-points/context.md +15 -0
  7. package/agent-docs/extension-points/device-provider.md +15 -0
  8. package/agent-docs/extension-points/file-preview.md +2 -0
  9. package/agent-docs/extension-points/model-provider.md +3 -1
  10. package/agent-docs/extension-points/object-store.md +2 -0
  11. package/agent-docs/extension-points/push-provider.md +17 -0
  12. package/agent-docs/extensions.md +29 -3
  13. package/agent-docs/plugin-format.md +53 -2
  14. package/agent-docs/setup.md +54 -0
  15. package/dist/agent-template.d.ts +15 -6
  16. package/dist/agent-template.js +32 -13
  17. package/dist/avatar-presets.d.ts +8 -0
  18. package/dist/avatar-presets.js +17 -0
  19. package/dist/bootstrap.d.ts +86 -1
  20. package/dist/bootstrap.js +161 -2
  21. package/dist/cards.d.ts +67 -13
  22. package/dist/cards.js +91 -21
  23. package/dist/channel.d.ts +148 -48
  24. package/dist/channel.js +10 -5
  25. package/dist/client-css.d.ts +36 -0
  26. package/dist/client-css.js +326 -0
  27. package/dist/client-section.d.ts +35 -0
  28. package/dist/client-section.js +133 -0
  29. package/dist/config-ui.d.ts +22 -0
  30. package/dist/config-ui.js +64 -4
  31. package/dist/connector-auth.d.ts +7 -2
  32. package/dist/connector-auth.js +29 -8
  33. package/dist/connector.d.ts +74 -32
  34. package/dist/context.d.ts +40 -0
  35. package/dist/context.js +2 -0
  36. package/dist/ctx.d.ts +120 -29
  37. package/dist/define-extension.d.ts +26 -12
  38. package/dist/define-extension.js +11 -4
  39. package/dist/device-denied-paths.d.ts +14 -0
  40. package/dist/device-denied-paths.js +41 -0
  41. package/dist/device-operation.d.ts +302 -0
  42. package/dist/device-operation.js +292 -0
  43. package/dist/device-protocol.d.ts +490 -0
  44. package/dist/device-protocol.js +1117 -0
  45. package/dist/device-provider.d.ts +472 -0
  46. package/dist/device-provider.js +283 -0
  47. package/dist/extension-point.d.ts +2 -0
  48. package/dist/extension-point.js +6 -2
  49. package/dist/file-preview.d.ts +23 -6
  50. package/dist/git-hosts.d.ts +53 -0
  51. package/dist/git-hosts.js +98 -0
  52. package/dist/hooks.d.ts +125 -20
  53. package/dist/hooks.js +5 -0
  54. package/dist/http-access.d.ts +62 -0
  55. package/dist/http-access.js +12 -0
  56. package/dist/identity.d.ts +38 -9
  57. package/dist/identity.js +21 -1
  58. package/dist/index.d.ts +29 -2
  59. package/dist/index.js +29 -2
  60. package/dist/marketplace.d.ts +26 -0
  61. package/dist/marketplace.js +43 -1
  62. package/dist/model-params.d.ts +41 -22
  63. package/dist/model-params.js +28 -15
  64. package/dist/model.d.ts +206 -71
  65. package/dist/model.js +152 -19
  66. package/dist/net.d.ts +52 -0
  67. package/dist/net.js +34 -0
  68. package/dist/network-classes.d.ts +98 -0
  69. package/dist/network-classes.js +291 -0
  70. package/dist/permissions.d.ts +41 -21
  71. package/dist/permissions.js +101 -42
  72. package/dist/plugin-manifest.d.ts +45 -5
  73. package/dist/plugin-manifest.js +169 -6
  74. package/dist/plugin-package.d.ts +82 -38
  75. package/dist/plugin-package.js +61 -29
  76. package/dist/push.d.ts +75 -0
  77. package/dist/push.js +87 -0
  78. package/dist/sandbox-linux-runtime-source.d.ts +1 -0
  79. package/dist/sandbox-linux-runtime-source.js +2318 -0
  80. package/dist/sandbox-native-runtime-source.d.ts +10 -0
  81. package/dist/sandbox-native-runtime-source.js +476 -0
  82. package/dist/sandbox-runtime-source.d.ts +19 -0
  83. package/dist/sandbox-runtime-source.js +28 -0
  84. package/dist/sandbox-write-denies.d.ts +139 -0
  85. package/dist/sandbox-write-denies.js +869 -0
  86. package/dist/secret.d.ts +4 -1
  87. package/dist/secret.js +4 -1
  88. package/dist/setup-check.d.ts +128 -0
  89. package/dist/setup-check.js +142 -0
  90. package/dist/setup-guide-parse.d.ts +135 -0
  91. package/dist/setup-guide-parse.js +413 -0
  92. package/dist/setup-guide-render.d.ts +50 -0
  93. package/dist/setup-guide-render.js +367 -0
  94. package/dist/setup-guide.d.ts +109 -0
  95. package/dist/setup-guide.js +377 -0
  96. package/dist/shell-capabilities.d.ts +231 -0
  97. package/dist/shell-capabilities.js +37 -0
  98. package/dist/shell-environment.d.ts +57 -0
  99. package/dist/shell-environment.js +22 -0
  100. package/dist/skill-invocation.d.ts +4 -3
  101. package/dist/skill-invocation.js +5 -4
  102. package/dist/skill.d.ts +34 -21
  103. package/dist/skill.js +49 -32
  104. package/dist/storage.d.ts +52 -25
  105. package/dist/theme-assets.d.ts +55 -0
  106. package/dist/theme-assets.js +507 -0
  107. package/dist/theme-readability.d.ts +37 -0
  108. package/dist/theme-readability.js +145 -0
  109. package/dist/theme-tokens.generated.d.ts +299 -0
  110. package/dist/theme-tokens.generated.js +184 -0
  111. package/dist/theme.d.ts +190 -0
  112. package/dist/theme.js +471 -0
  113. package/dist/tool.d.ts +69 -26
  114. package/dist/tool.js +29 -9
  115. package/dist/ui-parts.d.ts +23 -0
  116. package/dist/ui-parts.js +348 -0
  117. package/dist/ui-resolve.d.ts +35 -0
  118. package/dist/ui-resolve.js +42 -0
  119. package/dist/ui-slots.d.ts +65 -0
  120. package/dist/ui-slots.js +261 -0
  121. package/dist/ui.d.ts +212 -76
  122. package/dist/ui.js +101 -27
  123. package/dist/url.d.ts +4 -1
  124. package/dist/url.js +4 -1
  125. package/package.json +8 -1
  126. package/schemas/bootstrap-extra.v1.schema.json +172 -0
  127. package/schemas/bootstrap.v1.schema.json +6 -0
  128. package/schemas/connector-template.v1.schema.json +35 -0
  129. package/schemas/marketplace.v1.schema.json +14 -0
  130. package/schemas/plugin.v1.schema.json +117 -3
  131. package/schemas/theme.v1.schema.json +302 -0
  132. package/agent-docs/extension-points/sandbox.md +0 -15
  133. package/dist/sandbox.d.ts +0 -232
  134. package/dist/sandbox.js +0 -120
@@ -0,0 +1,292 @@
1
+ import { SANDBOX_TAG_RE, validateAllowHost, validateSandboxPathShape, } from "./device-provider.js";
2
+ /** Accepts only the supported permission profile names. */
3
+ export function isPermissionProfile(value) {
4
+ return value === "request-approval" || value === "approve-for-me" || value === "full-access";
5
+ }
6
+ /** The provider cannot enforce the requested permission profile. */
7
+ export class SandboxPermissionUnsupportedError extends Error {
8
+ sandboxPermissionUnsupported = true;
9
+ constructor(message, opts) {
10
+ super(message, opts && "cause" in opts ? { cause: opts.cause } : undefined);
11
+ this.name = "SandboxPermissionUnsupportedError";
12
+ }
13
+ }
14
+ /**
15
+ * Recognizes the inherited tag across SDK copies without requiring this class's identity, so every
16
+ * subclass counts too (for example {@link SandboxWorkUnsettledError}: the same definite refusal).
17
+ */
18
+ export function isSandboxPermissionUnsupportedError(e) {
19
+ return (e instanceof Error &&
20
+ e.sandboxPermissionUnsupported === true);
21
+ }
22
+ /**
23
+ * Earlier work on the device has not settled, so it refused to start a new operation. It extends
24
+ * {@link SandboxPermissionUnsupportedError} so every check that treats that error as a definite
25
+ * refusal (nothing ran) treats this one the same way.
26
+ */
27
+ export class SandboxWorkUnsettledError extends SandboxPermissionUnsupportedError {
28
+ sandboxWorkUnsettled = true;
29
+ constructor(message, opts) {
30
+ super(message, opts);
31
+ this.name = "SandboxWorkUnsettledError";
32
+ }
33
+ }
34
+ /** Recognizes the name and tag across SDK copies without requiring this class's identity. */
35
+ export function isSandboxWorkUnsettledError(e) {
36
+ return (e instanceof Error &&
37
+ e.name === "SandboxWorkUnsettledError" &&
38
+ e.sandboxWorkUnsettled === true);
39
+ }
40
+ /** The requested operation is outside the permitted scope. */
41
+ export class SandboxScopeDeniedError extends Error {
42
+ sandboxScopeDenied = true;
43
+ constructor(message, opts) {
44
+ super(message, opts && "cause" in opts ? { cause: opts.cause } : undefined);
45
+ this.name = "SandboxScopeDeniedError";
46
+ }
47
+ }
48
+ /** Recognizes the name and tag across SDK copies without requiring this class's identity. */
49
+ export function isSandboxScopeDeniedError(e) {
50
+ return (e instanceof Error &&
51
+ e.name === "SandboxScopeDeniedError" &&
52
+ e.sandboxScopeDenied === true);
53
+ }
54
+ /** A scope or execution reference is malformed; validate it before performing any effects. */
55
+ export class SandboxScopeValidationError extends Error {
56
+ sandboxScopeValidation = true;
57
+ constructor(message, opts) {
58
+ super(message, opts && "cause" in opts ? { cause: opts.cause } : undefined);
59
+ this.name = "SandboxScopeValidationError";
60
+ }
61
+ }
62
+ /** Recognizes validation errors across SDK copies. */
63
+ export function isSandboxScopeValidationError(e) {
64
+ return (e instanceof Error &&
65
+ e.name === "SandboxScopeValidationError" &&
66
+ e.sandboxScopeValidation === true);
67
+ }
68
+ /** An operation was consumed but its outcome is unknown. Never automatically retry with a new ID. */
69
+ export class SandboxOperationOutcomeUnknownError extends Error {
70
+ sandboxOperationOutcomeUnknown = true;
71
+ constructor(message, opts) {
72
+ super(message, opts && "cause" in opts ? { cause: opts.cause } : undefined);
73
+ this.name = "SandboxOperationOutcomeUnknownError";
74
+ }
75
+ }
76
+ /** Recognizes unknown outcomes across SDK copies; an unknown outcome is not a gone instance. */
77
+ export function isSandboxOperationOutcomeUnknownError(e) {
78
+ return (e instanceof Error &&
79
+ e.name === "SandboxOperationOutcomeUnknownError" &&
80
+ e.sandboxOperationOutcomeUnknown === true);
81
+ }
82
+ /**
83
+ * Whether a report is a supported instance boundary: `boundary: "instance"` with no
84
+ * `unavailableReason`. An instance report naming a reason (a stale image, a digest mismatch)
85
+ * claims nothing, so a device reporting it is unsupported, never the whole-instance sandbox.
86
+ */
87
+ export function instanceSupported(report) {
88
+ return report.boundary === "instance" && report.unavailableReason === undefined;
89
+ }
90
+ function invalid(field, requirement) {
91
+ throw new SandboxScopeValidationError(`Invalid ${field}: ${requirement}. Supply a valid scope or reference before retrying.`);
92
+ }
93
+ function record(value, keys, field) {
94
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
95
+ return invalid(field, "expected an object");
96
+ }
97
+ const prototype = Object.getPrototypeOf(value);
98
+ if (prototype !== Object.prototype && prototype !== null)
99
+ return invalid(field, "expected a plain object");
100
+ const result = Object.create(null);
101
+ for (const key of Reflect.ownKeys(value)) {
102
+ if (typeof key !== "string" || !keys.includes(key))
103
+ return invalid(field, "unknown fields are not allowed");
104
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
105
+ if (!descriptor || !("value" in descriptor))
106
+ return invalid(field, "accessor fields are not allowed");
107
+ result[key] = descriptor.value;
108
+ }
109
+ return result;
110
+ }
111
+ function id(value, field) {
112
+ if (typeof value !== "string" || value.length === 0 || value.length > 128) {
113
+ return invalid(field, "expected a nonempty string of at most 128 characters");
114
+ }
115
+ return value;
116
+ }
117
+ function integer(value, minimum, field) {
118
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value < minimum) {
119
+ return invalid(field, `expected a safe integer greater than or equal to ${minimum}`);
120
+ }
121
+ return value;
122
+ }
123
+ function tag(value) {
124
+ if (typeof value !== "string" || !SANDBOX_TAG_RE.test(value))
125
+ return invalid("tag", "expected 1–64 lowercase letters, digits or hyphens");
126
+ return value;
127
+ }
128
+ function strings(value, maximum, check, field) {
129
+ if (!Array.isArray(value) || value.length > maximum)
130
+ return invalid(field, `expected an array of at most ${maximum} entries`);
131
+ if (Reflect.ownKeys(value).length !== value.length + 1)
132
+ return invalid(field, "sparse arrays and extra fields are not allowed");
133
+ const result = [];
134
+ for (let i = 0; i < value.length; i++) {
135
+ const descriptor = Object.getOwnPropertyDescriptor(value, i);
136
+ if (!descriptor || !("value" in descriptor))
137
+ return invalid(field, "expected array data entries");
138
+ const item = descriptor.value;
139
+ if (typeof item !== "string")
140
+ return invalid(field, "expected string entries");
141
+ const errors = check(item);
142
+ if (errors.length > 0)
143
+ return invalid(field, errors.join("; "));
144
+ result.push(item);
145
+ }
146
+ return Object.freeze(result);
147
+ }
148
+ function roots(value, field) {
149
+ return strings(value, 64, validateSandboxPathShape, field);
150
+ }
151
+ function projectRoot(value) {
152
+ if (value === null)
153
+ return null;
154
+ if (typeof value !== "string")
155
+ return invalid("filesystem.projectRoot", "expected an absolute path or null");
156
+ const errors = validateSandboxPathShape(value);
157
+ if (errors.length > 0)
158
+ return invalid("filesystem.projectRoot", errors.join("; "));
159
+ return value;
160
+ }
161
+ function fileScope(value) {
162
+ const v = record(value, ["kind", "projectRoot", "writeRoots"], "filesystem");
163
+ if (v.kind === "device") {
164
+ record(value, ["kind"], "filesystem");
165
+ return Object.freeze({ kind: "device" });
166
+ }
167
+ if (v.kind !== "scoped")
168
+ return invalid("filesystem.kind", "expected scoped or device");
169
+ return Object.freeze({
170
+ kind: "scoped",
171
+ projectRoot: projectRoot(v.projectRoot),
172
+ writeRoots: roots(v.writeRoots, "filesystem.writeRoots"),
173
+ });
174
+ }
175
+ function networkScope(value) {
176
+ const v = record(value, ["kind", "hosts"], "network");
177
+ if (v.kind === "none" || v.kind === "open-public" || v.kind === "environment") {
178
+ record(value, ["kind"], "network");
179
+ return Object.freeze({ kind: v.kind });
180
+ }
181
+ if (v.kind !== "allowlist")
182
+ return invalid("network.kind", "expected none, allowlist, open-public or environment");
183
+ return Object.freeze({
184
+ kind: "allowlist",
185
+ hosts: strings(v.hosts, 100, validateAllowHost, "network.hosts"),
186
+ });
187
+ }
188
+ function actor(value) {
189
+ const v = record(value, ["accountId", "conversationId", "runId"], "actor");
190
+ return Object.freeze({
191
+ accountId: id(v.accountId, "actor.accountId"),
192
+ conversationId: id(v.conversationId, "actor.conversationId"),
193
+ ...(Object.hasOwn(v, "runId") ? { runId: id(v.runId, "actor.runId") } : {}),
194
+ });
195
+ }
196
+ function operationRef(v) {
197
+ return {
198
+ operationId: id(v.operationId, "operationId"),
199
+ admitBeforeMs: integer(v.admitBeforeMs, 1, "admitBeforeMs"),
200
+ };
201
+ }
202
+ /** Pure structural validation and a frozen copy; no clock lookup or authority resolution. */
203
+ export function parseSandboxOperationRef(value) {
204
+ return Object.freeze(operationRef(record(value, ["operationId", "admitBeforeMs"], "operation reference")));
205
+ }
206
+ /**
207
+ * Validates a scope and returns a deeply frozen copy, throwing SandboxScopeValidationError.
208
+ * IDs and ceiling revisions are bounded to 128 characters; roots to 64 paths of at most 4096 characters;
209
+ * hosts to 100 entries passing validateAllowHost. Empty grants stay empty, including deny-all.
210
+ * Performs no I/O, authority lookup or deadline refresh. Unknown fields are rejected at every level.
211
+ * The `environment` network and the `device` filesystem are accepted only together.
212
+ */
213
+ export function parseSandboxOperationScope(value) {
214
+ const v = record(value, [
215
+ "operationId",
216
+ "admitBeforeMs",
217
+ "deviceId",
218
+ "rootConversationId",
219
+ "profileRevision",
220
+ "ceilingRevision",
221
+ "profile",
222
+ "actor",
223
+ "tag",
224
+ "filesystem",
225
+ "network",
226
+ ], "operation scope");
227
+ if (!isPermissionProfile(v.profile))
228
+ return invalid("profile", "expected request-approval, approve-for-me or full-access");
229
+ const filesystem = fileScope(v.filesystem);
230
+ const network = networkScope(v.network);
231
+ // The device filesystem and the environment network are the two halves of the escalated call:
232
+ // neither ever pairs with a sandboxed counterpart.
233
+ if (network.kind === "environment" && filesystem.kind !== "device")
234
+ return invalid("network.kind: environment requires the device filesystem", "a scoped filesystem takes none, allowlist or open-public");
235
+ if (filesystem.kind === "device" && network.kind !== "environment")
236
+ return invalid("filesystem.kind: device requires the environment network", "the device filesystem is only the escalated call's");
237
+ return Object.freeze({
238
+ ...operationRef(v),
239
+ deviceId: id(v.deviceId, "deviceId"),
240
+ rootConversationId: id(v.rootConversationId, "rootConversationId"),
241
+ profileRevision: integer(v.profileRevision, 0, "profileRevision"),
242
+ ceilingRevision: id(v.ceilingRevision, "ceilingRevision"),
243
+ profile: v.profile,
244
+ actor: actor(v.actor),
245
+ tag: tag(v.tag),
246
+ filesystem,
247
+ network,
248
+ });
249
+ }
250
+ /** Validates an owner browsing grant and returns a deeply frozen copy; no conversation is required. */
251
+ export function parseSandboxBrowseScope(value) {
252
+ const v = record(value, [
253
+ "operationId",
254
+ "admitBeforeMs",
255
+ "deviceId",
256
+ "accountId",
257
+ "ceilingRevision",
258
+ "readRoots",
259
+ "tag",
260
+ ], "browse scope");
261
+ return Object.freeze({
262
+ ...operationRef(v),
263
+ deviceId: id(v.deviceId, "deviceId"),
264
+ accountId: id(v.accountId, "accountId"),
265
+ ceilingRevision: id(v.ceilingRevision, "ceilingRevision"),
266
+ readRoots: roots(v.readRoots, "readRoots"),
267
+ tag: tag(v.tag),
268
+ });
269
+ }
270
+ /** Validates trusted staging structure and returns a deeply frozen copy; does not authorize its roots. */
271
+ export function parseSandboxPreparationScope(value) {
272
+ const v = record(value, ["operationId", "deviceId", "purpose", "writeRoots", "tag"], "preparation scope");
273
+ if (v.purpose !== "skills" && v.purpose !== "attachments")
274
+ return invalid("purpose", "expected skills or attachments");
275
+ return Object.freeze({
276
+ operationId: id(v.operationId, "operationId"),
277
+ deviceId: id(v.deviceId, "deviceId"),
278
+ purpose: v.purpose,
279
+ writeRoots: roots(v.writeRoots, "writeRoots"),
280
+ tag: tag(v.tag),
281
+ });
282
+ }
283
+ /** Validates all four bounded locator fields and returns a frozen copy; does not authenticate the caller. */
284
+ export function parseSandboxExecutionRef(value) {
285
+ const v = record(value, ["executionId", "operationId", "instanceId", "instanceGeneration"], "execution reference");
286
+ return Object.freeze({
287
+ executionId: id(v.executionId, "executionId"),
288
+ operationId: id(v.operationId, "operationId"),
289
+ instanceId: id(v.instanceId, "instanceId"),
290
+ instanceGeneration: id(v.instanceGeneration, "instanceGeneration"),
291
+ });
292
+ }