@yaklabs-ai/plugin-sdk 0.48.1 → 0.49.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/README.md +33 -19
- package/THIRD-PARTY-INVENTORY.json +1 -1
- package/dist/disclosure.d.ts +41 -2
- package/dist/disclosure.js +16 -0
- package/dist/kay-agent-testing.d.ts +42 -3
- package/dist/kay-agent-testing.js +10 -0
- package/dist/kay-agent.d.ts +59 -9
- package/dist/kay-agent.js +16 -0
- package/dist/kay-app.d.ts +49 -57
- package/dist/kay-app.js +634 -608
- package/dist/uri.d.ts +380 -0
- package/dist/uri.js +81 -0
- package/dist/vendored-mcp.d.ts +2 -0
- package/package.json +5 -1
package/dist/kay-app.js
CHANGED
|
@@ -1,662 +1,686 @@
|
|
|
1
|
-
// packages/
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
/^(?:AKIA|ASIA)[0-9A-Z]{16}$/u,
|
|
34
|
-
// Google API keys, both published shapes.
|
|
35
|
-
/^AIza[0-9A-Za-z_-]{35}$/u,
|
|
36
|
-
/^AQ\.[A-Za-z0-9_-]{20,}$/u,
|
|
37
|
-
// npm automation tokens.
|
|
38
|
-
/^npm_[A-Za-z0-9]{30,}$/u,
|
|
39
|
-
// SendGrid API keys (SG.<key id>.<secret>).
|
|
40
|
-
/^SG\.[A-Za-z0-9_-]{16,}\.[A-Za-z0-9_-]{16,}$/u,
|
|
41
|
-
// HashiCorp Vault service/batch/recovery tokens.
|
|
42
|
-
/^hv[sbr]\.[A-Za-z0-9_-]{20,}$/u,
|
|
43
|
-
// Shopify access tokens.
|
|
44
|
-
/^shp(?:at|ss|ca|pa)_[a-fA-F0-9]{32}$/u,
|
|
45
|
-
// Stripe live/test secret and restricted keys.
|
|
46
|
-
/^(?:sk|rk)_(?:live|test)_[A-Za-z0-9]{16,}$/u,
|
|
47
|
-
// JSON Web Tokens - header.payload.signature, header always starts `eyJ`.
|
|
48
|
-
/^eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*$/u,
|
|
49
|
-
// A whole Authorization header value carried as data.
|
|
50
|
-
/^(?:Bearer|Basic) [A-Za-z0-9+/._~-]{16,}={0,2}$/iu,
|
|
51
|
-
// PEM private key blocks, anywhere in the string.
|
|
52
|
-
/-----BEGIN (?:[A-Z]+ )?PRIVATE KEY-----/u
|
|
53
|
-
];
|
|
54
|
-
function isCredentialShapedText(value) {
|
|
55
|
-
if (typeof value !== "string" || value.length === 0)
|
|
56
|
-
return false;
|
|
57
|
-
return CREDENTIAL_VALUE_PATTERNS.some((pattern) => pattern.test(value));
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// packages/plugin-protocol/dist/json.js
|
|
61
|
-
import { z } from "zod";
|
|
62
|
-
var JsonValue = z.lazy(() => z.union([
|
|
63
|
-
z.string(),
|
|
64
|
-
z.number(),
|
|
65
|
-
z.boolean(),
|
|
66
|
-
z.null(),
|
|
67
|
-
z.array(JsonValue),
|
|
68
|
-
z.record(z.string(), JsonValue)
|
|
69
|
-
]));
|
|
70
|
-
var JsonObject = z.record(z.string(), JsonValue);
|
|
71
|
-
var JsonSchema = z.record(z.string(), JsonValue);
|
|
72
|
-
|
|
73
|
-
// packages/plugin-sdk/dist/kay-app/card-layout.js
|
|
74
|
-
function element(type, props) {
|
|
75
|
-
return { root: "root", elements: { root: { type, props } } };
|
|
1
|
+
// packages/herd-uri/dist/errors.js
|
|
2
|
+
var UriError = class extends Error {
|
|
3
|
+
};
|
|
4
|
+
var CONFLICT_MESSAGES = {
|
|
5
|
+
changed: "This resource changed since this session last read it. Read it again before modifying it.",
|
|
6
|
+
unwitnessed: "This resource was not read in this session. Read it before modifying it.",
|
|
7
|
+
unknown: "This resource changed or was not read in this session. Read it again before modifying it."
|
|
8
|
+
};
|
|
9
|
+
var UriConflictError = class extends UriError {
|
|
10
|
+
_tag = "UriConflictError";
|
|
11
|
+
reason;
|
|
12
|
+
constructor(reason) {
|
|
13
|
+
super(CONFLICT_MESSAGES[reason ?? "unknown"]);
|
|
14
|
+
this.name = "UriConflictError";
|
|
15
|
+
this.reason = reason;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
var UriValidationError = class extends UriError {
|
|
19
|
+
_tag = "UriValidationError";
|
|
20
|
+
constructor(message) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.name = "UriValidationError";
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
function requireWriteContent(payload2, uri) {
|
|
26
|
+
if (payload2 === void 0) {
|
|
27
|
+
throw new UriValidationError(`Writing ${uri} needs \`content\` (or a \`source\` to copy from): pass the payload this address takes, which its help names.`);
|
|
28
|
+
}
|
|
29
|
+
if (payload2 instanceof Uint8Array) {
|
|
30
|
+
throw new UriValidationError(`${uri} stores text only, so it cannot take raw bytes. Copy the file to an address that accepts bytes.`);
|
|
31
|
+
}
|
|
32
|
+
return payload2;
|
|
76
33
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
34
|
+
var UriProviderError = class extends UriError {
|
|
35
|
+
_tag = "UriProviderError";
|
|
36
|
+
moduleId;
|
|
37
|
+
operation;
|
|
38
|
+
uri;
|
|
39
|
+
status;
|
|
40
|
+
providerCode;
|
|
41
|
+
retryable;
|
|
42
|
+
/** Provider-directed delay before retrying, in milliseconds. */
|
|
43
|
+
retryAfterMs;
|
|
44
|
+
/** See {@link UriProviderErrorOptions.effect}. */
|
|
45
|
+
effect;
|
|
46
|
+
/** See {@link UriProviderErrorOptions.refusalMessage}. */
|
|
47
|
+
refusalMessage;
|
|
48
|
+
constructor(options) {
|
|
49
|
+
super(options.message);
|
|
50
|
+
this.name = "UriProviderError";
|
|
51
|
+
this.moduleId = options.moduleId;
|
|
52
|
+
this.operation = options.operation;
|
|
53
|
+
this.uri = options.uri;
|
|
54
|
+
if (options.status !== void 0)
|
|
55
|
+
this.status = options.status;
|
|
56
|
+
if (options.providerCode !== void 0)
|
|
57
|
+
this.providerCode = options.providerCode;
|
|
58
|
+
if (options.retryable !== void 0)
|
|
59
|
+
this.retryable = options.retryable;
|
|
60
|
+
if (options.retryAfterMs !== void 0) {
|
|
61
|
+
if (!Number.isInteger(options.retryAfterMs) || options.retryAfterMs < 0) {
|
|
62
|
+
throw new TypeError("retryAfterMs must be a nonnegative integer.");
|
|
63
|
+
}
|
|
64
|
+
this.retryAfterMs = options.retryAfterMs;
|
|
86
65
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return { ...group("Card", { title }, children), ...state ? { state } : {} };
|
|
93
|
-
}
|
|
94
|
-
function row(children) {
|
|
95
|
-
return group("Row", {}, children);
|
|
96
|
-
}
|
|
97
|
-
function stack(children) {
|
|
98
|
-
return group("Stack", {}, children);
|
|
99
|
-
}
|
|
100
|
-
function field(type, name, options) {
|
|
101
|
-
const key = name.replaceAll("~", "~0").replaceAll("/", "~1");
|
|
102
|
-
return element(type, { ...options, value: { $bindState: `/form/${key}` } });
|
|
103
|
-
}
|
|
104
|
-
function textField(name, options) {
|
|
105
|
-
return field("Field", name, options);
|
|
106
|
-
}
|
|
107
|
-
function textArea(name, options) {
|
|
108
|
-
return field("TextArea", name, options);
|
|
109
|
-
}
|
|
110
|
-
function select(name, options) {
|
|
111
|
-
return field("Select", name, options);
|
|
112
|
-
}
|
|
113
|
-
function multiSelect(name, options) {
|
|
114
|
-
return field("MultiSelect", name, options);
|
|
115
|
-
}
|
|
116
|
-
function switchField(name, options) {
|
|
117
|
-
return field("Switch", name, options);
|
|
118
|
-
}
|
|
119
|
-
function submit(label) {
|
|
120
|
-
return {
|
|
121
|
-
root: "root",
|
|
122
|
-
elements: {
|
|
123
|
-
root: {
|
|
124
|
-
type: "Button",
|
|
125
|
-
props: { label },
|
|
126
|
-
on: { press: { action: "submit" } }
|
|
66
|
+
if (options.effect !== void 0)
|
|
67
|
+
this.effect = options.effect;
|
|
68
|
+
if (options.refusalMessage !== void 0) {
|
|
69
|
+
if (options.effect !== "none") {
|
|
70
|
+
throw new TypeError('refusalMessage requires effect: "none".');
|
|
127
71
|
}
|
|
72
|
+
this.refusalMessage = options.refusalMessage;
|
|
128
73
|
}
|
|
129
|
-
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
var UriNotFoundError = class extends UriError {
|
|
77
|
+
uri;
|
|
78
|
+
hint;
|
|
79
|
+
_tag = "UriNotFoundError";
|
|
80
|
+
constructor(uri, hint) {
|
|
81
|
+
super(hint !== void 0 ? `No resource found at '${uri}'. ${hint}` : `No resource found at '${uri}'.`);
|
|
82
|
+
this.uri = uri;
|
|
83
|
+
this.hint = hint;
|
|
84
|
+
this.name = "UriNotFoundError";
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
var UriUnsupportedOperationError = class extends UriError {
|
|
88
|
+
operation;
|
|
89
|
+
moduleId;
|
|
90
|
+
uri;
|
|
91
|
+
_tag = "UriUnsupportedOperationError";
|
|
92
|
+
constructor(operation, moduleId, uri, message) {
|
|
93
|
+
super(message ?? `URI module '${moduleId}' does not support '${operation}' for '${uri}'.`);
|
|
94
|
+
this.operation = operation;
|
|
95
|
+
this.moduleId = moduleId;
|
|
96
|
+
this.uri = uri;
|
|
97
|
+
this.name = "UriUnsupportedOperationError";
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// packages/herd-uri/dist/resource-witness.js
|
|
102
|
+
import { createHash } from "node:crypto";
|
|
103
|
+
function contentDigest(content) {
|
|
104
|
+
const hash = createHash("sha256");
|
|
105
|
+
hash.update(typeof content === "string" ? new TextEncoder().encode(content) : content);
|
|
106
|
+
return `${DIGEST_PREFIX}${hash.digest("base64url")}`;
|
|
130
107
|
}
|
|
108
|
+
var DIGEST_PREFIX = "sha256:";
|
|
131
109
|
|
|
132
|
-
// packages/
|
|
110
|
+
// packages/herd-uri/dist/operations.js
|
|
111
|
+
import { z } from "zod";
|
|
112
|
+
var URI_OPERATIONS = [
|
|
113
|
+
"help",
|
|
114
|
+
"read",
|
|
115
|
+
"write",
|
|
116
|
+
"edit",
|
|
117
|
+
"list",
|
|
118
|
+
"search",
|
|
119
|
+
"delete"
|
|
120
|
+
];
|
|
121
|
+
var UriOperationSchema = z.enum(URI_OPERATIONS);
|
|
122
|
+
|
|
123
|
+
// packages/herd-uri/dist/help-schema.js
|
|
133
124
|
import { z as z2 } from "zod";
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
stored: false,
|
|
143
|
-
deduplicated: false,
|
|
144
|
-
inputDigest: "",
|
|
145
|
-
recordedAtMs: Date.now()
|
|
146
|
-
}),
|
|
147
|
-
listDetectors: () => Promise.resolve(noStore),
|
|
148
|
-
list: () => Promise.resolve(noStore)
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
var SIGNAL_TIME_MAX_MS = 864e13;
|
|
152
|
-
var MAX_CHOICE_LABELS = 64;
|
|
153
|
-
var MAX_NAME = 64;
|
|
154
|
-
var MAX_POINTER = 256;
|
|
155
|
-
var MAX_QUESTIONS = 64;
|
|
156
|
-
var DETECTOR_ID = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u;
|
|
157
|
-
var VERSION = /^[A-Za-z0-9]+(?:[._-][A-Za-z0-9]+)*$/u;
|
|
158
|
-
var QUESTION_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/u;
|
|
159
|
-
var POINTER = /^[^\s\p{C}/?#]+$/u;
|
|
160
|
-
var LABEL = /^[^\s,@\p{C}]+(?: [^\s,@\p{C}]+)*$/u;
|
|
161
|
-
var RUN_ID = /^\P{Cc}+$/u;
|
|
162
|
-
var POINTER_RULE = `1 to ${MAX_POINTER} characters with no whitespace, \`/\`, \`?\`, \`#\`, or control or invisible character`;
|
|
163
|
-
var ObserveShape = z2.looseObject({
|
|
164
|
-
detector: z2.looseObject({ id: z2.string(), version: z2.string() }),
|
|
165
|
-
subject: z2.looseObject({ kind: z2.string(), key: z2.string().optional() }).optional(),
|
|
166
|
-
after: z2.looseObject({ observationId: z2.unknown() }).optional(),
|
|
167
|
-
reuse: z2.looseObject({ maxAgeMs: z2.unknown() }).optional(),
|
|
168
|
-
source: z2.looseObject({
|
|
169
|
-
sessionId: z2.string(),
|
|
170
|
-
entryId: z2.string(),
|
|
171
|
-
openerEntryId: z2.string().optional(),
|
|
172
|
-
runId: z2.string().optional(),
|
|
173
|
-
occurredAtMs: z2.unknown().optional()
|
|
174
|
-
}),
|
|
175
|
-
questions: z2.record(z2.string(), z2.unknown())
|
|
125
|
+
var UriContractJsonSchema = z2.record(z2.string(), z2.unknown());
|
|
126
|
+
var UriParameterSchema = z2.strictObject({
|
|
127
|
+
name: z2.string().min(1),
|
|
128
|
+
in: z2.enum(["uri", "query", "selector"]),
|
|
129
|
+
required: z2.boolean(),
|
|
130
|
+
description: z2.string().optional(),
|
|
131
|
+
schema: UriContractJsonSchema,
|
|
132
|
+
examples: z2.array(z2.unknown()).optional()
|
|
176
133
|
});
|
|
177
|
-
var
|
|
178
|
-
|
|
179
|
-
|
|
134
|
+
var UriPayloadContractSchema = z2.strictObject({
|
|
135
|
+
name: z2.string().min(1),
|
|
136
|
+
mediaType: z2.string().optional(),
|
|
137
|
+
description: z2.string().optional(),
|
|
138
|
+
schema: UriContractJsonSchema.optional(),
|
|
139
|
+
semanticConstraints: z2.array(z2.string().min(1)).min(1).optional(),
|
|
140
|
+
examples: z2.array(z2.unknown()).optional()
|
|
180
141
|
});
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
const id = source[field2];
|
|
212
|
-
if (id !== void 0 && !(id.length <= MAX_POINTER && grammar.test(id))) {
|
|
213
|
-
return `\`source.${field2}\` must be ${rule}.`;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
const occurredAtMs = source.occurredAtMs;
|
|
217
|
-
if (occurredAtMs !== void 0 && !(typeof occurredAtMs === "number" && Number.isSafeInteger(occurredAtMs) && occurredAtMs >= 0 && occurredAtMs <= SIGNAL_TIME_MAX_MS)) {
|
|
218
|
-
return `\`source.occurredAtMs\` must be whole epoch milliseconds from 0 to ${SIGNAL_TIME_MAX_MS}.`;
|
|
219
|
-
}
|
|
220
|
-
if (subject !== void 0 && !fits(subject.kind, DETECTOR_ID)) {
|
|
221
|
-
return "`subject.kind` must be a lowercase slug of at most 64 characters: a-z and 0-9 in words joined by single hyphens.";
|
|
222
|
-
}
|
|
223
|
-
if (subject?.key !== void 0 && !(subject.key.length <= MAX_POINTER && POINTER.test(subject.key))) {
|
|
224
|
-
return `\`subject.key\` must be ${POINTER_RULE}.`;
|
|
225
|
-
}
|
|
226
|
-
if (after !== void 0 && !isWhole(after.observationId, 1)) {
|
|
227
|
-
return "`after.observationId` must be a positive whole number: the id of a stored signal.";
|
|
142
|
+
|
|
143
|
+
// packages/herd-uri/dist/text-edit.js
|
|
144
|
+
import { z as z3 } from "zod";
|
|
145
|
+
var findReplaceArm = z3.strictObject({
|
|
146
|
+
find: z3.string().min(1),
|
|
147
|
+
replace: z3.string(),
|
|
148
|
+
all: z3.boolean().optional()
|
|
149
|
+
});
|
|
150
|
+
var oldNewEntry = z3.strictObject({
|
|
151
|
+
oldText: z3.string().min(1),
|
|
152
|
+
newText: z3.string()
|
|
153
|
+
});
|
|
154
|
+
var uriTextEditPayloadArms = z3.union([
|
|
155
|
+
findReplaceArm,
|
|
156
|
+
z3.strictObject({ edits: z3.array(oldNewEntry).min(1) }),
|
|
157
|
+
oldNewEntry,
|
|
158
|
+
z3.array(oldNewEntry).min(1)
|
|
159
|
+
]);
|
|
160
|
+
|
|
161
|
+
// packages/herd-uri/dist/line-selector.js
|
|
162
|
+
var RAW_TOKEN = /^raw$/i;
|
|
163
|
+
function parseRangeListToken(token) {
|
|
164
|
+
if (token.length === 0)
|
|
165
|
+
return void 0;
|
|
166
|
+
const ranges = [];
|
|
167
|
+
for (const part of token.split(",")) {
|
|
168
|
+
const range = parseSingleRange(part);
|
|
169
|
+
if (range === void 0)
|
|
170
|
+
return void 0;
|
|
171
|
+
ranges.push(range);
|
|
228
172
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
173
|
+
return ranges;
|
|
174
|
+
}
|
|
175
|
+
function toInt(value) {
|
|
176
|
+
if (!/^\d+$/.test(value))
|
|
177
|
+
return void 0;
|
|
178
|
+
const n = Number.parseInt(value, 10);
|
|
179
|
+
return Number.isSafeInteger(n) && n >= 1 ? n : void 0;
|
|
180
|
+
}
|
|
181
|
+
function parseSingleRange(part) {
|
|
182
|
+
const plus = part.indexOf("+");
|
|
183
|
+
if (plus >= 0) {
|
|
184
|
+
const start2 = toInt(part.slice(0, plus));
|
|
185
|
+
const count = toInt(part.slice(plus + 1));
|
|
186
|
+
if (start2 === void 0 || count === void 0)
|
|
187
|
+
return void 0;
|
|
188
|
+
return { start: start2, end: start2 + count - 1 };
|
|
236
189
|
}
|
|
237
|
-
const
|
|
238
|
-
if (
|
|
239
|
-
|
|
190
|
+
const dash = part.indexOf("-");
|
|
191
|
+
if (dash >= 0) {
|
|
192
|
+
const start2 = toInt(part.slice(0, dash));
|
|
193
|
+
const endRaw = part.slice(dash + 1);
|
|
194
|
+
if (start2 === void 0)
|
|
195
|
+
return void 0;
|
|
196
|
+
if (endRaw.length === 0)
|
|
197
|
+
return { start: start2, end: Number.POSITIVE_INFINITY };
|
|
198
|
+
const end = toInt(endRaw);
|
|
199
|
+
if (end === void 0 || end < start2)
|
|
200
|
+
return void 0;
|
|
201
|
+
return { start: start2, end };
|
|
240
202
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
203
|
+
const start = toInt(part);
|
|
204
|
+
if (start === void 0)
|
|
205
|
+
return void 0;
|
|
206
|
+
return { start, end: Number.POSITIVE_INFINITY };
|
|
207
|
+
}
|
|
208
|
+
function mergeRanges(ranges) {
|
|
209
|
+
const sorted = [...ranges].sort((a, b) => a.start - b.start);
|
|
210
|
+
const merged = [];
|
|
211
|
+
for (const range of sorted) {
|
|
212
|
+
const last = merged[merged.length - 1];
|
|
213
|
+
if (last !== void 0 && range.start <= last.end) {
|
|
214
|
+
if (range.end > last.end) {
|
|
215
|
+
merged[merged.length - 1] = { start: last.start, end: range.end };
|
|
216
|
+
}
|
|
247
217
|
continue;
|
|
248
|
-
const labels = Object.keys(choice.data.criteria);
|
|
249
|
-
if (labels.length > MAX_CHOICE_LABELS) {
|
|
250
|
-
return `The choice question \`${name}\` offers ${labels.length} labels; at most ${MAX_CHOICE_LABELS}.`;
|
|
251
|
-
}
|
|
252
|
-
const bad = labels.find((label) => !fits(label, LABEL));
|
|
253
|
-
if (bad !== void 0) {
|
|
254
|
-
return `The choice question \`${name}\` offers the label ${quoted(bad)}, which a \`where\` filter cannot name: a label is 1 to 64 characters with no \`,\`, \`@\`, or control or invisible character, and no whitespace but single spaces between words.`;
|
|
255
218
|
}
|
|
219
|
+
merged.push(range);
|
|
256
220
|
}
|
|
257
|
-
return
|
|
221
|
+
return merged;
|
|
258
222
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
223
|
+
function parseLineSelector(input) {
|
|
224
|
+
let address = input;
|
|
225
|
+
let raw = false;
|
|
226
|
+
let ranges;
|
|
227
|
+
for (let i = 0; i < 2; i += 1) {
|
|
228
|
+
const colon = address.lastIndexOf(":");
|
|
229
|
+
if (colon < 0)
|
|
230
|
+
break;
|
|
231
|
+
const token = address.slice(colon + 1);
|
|
232
|
+
if (RAW_TOKEN.test(token)) {
|
|
233
|
+
if (raw)
|
|
234
|
+
break;
|
|
235
|
+
raw = true;
|
|
236
|
+
address = address.slice(0, colon);
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
const parsed = parseRangeListToken(token);
|
|
240
|
+
if (parsed === void 0)
|
|
241
|
+
break;
|
|
242
|
+
if (ranges !== void 0)
|
|
243
|
+
break;
|
|
244
|
+
ranges = parsed;
|
|
245
|
+
address = address.slice(0, colon);
|
|
246
|
+
}
|
|
272
247
|
return {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
detector: { ...detector, rubricDigest: "" },
|
|
276
|
-
source,
|
|
277
|
-
stored: false,
|
|
278
|
-
deduplicated: false,
|
|
279
|
-
inputDigest: "",
|
|
280
|
-
recordedAtMs: Date.now()
|
|
248
|
+
address,
|
|
249
|
+
selector: { ranges: ranges ? mergeRanges(ranges) : [], raw }
|
|
281
250
|
};
|
|
282
251
|
}
|
|
283
252
|
|
|
284
|
-
// packages/herd-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
switch (entry.type) {
|
|
312
|
-
case "message": {
|
|
313
|
-
const message = entry.message;
|
|
314
|
-
if (message.role === "custom") {
|
|
315
|
-
return `custom_message:${typeof message.customType === "string" ? message.customType : ""}`;
|
|
316
|
-
}
|
|
317
|
-
return (typeof message.role === "string" ? ROLE_KINDS[message.role] : void 0) ?? "other";
|
|
318
|
-
}
|
|
319
|
-
case "custom":
|
|
320
|
-
return `custom:${entry.customType}`;
|
|
321
|
-
case "compaction":
|
|
322
|
-
return "compaction";
|
|
323
|
-
case "branch_summary":
|
|
324
|
-
return "branch_summary";
|
|
325
|
-
default:
|
|
326
|
-
return "other";
|
|
253
|
+
// packages/herd-uri/dist/schema/to-json-schema.js
|
|
254
|
+
import { z as z4 } from "zod";
|
|
255
|
+
function toJsonSchema(schema) {
|
|
256
|
+
if (schema instanceof z4.ZodType) {
|
|
257
|
+
const { $schema: _dialect, ...value } = z4.toJSONSchema(schema, {
|
|
258
|
+
// `io: "input"` describes what a caller may SEND, which is what a parameter and an
|
|
259
|
+
// `accepts` payload advertise: a field with a Zod default is optional on the wire even
|
|
260
|
+
// though the parsed value always carries it. Strictness still survives where the validator
|
|
261
|
+
// really enforces it - `z.strictObject` emits `additionalProperties: false`, while a plain
|
|
262
|
+
// `z.object` correctly does not, because it TOLERATES unknown keys and silently strips
|
|
263
|
+
// them. A `returns` payload derived from a Zod schema is described in the same input terms;
|
|
264
|
+
// no module does that today, and a faithful output projection would need its own seam.
|
|
265
|
+
io: "input",
|
|
266
|
+
// Inline every reused sub-schema rather than emitting `$ref`s into a `$defs` block. A
|
|
267
|
+
// contract schema is a FRAGMENT: it gets embedded in a payload contract, and callers
|
|
268
|
+
// legitimately lift one arm of a union out of it. A `$ref` only resolves relative to the
|
|
269
|
+
// root that carries `$defs`, so the moment the fragment moves, the reference dangles.
|
|
270
|
+
// Self-contained is worth the repetition at these sizes.
|
|
271
|
+
reused: "inline",
|
|
272
|
+
// Recursion (`z.lazy`) has no self-contained form: zod's default is to emit a
|
|
273
|
+
// `$defs` block with `$ref` pointers, which dangle the moment the fragment is
|
|
274
|
+
// embedded. Throw instead, so a contract that needs recursion has to disclose a
|
|
275
|
+
// non-recursive shape (see skill-module's metadata disclosure) rather than ship a
|
|
276
|
+
// reference nothing can resolve.
|
|
277
|
+
cycles: "throw"
|
|
278
|
+
});
|
|
279
|
+
return value;
|
|
327
280
|
}
|
|
281
|
+
return structuredClone(schema);
|
|
328
282
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
let all = false;
|
|
333
|
-
for (const raw of tokens) {
|
|
334
|
-
const token = raw.trim();
|
|
335
|
-
if (token === "all") {
|
|
336
|
-
all = true;
|
|
337
|
-
} else if (token === "messages") {
|
|
338
|
-
for (const kind of STORED_TRANSCRIPT_MESSAGE_KINDS)
|
|
339
|
-
addToken(kind);
|
|
340
|
-
} else if (!addToken(token)) {
|
|
341
|
-
return { ok: false, invalid: raw };
|
|
342
|
-
}
|
|
343
|
-
}
|
|
283
|
+
|
|
284
|
+
// packages/herd-uri/dist/schema/helpers.js
|
|
285
|
+
function payload(name, schema, options = {}) {
|
|
344
286
|
return {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
287
|
+
name,
|
|
288
|
+
...options.mediaType === void 0 ? {} : { mediaType: options.mediaType },
|
|
289
|
+
...options.description === void 0 ? {} : { description: options.description },
|
|
290
|
+
schema: toJsonSchema(schema),
|
|
291
|
+
...options.semanticConstraints === void 0 ? {} : { semanticConstraints: options.semanticConstraints },
|
|
292
|
+
...options.examples === void 0 ? {} : { examples: options.examples }
|
|
349
293
|
};
|
|
350
|
-
function addToken(token) {
|
|
351
|
-
if (NAMED_KINDS.has(token)) {
|
|
352
|
-
exact.add(token);
|
|
353
|
-
return true;
|
|
354
|
-
}
|
|
355
|
-
const family = /^(custom|custom_message):(.+)$/.exec(token);
|
|
356
|
-
if (family === null)
|
|
357
|
-
return false;
|
|
358
|
-
if (family[2] === "*")
|
|
359
|
-
families.add(`${family[1]}:`);
|
|
360
|
-
else
|
|
361
|
-
exact.add(token);
|
|
362
|
-
return true;
|
|
363
|
-
}
|
|
364
294
|
}
|
|
365
|
-
var STORED_TRANSCRIPT_MESSAGE_FILTER = (() => {
|
|
366
|
-
const parsed = parseStoredTranscriptKindFilter(STORED_TRANSCRIPT_MESSAGE_KINDS);
|
|
367
|
-
if (!parsed.ok)
|
|
368
|
-
throw new Error(`invalid default kinds: ${parsed.invalid}`);
|
|
369
|
-
return parsed.filter;
|
|
370
|
-
})();
|
|
371
295
|
|
|
372
|
-
// packages/plugin-sdk/dist/
|
|
373
|
-
|
|
296
|
+
// packages/plugin-sdk/dist/uri.js
|
|
297
|
+
function createUnavailableUriCaller(message) {
|
|
298
|
+
const unavailable = async () => {
|
|
299
|
+
throw new Error(message);
|
|
300
|
+
};
|
|
301
|
+
return {
|
|
302
|
+
read: unavailable,
|
|
303
|
+
list: unavailable,
|
|
304
|
+
search: unavailable,
|
|
305
|
+
write: unavailable,
|
|
306
|
+
edit: unavailable,
|
|
307
|
+
delete: unavailable
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// packages/plugin-protocol/dist/plugin-signal-limits.js
|
|
312
|
+
var PLUGIN_EVENT_REFUSED_ERROR_NAME = "PluginEventRefusedError";
|
|
313
|
+
var PLUGIN_SIGNAL_KINDS = [
|
|
314
|
+
"message",
|
|
315
|
+
"request",
|
|
316
|
+
"mention",
|
|
317
|
+
"invite",
|
|
318
|
+
"status"
|
|
319
|
+
];
|
|
320
|
+
var PLUGIN_SIGNAL_TITLE_MAX = 300;
|
|
321
|
+
var PLUGIN_SIGNAL_SNIPPET_MAX = 500;
|
|
322
|
+
var PLUGIN_SIGNAL_LABELS_MAX = 20;
|
|
323
|
+
var PLUGIN_SIGNAL_LABEL_MAX = 64;
|
|
324
|
+
var PLUGIN_SIGNAL_RELATED_KEYS = [
|
|
325
|
+
"thread",
|
|
326
|
+
"from",
|
|
327
|
+
"to",
|
|
328
|
+
"cc"
|
|
329
|
+
];
|
|
330
|
+
|
|
331
|
+
// packages/plugin-protocol/dist/credential-text.js
|
|
332
|
+
var CREDENTIAL_VALUE_PATTERNS = [
|
|
333
|
+
// Anthropic / OpenAI-style secret keys (`sk-`, `sk-ant-`, `sk-proj-`).
|
|
334
|
+
/^sk-[A-Za-z0-9_-]{16,}$/u,
|
|
335
|
+
// GitHub classic, fine-grained, app, and OAuth tokens.
|
|
336
|
+
/^gh[pousr]_[A-Za-z0-9]{16,}$/u,
|
|
337
|
+
/^github_pat_[A-Za-z0-9_]{20,}$/u,
|
|
338
|
+
// GitLab personal access tokens.
|
|
339
|
+
/^glpat-[A-Za-z0-9_-]{16,}$/u,
|
|
340
|
+
// Slack bot/user/app tokens.
|
|
341
|
+
/^xox[baprse]-[A-Za-z0-9-]{10,}$/u,
|
|
342
|
+
// AWS access key ids, long-lived and STS-issued.
|
|
343
|
+
/^(?:AKIA|ASIA)[0-9A-Z]{16}$/u,
|
|
344
|
+
// Google API keys, both published shapes.
|
|
345
|
+
/^AIza[0-9A-Za-z_-]{35}$/u,
|
|
346
|
+
/^AQ\.[A-Za-z0-9_-]{20,}$/u,
|
|
347
|
+
// npm automation tokens.
|
|
348
|
+
/^npm_[A-Za-z0-9]{30,}$/u,
|
|
349
|
+
// SendGrid API keys (SG.<key id>.<secret>).
|
|
350
|
+
/^SG\.[A-Za-z0-9_-]{16,}\.[A-Za-z0-9_-]{16,}$/u,
|
|
351
|
+
// HashiCorp Vault service/batch/recovery tokens.
|
|
352
|
+
/^hv[sbr]\.[A-Za-z0-9_-]{20,}$/u,
|
|
353
|
+
// Shopify access tokens.
|
|
354
|
+
/^shp(?:at|ss|ca|pa)_[a-fA-F0-9]{32}$/u,
|
|
355
|
+
// Stripe live/test secret and restricted keys.
|
|
356
|
+
/^(?:sk|rk)_(?:live|test)_[A-Za-z0-9]{16,}$/u,
|
|
357
|
+
// JSON Web Tokens - header.payload.signature, header always starts `eyJ`.
|
|
358
|
+
/^eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*$/u,
|
|
359
|
+
// A whole Authorization header value carried as data.
|
|
360
|
+
/^(?:Bearer|Basic) [A-Za-z0-9+/._~-]{16,}={0,2}$/iu,
|
|
361
|
+
// PEM private key blocks, anywhere in the string.
|
|
362
|
+
/-----BEGIN (?:[A-Z]+ )?PRIVATE KEY-----/u
|
|
363
|
+
];
|
|
364
|
+
function isCredentialShapedText(value) {
|
|
365
|
+
if (typeof value !== "string" || value.length === 0)
|
|
366
|
+
return false;
|
|
367
|
+
return CREDENTIAL_VALUE_PATTERNS.some((pattern) => pattern.test(value));
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// packages/plugin-protocol/dist/json.js
|
|
371
|
+
import { z as z5 } from "zod";
|
|
372
|
+
var JsonValue = z5.lazy(() => z5.union([
|
|
373
|
+
z5.string(),
|
|
374
|
+
z5.number(),
|
|
375
|
+
z5.boolean(),
|
|
376
|
+
z5.null(),
|
|
377
|
+
z5.array(JsonValue),
|
|
378
|
+
z5.record(z5.string(), JsonValue)
|
|
379
|
+
]));
|
|
380
|
+
var JsonObject = z5.record(z5.string(), JsonValue);
|
|
381
|
+
var JsonSchema = z5.record(z5.string(), JsonValue);
|
|
374
382
|
|
|
375
|
-
// packages/
|
|
376
|
-
|
|
377
|
-
};
|
|
378
|
-
var CONFLICT_MESSAGES = {
|
|
379
|
-
changed: "This resource changed since this session last read it. Read it again before modifying it.",
|
|
380
|
-
unwitnessed: "This resource was not read in this session. Read it before modifying it.",
|
|
381
|
-
unknown: "This resource changed or was not read in this session. Read it again before modifying it."
|
|
382
|
-
};
|
|
383
|
-
var UriConflictError = class extends UriError {
|
|
384
|
-
_tag = "UriConflictError";
|
|
385
|
-
reason;
|
|
386
|
-
constructor(reason) {
|
|
387
|
-
super(CONFLICT_MESSAGES[reason ?? "unknown"]);
|
|
388
|
-
this.name = "UriConflictError";
|
|
389
|
-
this.reason = reason;
|
|
390
|
-
}
|
|
391
|
-
};
|
|
392
|
-
var UriValidationError = class extends UriError {
|
|
393
|
-
_tag = "UriValidationError";
|
|
394
|
-
constructor(message) {
|
|
395
|
-
super(message);
|
|
396
|
-
this.name = "UriValidationError";
|
|
397
|
-
}
|
|
398
|
-
};
|
|
399
|
-
function requireWriteContent(payload2, uri) {
|
|
400
|
-
if (payload2 === void 0) {
|
|
401
|
-
throw new UriValidationError(`Writing ${uri} needs \`content\` (or a \`source\` to copy from): pass the payload this address takes, which its help names.`);
|
|
402
|
-
}
|
|
403
|
-
if (payload2 instanceof Uint8Array) {
|
|
404
|
-
throw new UriValidationError(`${uri} stores text only, so it cannot take raw bytes. Copy the file to an address that accepts bytes.`);
|
|
405
|
-
}
|
|
406
|
-
return payload2;
|
|
383
|
+
// packages/plugin-sdk/dist/kay-app/card-layout.js
|
|
384
|
+
function element(type, props) {
|
|
385
|
+
return { root: "root", elements: { root: { type, props } } };
|
|
407
386
|
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
retryAfterMs;
|
|
418
|
-
/** See {@link UriProviderErrorOptions.effect}. */
|
|
419
|
-
effect;
|
|
420
|
-
/** See {@link UriProviderErrorOptions.refusalMessage}. */
|
|
421
|
-
refusalMessage;
|
|
422
|
-
constructor(options) {
|
|
423
|
-
super(options.message);
|
|
424
|
-
this.name = "UriProviderError";
|
|
425
|
-
this.moduleId = options.moduleId;
|
|
426
|
-
this.operation = options.operation;
|
|
427
|
-
this.uri = options.uri;
|
|
428
|
-
if (options.status !== void 0)
|
|
429
|
-
this.status = options.status;
|
|
430
|
-
if (options.providerCode !== void 0)
|
|
431
|
-
this.providerCode = options.providerCode;
|
|
432
|
-
if (options.retryable !== void 0)
|
|
433
|
-
this.retryable = options.retryable;
|
|
434
|
-
if (options.retryAfterMs !== void 0) {
|
|
435
|
-
if (!Number.isInteger(options.retryAfterMs) || options.retryAfterMs < 0) {
|
|
436
|
-
throw new TypeError("retryAfterMs must be a nonnegative integer.");
|
|
437
|
-
}
|
|
438
|
-
this.retryAfterMs = options.retryAfterMs;
|
|
387
|
+
function group(type, props, children) {
|
|
388
|
+
const layout = element(type, props);
|
|
389
|
+
layout.elements.root.children = children.map((child, index) => {
|
|
390
|
+
const prefix = `${index}-`;
|
|
391
|
+
for (const [key, value] of Object.entries(child.elements)) {
|
|
392
|
+
layout.elements[prefix + key] = {
|
|
393
|
+
...value,
|
|
394
|
+
...value.children ? { children: value.children.map((id) => prefix + id) } : {}
|
|
395
|
+
};
|
|
439
396
|
}
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
397
|
+
return prefix + child.root;
|
|
398
|
+
});
|
|
399
|
+
return layout;
|
|
400
|
+
}
|
|
401
|
+
function card(title, children, state) {
|
|
402
|
+
return { ...group("Card", { title }, children), ...state ? { state } : {} };
|
|
403
|
+
}
|
|
404
|
+
function row(children) {
|
|
405
|
+
return group("Row", {}, children);
|
|
406
|
+
}
|
|
407
|
+
function stack(children) {
|
|
408
|
+
return group("Stack", {}, children);
|
|
409
|
+
}
|
|
410
|
+
function field(type, name, options) {
|
|
411
|
+
const key = name.replaceAll("~", "~0").replaceAll("/", "~1");
|
|
412
|
+
return element(type, { ...options, value: { $bindState: `/form/${key}` } });
|
|
413
|
+
}
|
|
414
|
+
function textField(name, options) {
|
|
415
|
+
return field("Field", name, options);
|
|
416
|
+
}
|
|
417
|
+
function textArea(name, options) {
|
|
418
|
+
return field("TextArea", name, options);
|
|
419
|
+
}
|
|
420
|
+
function select(name, options) {
|
|
421
|
+
return field("Select", name, options);
|
|
422
|
+
}
|
|
423
|
+
function multiSelect(name, options) {
|
|
424
|
+
return field("MultiSelect", name, options);
|
|
425
|
+
}
|
|
426
|
+
function switchField(name, options) {
|
|
427
|
+
return field("Switch", name, options);
|
|
428
|
+
}
|
|
429
|
+
function submit(label) {
|
|
430
|
+
return {
|
|
431
|
+
root: "root",
|
|
432
|
+
elements: {
|
|
433
|
+
root: {
|
|
434
|
+
type: "Button",
|
|
435
|
+
props: { label },
|
|
436
|
+
on: { press: { action: "submit" } }
|
|
445
437
|
}
|
|
446
|
-
this.refusalMessage = options.refusalMessage;
|
|
447
438
|
}
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
var UriNotFoundError = class extends UriError {
|
|
451
|
-
uri;
|
|
452
|
-
hint;
|
|
453
|
-
_tag = "UriNotFoundError";
|
|
454
|
-
constructor(uri, hint) {
|
|
455
|
-
super(hint !== void 0 ? `No resource found at '${uri}'. ${hint}` : `No resource found at '${uri}'.`);
|
|
456
|
-
this.uri = uri;
|
|
457
|
-
this.hint = hint;
|
|
458
|
-
this.name = "UriNotFoundError";
|
|
459
|
-
}
|
|
460
|
-
};
|
|
461
|
-
var UriUnsupportedOperationError = class extends UriError {
|
|
462
|
-
operation;
|
|
463
|
-
moduleId;
|
|
464
|
-
uri;
|
|
465
|
-
_tag = "UriUnsupportedOperationError";
|
|
466
|
-
constructor(operation, moduleId, uri, message) {
|
|
467
|
-
super(message ?? `URI module '${moduleId}' does not support '${operation}' for '${uri}'.`);
|
|
468
|
-
this.operation = operation;
|
|
469
|
-
this.moduleId = moduleId;
|
|
470
|
-
this.uri = uri;
|
|
471
|
-
this.name = "UriUnsupportedOperationError";
|
|
472
|
-
}
|
|
473
|
-
};
|
|
474
|
-
|
|
475
|
-
// packages/herd-uri/dist/operations.js
|
|
476
|
-
import { z as z3 } from "zod";
|
|
477
|
-
var URI_OPERATIONS = [
|
|
478
|
-
"help",
|
|
479
|
-
"read",
|
|
480
|
-
"write",
|
|
481
|
-
"edit",
|
|
482
|
-
"list",
|
|
483
|
-
"search",
|
|
484
|
-
"delete"
|
|
485
|
-
];
|
|
486
|
-
var UriOperationSchema = z3.enum(URI_OPERATIONS);
|
|
487
|
-
|
|
488
|
-
// packages/herd-uri/dist/help-schema.js
|
|
489
|
-
import { z as z4 } from "zod";
|
|
490
|
-
var UriContractJsonSchema = z4.record(z4.string(), z4.unknown());
|
|
491
|
-
var UriParameterSchema = z4.strictObject({
|
|
492
|
-
name: z4.string().min(1),
|
|
493
|
-
in: z4.enum(["uri", "query", "selector"]),
|
|
494
|
-
required: z4.boolean(),
|
|
495
|
-
description: z4.string().optional(),
|
|
496
|
-
schema: UriContractJsonSchema,
|
|
497
|
-
examples: z4.array(z4.unknown()).optional()
|
|
498
|
-
});
|
|
499
|
-
var UriPayloadContractSchema = z4.strictObject({
|
|
500
|
-
name: z4.string().min(1),
|
|
501
|
-
mediaType: z4.string().optional(),
|
|
502
|
-
description: z4.string().optional(),
|
|
503
|
-
schema: UriContractJsonSchema.optional(),
|
|
504
|
-
semanticConstraints: z4.array(z4.string().min(1)).min(1).optional(),
|
|
505
|
-
examples: z4.array(z4.unknown()).optional()
|
|
506
|
-
});
|
|
439
|
+
};
|
|
440
|
+
}
|
|
507
441
|
|
|
508
|
-
// packages/
|
|
509
|
-
import { z as
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
442
|
+
// packages/plugin-sdk/dist/signals.js
|
|
443
|
+
import { z as z6 } from "zod";
|
|
444
|
+
function createFallbackOnlySignals() {
|
|
445
|
+
const noStore = { status: "unavailable", reason: "no-store" };
|
|
446
|
+
return {
|
|
447
|
+
observe: (input) => Promise.resolve(invalidObservation(input) ?? {
|
|
448
|
+
status: "unavailable",
|
|
449
|
+
reason: "no-system-one",
|
|
450
|
+
detector: { ...input.detector, rubricDigest: "" },
|
|
451
|
+
source: input.source,
|
|
452
|
+
stored: false,
|
|
453
|
+
deduplicated: false,
|
|
454
|
+
inputDigest: "",
|
|
455
|
+
recordedAtMs: Date.now()
|
|
456
|
+
}),
|
|
457
|
+
listDetectors: () => Promise.resolve(noStore),
|
|
458
|
+
list: () => Promise.resolve(noStore)
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
var SIGNAL_TIME_MAX_MS = 864e13;
|
|
462
|
+
var MAX_CHOICE_LABELS = 64;
|
|
463
|
+
var MAX_NAME = 64;
|
|
464
|
+
var MAX_POINTER = 256;
|
|
465
|
+
var MAX_QUESTIONS = 64;
|
|
466
|
+
var DETECTOR_ID = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u;
|
|
467
|
+
var VERSION = /^[A-Za-z0-9]+(?:[._-][A-Za-z0-9]+)*$/u;
|
|
468
|
+
var QUESTION_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/u;
|
|
469
|
+
var POINTER = /^[^\s\p{C}/?#]+$/u;
|
|
470
|
+
var LABEL = /^[^\s,@\p{C}]+(?: [^\s,@\p{C}]+)*$/u;
|
|
471
|
+
var RUN_ID = /^\P{Cc}+$/u;
|
|
472
|
+
var POINTER_RULE = `1 to ${MAX_POINTER} characters with no whitespace, \`/\`, \`?\`, \`#\`, or control or invisible character`;
|
|
473
|
+
var ObserveShape = z6.looseObject({
|
|
474
|
+
detector: z6.looseObject({ id: z6.string(), version: z6.string() }),
|
|
475
|
+
subject: z6.looseObject({ kind: z6.string(), key: z6.string().optional() }).optional(),
|
|
476
|
+
after: z6.looseObject({ observationId: z6.unknown() }).optional(),
|
|
477
|
+
reuse: z6.looseObject({ maxAgeMs: z6.unknown() }).optional(),
|
|
478
|
+
source: z6.looseObject({
|
|
479
|
+
sessionId: z6.string(),
|
|
480
|
+
entryId: z6.string(),
|
|
481
|
+
openerEntryId: z6.string().optional(),
|
|
482
|
+
runId: z6.string().optional(),
|
|
483
|
+
occurredAtMs: z6.unknown().optional()
|
|
484
|
+
}),
|
|
485
|
+
questions: z6.record(z6.string(), z6.unknown())
|
|
514
486
|
});
|
|
515
|
-
var
|
|
516
|
-
|
|
517
|
-
|
|
487
|
+
var ChoiceQuestion = z6.looseObject({
|
|
488
|
+
type: z6.literal("choice"),
|
|
489
|
+
criteria: z6.record(z6.string(), z6.unknown())
|
|
518
490
|
});
|
|
519
|
-
var
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
491
|
+
var fits = (value, grammar) => value.length <= MAX_NAME && grammar.test(value);
|
|
492
|
+
var isWhole = (value, min) => typeof value === "number" && Number.isSafeInteger(value) && value >= min && value <= SIGNAL_TIME_MAX_MS;
|
|
493
|
+
var quoted = (value) => JSON.stringify(value.length > 40 ? `${value.slice(0, 40)}\u2026` : value).replace(/(?! )[\s\p{C}]/gu, (char) => `\\u${char.codePointAt(0).toString(16).padStart(4, "0")}`);
|
|
494
|
+
function grammarProblem(input) {
|
|
495
|
+
const shape = ObserveShape.safeParse(input);
|
|
496
|
+
if (!shape.success) {
|
|
497
|
+
const field2 = shape.error.issues[0]?.path.join(".") ?? "";
|
|
498
|
+
return field2 === "" ? "`observe` takes an object with `detector`, `source`, `state`, and `questions`." : `\`${field2}\` is missing or has the wrong type.`;
|
|
499
|
+
}
|
|
500
|
+
const { detector, source, questions, subject, after, reuse } = shape.data;
|
|
501
|
+
const { state } = input;
|
|
502
|
+
if (typeof state !== "object" || state === null || Array.isArray(state)) {
|
|
503
|
+
return "`state` must be a JSON object.";
|
|
504
|
+
}
|
|
505
|
+
if (!fits(detector.id, DETECTOR_ID)) {
|
|
506
|
+
return "`detector.id` must be a lowercase slug of at most 64 characters: a-z and 0-9 in words joined by single hyphens.";
|
|
507
|
+
}
|
|
508
|
+
if (!fits(detector.version, VERSION)) {
|
|
509
|
+
return "`detector.version` must be at most 64 characters: letters and digits in parts joined by single `.`, `-`, or `_`.";
|
|
510
|
+
}
|
|
511
|
+
for (const [field2, grammar, rule] of [
|
|
512
|
+
["sessionId", POINTER, POINTER_RULE],
|
|
513
|
+
["entryId", POINTER, POINTER_RULE],
|
|
514
|
+
["openerEntryId", POINTER, POINTER_RULE],
|
|
515
|
+
[
|
|
516
|
+
"runId",
|
|
517
|
+
RUN_ID,
|
|
518
|
+
`1 to ${MAX_POINTER} characters with no control character`
|
|
519
|
+
]
|
|
520
|
+
]) {
|
|
521
|
+
const id = source[field2];
|
|
522
|
+
if (id !== void 0 && !(id.length <= MAX_POINTER && grammar.test(id))) {
|
|
523
|
+
return `\`source.${field2}\` must be ${rule}.`;
|
|
524
|
+
}
|
|
537
525
|
}
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
if (!/^\d+$/.test(value))
|
|
542
|
-
return void 0;
|
|
543
|
-
const n = Number.parseInt(value, 10);
|
|
544
|
-
return Number.isSafeInteger(n) && n >= 1 ? n : void 0;
|
|
545
|
-
}
|
|
546
|
-
function parseSingleRange(part) {
|
|
547
|
-
const plus = part.indexOf("+");
|
|
548
|
-
if (plus >= 0) {
|
|
549
|
-
const start2 = toInt(part.slice(0, plus));
|
|
550
|
-
const count = toInt(part.slice(plus + 1));
|
|
551
|
-
if (start2 === void 0 || count === void 0)
|
|
552
|
-
return void 0;
|
|
553
|
-
return { start: start2, end: start2 + count - 1 };
|
|
526
|
+
const occurredAtMs = source.occurredAtMs;
|
|
527
|
+
if (occurredAtMs !== void 0 && !(typeof occurredAtMs === "number" && Number.isSafeInteger(occurredAtMs) && occurredAtMs >= 0 && occurredAtMs <= SIGNAL_TIME_MAX_MS)) {
|
|
528
|
+
return `\`source.occurredAtMs\` must be whole epoch milliseconds from 0 to ${SIGNAL_TIME_MAX_MS}.`;
|
|
554
529
|
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
const start2 = toInt(part.slice(0, dash));
|
|
558
|
-
const endRaw = part.slice(dash + 1);
|
|
559
|
-
if (start2 === void 0)
|
|
560
|
-
return void 0;
|
|
561
|
-
if (endRaw.length === 0)
|
|
562
|
-
return { start: start2, end: Number.POSITIVE_INFINITY };
|
|
563
|
-
const end = toInt(endRaw);
|
|
564
|
-
if (end === void 0 || end < start2)
|
|
565
|
-
return void 0;
|
|
566
|
-
return { start: start2, end };
|
|
530
|
+
if (subject !== void 0 && !fits(subject.kind, DETECTOR_ID)) {
|
|
531
|
+
return "`subject.kind` must be a lowercase slug of at most 64 characters: a-z and 0-9 in words joined by single hyphens.";
|
|
567
532
|
}
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
if (
|
|
579
|
-
|
|
580
|
-
merged[merged.length - 1] = { start: last.start, end: range.end };
|
|
581
|
-
}
|
|
582
|
-
continue;
|
|
533
|
+
if (subject?.key !== void 0 && !(subject.key.length <= MAX_POINTER && POINTER.test(subject.key))) {
|
|
534
|
+
return `\`subject.key\` must be ${POINTER_RULE}.`;
|
|
535
|
+
}
|
|
536
|
+
if (after !== void 0 && !isWhole(after.observationId, 1)) {
|
|
537
|
+
return "`after.observationId` must be a positive whole number: the id of a stored signal.";
|
|
538
|
+
}
|
|
539
|
+
if (reuse !== void 0) {
|
|
540
|
+
if (!isWhole(reuse.maxAgeMs, 1)) {
|
|
541
|
+
return `\`reuse.maxAgeMs\` must be whole milliseconds from 1 to ${SIGNAL_TIME_MAX_MS}.`;
|
|
542
|
+
}
|
|
543
|
+
if (subject?.key === void 0) {
|
|
544
|
+
return "`reuse` needs `subject.key`: a stored answer is reused only for the same subject.";
|
|
583
545
|
}
|
|
584
|
-
merged.push(range);
|
|
585
546
|
}
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
const token = address.slice(colon + 1);
|
|
597
|
-
if (RAW_TOKEN.test(token)) {
|
|
598
|
-
if (raw)
|
|
599
|
-
break;
|
|
600
|
-
raw = true;
|
|
601
|
-
address = address.slice(0, colon);
|
|
547
|
+
const names = Object.keys(questions);
|
|
548
|
+
if (names.length === 0 || names.length > MAX_QUESTIONS) {
|
|
549
|
+
return `\`questions\` must ask 1 to ${MAX_QUESTIONS} questions.`;
|
|
550
|
+
}
|
|
551
|
+
for (const name of names) {
|
|
552
|
+
if (!fits(name, QUESTION_NAME)) {
|
|
553
|
+
return `The question name ${quoted(name)} must be an identifier of at most 64 characters: letters, digits, and \`_\`, not starting with a digit.`;
|
|
554
|
+
}
|
|
555
|
+
const choice = ChoiceQuestion.safeParse(questions[name]);
|
|
556
|
+
if (!choice.success)
|
|
602
557
|
continue;
|
|
558
|
+
const labels = Object.keys(choice.data.criteria);
|
|
559
|
+
if (labels.length > MAX_CHOICE_LABELS) {
|
|
560
|
+
return `The choice question \`${name}\` offers ${labels.length} labels; at most ${MAX_CHOICE_LABELS}.`;
|
|
561
|
+
}
|
|
562
|
+
const bad = labels.find((label) => !fits(label, LABEL));
|
|
563
|
+
if (bad !== void 0) {
|
|
564
|
+
return `The choice question \`${name}\` offers the label ${quoted(bad)}, which a \`where\` filter cannot name: a label is 1 to 64 characters with no \`,\`, \`@\`, or control or invisible character, and no whitespace but single spaces between words.`;
|
|
603
565
|
}
|
|
604
|
-
const parsed = parseRangeListToken(token);
|
|
605
|
-
if (parsed === void 0)
|
|
606
|
-
break;
|
|
607
|
-
if (ranges !== void 0)
|
|
608
|
-
break;
|
|
609
|
-
ranges = parsed;
|
|
610
|
-
address = address.slice(0, colon);
|
|
611
566
|
}
|
|
567
|
+
return void 0;
|
|
568
|
+
}
|
|
569
|
+
var EchoText = z6.string().catch("");
|
|
570
|
+
var Echo = z6.object({
|
|
571
|
+
detector: z6.object({ id: EchoText, version: EchoText }).catch({ id: "", version: "" }),
|
|
572
|
+
source: z6.object({ sessionId: EchoText, entryId: EchoText }).catch({ sessionId: "", entryId: "" })
|
|
573
|
+
}).catch({
|
|
574
|
+
detector: { id: "", version: "" },
|
|
575
|
+
source: { sessionId: "", entryId: "" }
|
|
576
|
+
});
|
|
577
|
+
function invalidObservation(input) {
|
|
578
|
+
const reason = grammarProblem(input);
|
|
579
|
+
if (reason === void 0)
|
|
580
|
+
return void 0;
|
|
581
|
+
const { detector, source } = Echo.parse(input);
|
|
612
582
|
return {
|
|
613
|
-
|
|
614
|
-
|
|
583
|
+
status: "invalid",
|
|
584
|
+
reason,
|
|
585
|
+
detector: { ...detector, rubricDigest: "" },
|
|
586
|
+
source,
|
|
587
|
+
stored: false,
|
|
588
|
+
deduplicated: false,
|
|
589
|
+
inputDigest: "",
|
|
590
|
+
recordedAtMs: Date.now()
|
|
615
591
|
};
|
|
616
592
|
}
|
|
617
593
|
|
|
618
|
-
// packages/herd-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
594
|
+
// packages/herd-transcript/dist/record-kinds.js
|
|
595
|
+
var STORED_TRANSCRIPT_MESSAGE_KINDS = [
|
|
596
|
+
"user",
|
|
597
|
+
"assistant",
|
|
598
|
+
"tool_result",
|
|
599
|
+
"custom_message:*",
|
|
600
|
+
"compaction",
|
|
601
|
+
"branch_summary"
|
|
602
|
+
];
|
|
603
|
+
var NAMED_KINDS = /* @__PURE__ */ new Set([
|
|
604
|
+
"user",
|
|
605
|
+
"assistant",
|
|
606
|
+
"tool_result",
|
|
607
|
+
"compaction",
|
|
608
|
+
"branch_summary",
|
|
609
|
+
"other",
|
|
610
|
+
"unreadable"
|
|
611
|
+
]);
|
|
612
|
+
var ROLE_KINDS = {
|
|
613
|
+
user: "user",
|
|
614
|
+
assistant: "assistant",
|
|
615
|
+
toolResult: "tool_result"
|
|
616
|
+
};
|
|
617
|
+
function storedTranscriptKindOf(record) {
|
|
618
|
+
if (!("entry" in record))
|
|
619
|
+
return "unreadable";
|
|
620
|
+
const entry = record.entry;
|
|
621
|
+
switch (entry.type) {
|
|
622
|
+
case "message": {
|
|
623
|
+
const message = entry.message;
|
|
624
|
+
if (message.role === "custom") {
|
|
625
|
+
return `custom_message:${typeof message.customType === "string" ? message.customType : ""}`;
|
|
626
|
+
}
|
|
627
|
+
return (typeof message.role === "string" ? ROLE_KINDS[message.role] : void 0) ?? "other";
|
|
628
|
+
}
|
|
629
|
+
case "custom":
|
|
630
|
+
return `custom:${entry.customType}`;
|
|
631
|
+
case "compaction":
|
|
632
|
+
return "compaction";
|
|
633
|
+
case "branch_summary":
|
|
634
|
+
return "branch_summary";
|
|
635
|
+
default:
|
|
636
|
+
return "other";
|
|
645
637
|
}
|
|
646
|
-
return structuredClone(schema);
|
|
647
638
|
}
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
639
|
+
function parseStoredTranscriptKindFilter(tokens) {
|
|
640
|
+
const exact = /* @__PURE__ */ new Set();
|
|
641
|
+
const families = /* @__PURE__ */ new Set();
|
|
642
|
+
let all = false;
|
|
643
|
+
for (const raw of tokens) {
|
|
644
|
+
const token = raw.trim();
|
|
645
|
+
if (token === "all") {
|
|
646
|
+
all = true;
|
|
647
|
+
} else if (token === "messages") {
|
|
648
|
+
for (const kind of STORED_TRANSCRIPT_MESSAGE_KINDS)
|
|
649
|
+
addToken(kind);
|
|
650
|
+
} else if (!addToken(token)) {
|
|
651
|
+
return { ok: false, invalid: raw };
|
|
652
|
+
}
|
|
653
|
+
}
|
|
651
654
|
return {
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
...options.semanticConstraints === void 0 ? {} : { semanticConstraints: options.semanticConstraints },
|
|
657
|
-
...options.examples === void 0 ? {} : { examples: options.examples }
|
|
655
|
+
ok: true,
|
|
656
|
+
filter: {
|
|
657
|
+
includes: (kind) => all || exact.has(kind) || families.has(kind.slice(0, kind.indexOf(":") + 1))
|
|
658
|
+
}
|
|
658
659
|
};
|
|
660
|
+
function addToken(token) {
|
|
661
|
+
if (NAMED_KINDS.has(token)) {
|
|
662
|
+
exact.add(token);
|
|
663
|
+
return true;
|
|
664
|
+
}
|
|
665
|
+
const family = /^(custom|custom_message):(.+)$/.exec(token);
|
|
666
|
+
if (family === null)
|
|
667
|
+
return false;
|
|
668
|
+
if (family[2] === "*")
|
|
669
|
+
families.add(`${family[1]}:`);
|
|
670
|
+
else
|
|
671
|
+
exact.add(token);
|
|
672
|
+
return true;
|
|
673
|
+
}
|
|
659
674
|
}
|
|
675
|
+
var STORED_TRANSCRIPT_MESSAGE_FILTER = (() => {
|
|
676
|
+
const parsed = parseStoredTranscriptKindFilter(STORED_TRANSCRIPT_MESSAGE_KINDS);
|
|
677
|
+
if (!parsed.ok)
|
|
678
|
+
throw new Error(`invalid default kinds: ${parsed.invalid}`);
|
|
679
|
+
return parsed.filter;
|
|
680
|
+
})();
|
|
681
|
+
|
|
682
|
+
// packages/plugin-sdk/dist/kay-app/index.js
|
|
683
|
+
import { pathToFileURL } from "node:url";
|
|
660
684
|
|
|
661
685
|
// packages/plugin-sdk/dist/kay-app/auth.js
|
|
662
686
|
var KayAppCredentialRejectedError = class extends Error {
|
|
@@ -1078,12 +1102,14 @@ export {
|
|
|
1078
1102
|
UriUnsupportedOperationError,
|
|
1079
1103
|
UriValidationError,
|
|
1080
1104
|
card,
|
|
1105
|
+
contentDigest,
|
|
1081
1106
|
createConsoleKayPluginLog,
|
|
1082
1107
|
createFallbackOnlySignals,
|
|
1083
1108
|
createKayPluginLog,
|
|
1084
1109
|
createUnavailableSealing,
|
|
1085
1110
|
createUnavailableSkills,
|
|
1086
1111
|
createUnavailableTools,
|
|
1112
|
+
createUnavailableUriCaller,
|
|
1087
1113
|
createUnavailableUsage,
|
|
1088
1114
|
declaredAppToolDefinition,
|
|
1089
1115
|
definePoller,
|