@ruakit/schema 0.0.0-stage → 0.1.0-alpha.1
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/LICENSE +21 -0
- package/NOTICE +4 -0
- package/dist/decision.d.ts +706 -0
- package/dist/decision.d.ts.map +1 -0
- package/dist/decision.js +3 -0
- package/dist/decision.js.map +7 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +7 -0
- package/dist/plan.d.ts +1126 -0
- package/dist/plan.d.ts.map +1 -0
- package/dist/plan.js +3 -0
- package/dist/plan.js.map +7 -0
- package/dist/protocol.d.ts +99 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +3 -0
- package/dist/protocol.js.map +7 -0
- package/dist/verification.d.ts +162 -0
- package/dist/verification.d.ts.map +1 -0
- package/dist/verification.js +5 -0
- package/dist/verification.js.map +7 -0
- package/package.json +25 -3
- package/src/decision.ts +159 -0
- package/src/index.ts +5 -0
- package/src/plan.ts +177 -0
- package/src/protocol.ts +37 -0
- package/src/verification.ts +204 -0
- package/README.md +0 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan.d.ts","sourceRoot":"","sources":["../src/plan.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAiBxB,qFAAqF;AACrF,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4BAQ5B,CAAC;AAEH,iEAAiE;AACjE,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oBAe7B,CAAC;AAEH,wBAAwB;AACxB,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AAC9C,4BAA4B;AAC5B,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAC5D,iDAAiD;AACjD,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AACxE,wCAAwC;AACxC,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAClD,oCAAoC;AACpC,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAC5D,qCAAqC;AACrC,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAC9D,4CAA4C;AAC5C,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
|
package/dist/plan.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// Copyright 2026 RuaKit contributors. SPDX-License-Identifier: MIT
|
|
2
|
+
var b=Object.defineProperty;var a=(t,n)=>b(t,"name",{value:n,configurable:!0});import{z as e}from"zod";import{decisionRequestSchema as y,actionSchema as r}from"./decision.js";import{completionChecksSchema as x,controlLocatorSchema as O}from"./verification.js";const s=e.string().trim().min(1).max(200),i={id:s,message:e.string().trim().min(1).max(2e3),target:O},f=e.discriminatedUnion("type",[r.options[0].extend(i),r.options[1].extend(i),r.options[2].extend(i),r.options[3].extend(i),r.options[4].extend(i),r.options[5].extend(i),r.options[6].extend(i)]),h=e.strictObject({id:s,replacesPlanId:s.optional(),message:e.string().trim().min(1).max(2e3),steps:e.array(f).max(50).refine(t=>new Set(t.map(n=>n.id)).size===t.length,"Plan step IDs must be distinct."),checks:x}),j=e.strictObject({type:e.literal("approval"),message:e.string().trim().min(1).max(2e3),plan:h}),z=e.strictObject({planId:s,step:f}),I=e.strictObject({planId:s,completedSteps:e.array(z).max(200),failedStepId:s.nullable(),reason:e.enum(["target-unavailable","target-stale","outcome-mismatch"]),message:e.string().min(1).max(2e3)});function k(t){return t===null||typeof t=="boolean"?5:typeof t=="string"?t.length:typeof t=="number"&&Number.isFinite(t)?24:null}a(k,"primitiveSize");function N(t){if(Array.isArray(t))return!0;const n=Object.getPrototypeOf(t);return n===Object.prototype||n===null}a(N,"isJsonContainer");function P(t){const c=[{value:t,depth:0}],m=new Set;let p=0,d=0;for(;c.length>0;){const l=c.pop(),o=l.value;if(d+=1,d>2048||l.depth>8)return!1;const u=k(o);if(u!==null)p+=u;else if(typeof o=="object"&&o!==null){if(m.has(o)||(m.add(o),!N(o)))return!1;for(const[g,S]of Object.entries(o))p+=g.length+4,c.push({value:S,depth:l.depth+1})}else return!1;if(p>32768)return!1}return!0}a(P,"boundedJson");const w=e.custom(P,"Expected bounded JSON context."),E=y.omit({history:!0}).extend({protocol:e.literal("plan"),context:w.optional(),checks:x.nullable(),replan:I.nullable()}),F=e.union([h,j,e.strictObject({type:e.literal("clarify"),message:e.string().min(1).max(500)}),e.strictObject({type:e.literal("screenshot"),message:e.string().min(1).max(2e3)}),e.strictObject({type:e.literal("unsupported"),message:e.string().min(1).max(2e3)})]);export{z as completedPlanStepSchema,j as planApprovalSchema,w as planContextSchema,E as planRequestSchema,F as planResponseSchema,h as planSchema,f as plannedStepSchema,I as replanSchema};
|
|
3
|
+
//# sourceMappingURL=plan.js.map
|
package/dist/plan.js.map
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/plan.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright 2026 RuaKit contributors. SPDX-License-Identifier: MIT\nimport { z } from 'zod';\nimport { decisionRequestSchema, actionSchema } from './decision.js';\nimport {\n completionChecksSchema,\n controlLocatorSchema,\n} from './verification.js';\n\n/** Shared constraints for plan and step identifiers. */\nconst identifier = z.string().trim().min(1).max(200);\n\n/** Fields added to each action when it becomes a planned step. */\nconst metadata = {\n id: identifier,\n message: z.string().trim().min(1).max(2000),\n target: controlLocatorSchema,\n};\n\n/** Resolve these locators against a fresh observation before executing each step. */\nexport const plannedStepSchema = z.discriminatedUnion('type', [\n actionSchema.options[0].extend(metadata),\n actionSchema.options[1].extend(metadata),\n actionSchema.options[2].extend(metadata),\n actionSchema.options[3].extend(metadata),\n actionSchema.options[4].extend(metadata),\n actionSchema.options[5].extend(metadata),\n actionSchema.options[6].extend(metadata),\n]);\n\n/** An ordered plan and the checks used to assess its outcome. */\nexport const planSchema = z.strictObject({\n id: identifier,\n replacesPlanId: identifier.optional(),\n message: z.string().trim().min(1).max(2000),\n steps: z\n .array(plannedStepSchema)\n .max(50)\n .refine(\n (steps) => new Set(steps.map((step) => step.id)).size === steps.length,\n 'Plan step IDs must be distinct.',\n ),\n checks: completionChecksSchema,\n});\n\n/** Approval covers this concrete plan revision, including every action and argument. */\nexport const planApprovalSchema = z.strictObject({\n type: z.literal('approval'),\n message: z.string().trim().min(1).max(2000),\n plan: planSchema,\n});\n\n/** A step that has already been executed as part of a plan. */\nexport const completedPlanStepSchema = z.strictObject({\n planId: identifier,\n step: plannedStepSchema,\n});\n\n/** Execution history and reason supplied when requesting a replacement plan. */\nexport const replanSchema = z.strictObject({\n planId: identifier,\n completedSteps: z.array(completedPlanStepSchema).max(200),\n failedStepId: identifier.nullable(),\n reason: z.enum(['target-unavailable', 'target-stale', 'outcome-mismatch']),\n message: z.string().min(1).max(2000),\n});\n\n/** JSON-compatible context accepted by the planning protocol. */\nexport type JsonValue =\n string | number | boolean | null | JsonValue[] | { [key: string]: JsonValue };\n\n/** Return the estimated size of a JSON primitive, or null for other values. */\nfunction primitiveSize(value: unknown): number | null {\n if (value === null || typeof value === 'boolean') return 5;\n if (typeof value === 'string') return value.length;\n if (typeof value === 'number' && Number.isFinite(value)) return 24;\n return null;\n}\n\n/** Accept arrays and plain objects, but not class instances or other objects. */\nfunction isJsonContainer(value: object): boolean {\n if (Array.isArray(value)) return true;\n\n const prototype = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n}\n\n/** Check that context is plain JSON within the protocol's traversal and size limits. */\nfunction boundedJson(value: unknown): value is JsonValue {\n const maxNodes = 2048;\n const maxDepth = 8;\n const maxSize = 32768;\n\n // Track pending values, visited objects, and the estimated serialized size.\n const pending = [{ value, depth: 0 }];\n const seen = new Set<object>();\n let size = 0;\n let nodes = 0;\n\n while (pending.length > 0) {\n const item = pending.pop()!;\n const current = item.value;\n\n nodes += 1;\n if (nodes > maxNodes || item.depth > maxDepth) return false;\n\n const estimatedSize = primitiveSize(current);\n if (estimatedSize !== null) {\n size += estimatedSize;\n } else if (typeof current === 'object' && current !== null) {\n // Repeated references, cycles, and non-plain objects are not accepted.\n if (seen.has(current)) return false;\n seen.add(current);\n if (!isJsonContainer(current)) return false;\n\n // Account for property names and visit their values at the next depth.\n for (const [key, child] of Object.entries(current)) {\n size += key.length + 4;\n pending.push({ value: child, depth: item.depth + 1 });\n }\n } else {\n return false;\n }\n\n if (size > maxSize) return false;\n }\n\n return true;\n}\n\n/** Context is JSON data, bounded independently of page observations and images. */\nexport const planContextSchema = z.custom<JsonValue>(\n boundedJson,\n 'Expected bounded JSON context.',\n);\n\n/** Request for a plan, optionally including application context and replan history. */\nexport const planRequestSchema = decisionRequestSchema\n .omit({ history: true })\n .extend({\n protocol: z.literal('plan'),\n context: planContextSchema.optional(),\n checks: completionChecksSchema.nullable(),\n replan: replanSchema.nullable(),\n });\n\n/** A plan or a response explaining what the planner needs next. */\nexport const planResponseSchema = z.union([\n planSchema,\n planApprovalSchema,\n z.strictObject({\n type: z.literal('clarify'),\n message: z.string().min(1).max(500),\n }),\n z.strictObject({\n type: z.literal('screenshot'),\n message: z.string().min(1).max(2000),\n }),\n z.strictObject({\n type: z.literal('unsupported'),\n message: z.string().min(1).max(2000),\n }),\n]);\n\n/** A validated plan. */\nexport type Plan = z.infer<typeof planSchema>;\n/** One action in a plan. */\nexport type PlannedStep = z.infer<typeof plannedStepSchema>;\n/** A completed step and its originating plan. */\nexport type CompletedPlanStep = z.infer<typeof completedPlanStepSchema>;\n/** The context for replacing a plan. */\nexport type Replan = z.infer<typeof replanSchema>;\n/** A validated planning request. */\nexport type PlanRequest = z.infer<typeof planRequestSchema>;\n/** A validated planning response. */\nexport type PlanResponse = z.infer<typeof planResponseSchema>;\n/** A request to approve a concrete plan. */\nexport type PlanApproval = z.infer<typeof planApprovalSchema>;\n"],
|
|
5
|
+
"mappings": ";+EACA,OAAS,KAAAA,MAAS,MAClB,OAAS,yBAAAC,EAAuB,gBAAAC,MAAoB,gBACpD,OACE,0BAAAC,EACA,wBAAAC,MACK,oBAGP,MAAMC,EAAaL,EAAE,OAAM,EAAG,KAAI,EAAG,IAAI,CAAC,EAAE,IAAI,GAAG,EAG7CM,EAAW,CACf,GAAID,EACJ,QAASL,EAAE,OAAM,EAAG,KAAI,EAAG,IAAI,CAAC,EAAE,IAAI,GAAI,EAC1C,OAAQI,GAIGG,EAAoBP,EAAE,mBAAmB,OAAQ,CAC5DE,EAAa,QAAQ,CAAC,EAAE,OAAOI,CAAQ,EACvCJ,EAAa,QAAQ,CAAC,EAAE,OAAOI,CAAQ,EACvCJ,EAAa,QAAQ,CAAC,EAAE,OAAOI,CAAQ,EACvCJ,EA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AE,IAAI,GAAG,EACnC,EACDA,EAAE,aAAa,CACb,KAAMA,EAAE,QAAQ,YAAY,EAC5B,QAASA,EAAE,OAAM,EAAG,IAAI,CAAC,EAAE,IAAI,GAAI,EACpC,EACDA,EAAE,aAAa,CACb,KAAMA,EAAE,QAAQ,aAAa,EAC7B,QAASA,EAAE,OAAM,EAAG,IAAI,CAAC,EAAE,IAAI,GAAI,EACpC,EACF",
|
|
6
|
+
"names": ["z", "decisionRequestSchema", "actionSchema", "completionChecksSchema", "controlLocatorSchema", "identifier", "metadata", "plannedStepSchema", "planSchema", "steps", "step", "planApprovalSchema", "completedPlanStepSchema", "replanSchema", "primitiveSize", "value", "__name", "isJsonContainer", "prototype", "boundedJson", "pending", "seen", "size", "nodes", "item", "current", "estimatedSize", "key", "child", "planContextSchema", "planRequestSchema", "planResponseSchema"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { DecisionRequest } from './decision.js';
|
|
3
|
+
/** Name of the HTML metadata element used for runtime configuration. */
|
|
4
|
+
export declare const RUNTIME_META_NAME = "ruakit-config";
|
|
5
|
+
/** A conversational response contains no executable instructions. */
|
|
6
|
+
export declare const clarificationSchema: z.ZodObject<{
|
|
7
|
+
type: z.ZodLiteral<"clarification">;
|
|
8
|
+
question: z.ZodString;
|
|
9
|
+
options: z.ZodArray<z.ZodString>;
|
|
10
|
+
}, z.core.$strict>;
|
|
11
|
+
/** Result of an execution, including any observed verification evidence. */
|
|
12
|
+
export declare const resultSchema: z.ZodObject<{
|
|
13
|
+
planId: z.ZodString;
|
|
14
|
+
status: z.ZodEnum<{
|
|
15
|
+
triggered: "triggered";
|
|
16
|
+
failed: "failed";
|
|
17
|
+
}>;
|
|
18
|
+
events: z.ZodArray<z.ZodString>;
|
|
19
|
+
goalCompleted: z.ZodOptional<z.ZodLiteral<true>>;
|
|
20
|
+
verification: z.ZodOptional<z.ZodObject<{
|
|
21
|
+
level: z.ZodEnum<{
|
|
22
|
+
observed: "observed";
|
|
23
|
+
confirmed: "confirmed";
|
|
24
|
+
}>;
|
|
25
|
+
checks: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
26
|
+
type: z.ZodLiteral<"value">;
|
|
27
|
+
description: z.ZodString;
|
|
28
|
+
control: z.ZodObject<{
|
|
29
|
+
id: z.ZodNullable<z.ZodString>;
|
|
30
|
+
role: z.ZodString;
|
|
31
|
+
label: z.ZodString;
|
|
32
|
+
context: z.ZodNullable<z.ZodString>;
|
|
33
|
+
group: z.ZodNullable<z.ZodString>;
|
|
34
|
+
}, z.core.$strict>;
|
|
35
|
+
equals: z.ZodString;
|
|
36
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
37
|
+
type: z.ZodLiteral<"checked">;
|
|
38
|
+
description: z.ZodString;
|
|
39
|
+
control: z.ZodObject<{
|
|
40
|
+
id: z.ZodNullable<z.ZodString>;
|
|
41
|
+
role: z.ZodString;
|
|
42
|
+
label: z.ZodString;
|
|
43
|
+
context: z.ZodNullable<z.ZodString>;
|
|
44
|
+
group: z.ZodNullable<z.ZodString>;
|
|
45
|
+
}, z.core.$strict>;
|
|
46
|
+
equals: z.ZodBoolean;
|
|
47
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
48
|
+
type: z.ZodLiteral<"selected">;
|
|
49
|
+
description: z.ZodString;
|
|
50
|
+
control: z.ZodObject<{
|
|
51
|
+
id: z.ZodNullable<z.ZodString>;
|
|
52
|
+
role: z.ZodString;
|
|
53
|
+
label: z.ZodString;
|
|
54
|
+
context: z.ZodNullable<z.ZodString>;
|
|
55
|
+
group: z.ZodNullable<z.ZodString>;
|
|
56
|
+
}, z.core.$strict>;
|
|
57
|
+
equals: z.ZodArray<z.ZodString>;
|
|
58
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
59
|
+
type: z.ZodLiteral<"text">;
|
|
60
|
+
description: z.ZodString;
|
|
61
|
+
text: z.ZodString;
|
|
62
|
+
fresh: z.ZodBoolean;
|
|
63
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
64
|
+
type: z.ZodLiteral<"url">;
|
|
65
|
+
description: z.ZodString;
|
|
66
|
+
equals: z.ZodString;
|
|
67
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
68
|
+
type: z.ZodLiteral<"absent">;
|
|
69
|
+
description: z.ZodString;
|
|
70
|
+
control: z.ZodObject<{
|
|
71
|
+
id: z.ZodNullable<z.ZodString>;
|
|
72
|
+
role: z.ZodString;
|
|
73
|
+
label: z.ZodString;
|
|
74
|
+
context: z.ZodNullable<z.ZodString>;
|
|
75
|
+
group: z.ZodNullable<z.ZodString>;
|
|
76
|
+
}, z.core.$strict>;
|
|
77
|
+
}, z.core.$strict>], "type">>;
|
|
78
|
+
}, z.core.$strict>>;
|
|
79
|
+
screenshot: z.ZodOptional<z.ZodObject<{
|
|
80
|
+
data: z.ZodString;
|
|
81
|
+
mimeType: z.ZodEnum<{
|
|
82
|
+
"image/png": "image/png";
|
|
83
|
+
"image/jpeg": "image/jpeg";
|
|
84
|
+
"image/webp": "image/webp";
|
|
85
|
+
}>;
|
|
86
|
+
width: z.ZodNumber;
|
|
87
|
+
height: z.ZodNumber;
|
|
88
|
+
capturedAt: z.ZodNumber;
|
|
89
|
+
url: z.ZodString;
|
|
90
|
+
}, z.core.$strict>>;
|
|
91
|
+
message: z.ZodOptional<z.ZodString>;
|
|
92
|
+
}, z.core.$strict>;
|
|
93
|
+
/** A question and optional choices returned to the user. */
|
|
94
|
+
export type Clarification = z.infer<typeof clarificationSchema>;
|
|
95
|
+
/** One question and answer included in a decision request. */
|
|
96
|
+
export type ClarificationTurn = DecisionRequest['clarifications'][number];
|
|
97
|
+
/** A validated execution result. */
|
|
98
|
+
export type ExecutionResult = z.infer<typeof resultSchema>;
|
|
99
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAGrD,wEAAwE;AACxE,eAAO,MAAM,iBAAiB,kBAAkB,CAAC;AAEjD,qEAAqE;AACrE,eAAO,MAAM,mBAAmB;;;;kBAO9B,CAAC;AAEH,4EAA4E;AAC5E,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAUvB,CAAC;AAEH,4DAA4D;AAC5D,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAChE,8DAA8D;AAC9D,MAAM,MAAM,iBAAiB,GAAG,eAAe,CAAC,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AAC1E,oCAAoC;AACpC,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC"}
|
package/dist/protocol.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// Copyright 2026 RuaKit contributors. SPDX-License-Identifier: MIT
|
|
2
|
+
import{z as t}from"zod";import{completionChecksSchema as i,screenshotSchema as r}from"./verification.js";const a="ruakit-config",c=t.strictObject({type:t.literal("clarification"),question:t.string().trim().min(1).max(500),options:t.array(t.string().trim().min(1).max(400)).max(4).refine(e=>new Set(e).size===e.length,"Expected distinct options.")}),s=t.strictObject({planId:t.string().min(1).max(200),status:t.enum(["triggered","failed"]),events:t.array(t.string().max(500)).max(220),goalCompleted:t.literal(!0).optional(),verification:t.strictObject({level:t.enum(["observed","confirmed"]),checks:i}).optional(),screenshot:r.optional(),message:t.string().max(2e3).optional()});export{a as RUNTIME_META_NAME,c as clarificationSchema,s as resultSchema};
|
|
3
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/protocol.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright 2026 RuaKit contributors. SPDX-License-Identifier: MIT\nimport { z } from 'zod';\nimport type { DecisionRequest } from './decision.js';\nimport { completionChecksSchema, screenshotSchema } from './verification.js';\n\n/** Name of the HTML metadata element used for runtime configuration. */\nexport const RUNTIME_META_NAME = 'ruakit-config';\n\n/** A conversational response contains no executable instructions. */\nexport const clarificationSchema = z.strictObject({\n type: z.literal('clarification'),\n question: z.string().trim().min(1).max(500),\n options: z\n .array(z.string().trim().min(1).max(400))\n .max(4)\n .refine((items) => new Set(items).size === items.length, 'Expected distinct options.'),\n});\n\n/** Result of an execution, including any observed verification evidence. */\nexport const resultSchema = z.strictObject({\n planId: z.string().min(1).max(200),\n status: z.enum(['triggered', 'failed']),\n events: z.array(z.string().max(500)).max(220),\n goalCompleted: z.literal(true).optional(),\n verification: z\n .strictObject({ level: z.enum(['observed', 'confirmed']), checks: completionChecksSchema })\n .optional(),\n screenshot: screenshotSchema.optional(),\n message: z.string().max(2000).optional(),\n});\n\n/** A question and optional choices returned to the user. */\nexport type Clarification = z.infer<typeof clarificationSchema>;\n/** One question and answer included in a decision request. */\nexport type ClarificationTurn = DecisionRequest['clarifications'][number];\n/** A validated execution result. */\nexport type ExecutionResult = z.infer<typeof resultSchema>;\n"],
|
|
5
|
+
"mappings": ";AACA,OAAS,KAAAA,MAAS,MAElB,OAAS,0BAAAC,EAAwB,oBAAAC,MAAwB,oBAGlD,MAAMC,EAAoB,gBAGpBC,EAAsBJ,EAAE,aAAa,CAChD,KAAMA,EAAE,QAAQ,eAAe,EAC/B,SAAUA,EAAE,OAAM,EAAG,KAAI,EAAG,IAAI,CAAC,EAAE,IAAI,GAAG,EAC1C,QAASA,EACN,MAAMA,EAAE,OAAM,EAAG,KAAI,EAAG,IAAI,CAAC,EAAE,IAAI,GAAG,CAAC,EACvC,IAAI,CAAC,EACL,OAAQK,GAAU,IAAI,IAAIA,CAAK,EAAE,OAASA,EAAM,OAAQ,4BAA4B,EACxF,EAGYC,EAAeN,EAAE,aAAa,CACzC,OAAQA,EAAE,OAAM,EAAG,IAAI,CAAC,EAAE,IAAI,GAAG,EACjC,OAAQA,EAAE,KAAK,CAAC,YAAa,QAAQ,CAAC,EACtC,OAAQA,EAAE,MAAMA,EAAE,OAAM,EAAG,IAAI,GAAG,CAAC,EAAE,IAAI,GAAG,EAC5C,cAAeA,EAAE,QAAQ,EAAI,EAAE,SAAQ,EACvC,aAAcA,EACX,aAAa,CAAE,MAAOA,EAAE,KAAK,CAAC,WAAY,WAAW,CAAC,EAAG,OAAQC,CAAsB,CAAE,EACzF,SAAQ,EACX,WAAYC,EAAiB,SAAQ,EACrC,QAASF,EAAE,OAAM,EAAG,IAAI,GAAI,EAAE,SAAQ,EACvC",
|
|
6
|
+
"names": ["z", "completionChecksSchema", "screenshotSchema", "RUNTIME_META_NAME", "clarificationSchema", "items", "resultSchema"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** Identifies a control by its observed identity and accessible context. */
|
|
3
|
+
export declare const controlLocatorSchema: z.ZodObject<{
|
|
4
|
+
id: z.ZodNullable<z.ZodString>;
|
|
5
|
+
role: z.ZodString;
|
|
6
|
+
label: z.ZodString;
|
|
7
|
+
context: z.ZodNullable<z.ZodString>;
|
|
8
|
+
group: z.ZodNullable<z.ZodString>;
|
|
9
|
+
}, z.core.$strict>;
|
|
10
|
+
/** A single observable condition that can establish progress toward a goal. */
|
|
11
|
+
export declare const completionCheckSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
12
|
+
type: z.ZodLiteral<"value">;
|
|
13
|
+
description: z.ZodString;
|
|
14
|
+
control: z.ZodObject<{
|
|
15
|
+
id: z.ZodNullable<z.ZodString>;
|
|
16
|
+
role: z.ZodString;
|
|
17
|
+
label: z.ZodString;
|
|
18
|
+
context: z.ZodNullable<z.ZodString>;
|
|
19
|
+
group: z.ZodNullable<z.ZodString>;
|
|
20
|
+
}, z.core.$strict>;
|
|
21
|
+
equals: z.ZodString;
|
|
22
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
23
|
+
type: z.ZodLiteral<"checked">;
|
|
24
|
+
description: z.ZodString;
|
|
25
|
+
control: z.ZodObject<{
|
|
26
|
+
id: z.ZodNullable<z.ZodString>;
|
|
27
|
+
role: z.ZodString;
|
|
28
|
+
label: z.ZodString;
|
|
29
|
+
context: z.ZodNullable<z.ZodString>;
|
|
30
|
+
group: z.ZodNullable<z.ZodString>;
|
|
31
|
+
}, z.core.$strict>;
|
|
32
|
+
equals: z.ZodBoolean;
|
|
33
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
34
|
+
type: z.ZodLiteral<"selected">;
|
|
35
|
+
description: z.ZodString;
|
|
36
|
+
control: z.ZodObject<{
|
|
37
|
+
id: z.ZodNullable<z.ZodString>;
|
|
38
|
+
role: z.ZodString;
|
|
39
|
+
label: z.ZodString;
|
|
40
|
+
context: z.ZodNullable<z.ZodString>;
|
|
41
|
+
group: z.ZodNullable<z.ZodString>;
|
|
42
|
+
}, z.core.$strict>;
|
|
43
|
+
equals: z.ZodArray<z.ZodString>;
|
|
44
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
45
|
+
type: z.ZodLiteral<"text">;
|
|
46
|
+
description: z.ZodString;
|
|
47
|
+
text: z.ZodString;
|
|
48
|
+
fresh: z.ZodBoolean;
|
|
49
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
50
|
+
type: z.ZodLiteral<"url">;
|
|
51
|
+
description: z.ZodString;
|
|
52
|
+
equals: z.ZodString;
|
|
53
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
54
|
+
type: z.ZodLiteral<"absent">;
|
|
55
|
+
description: z.ZodString;
|
|
56
|
+
control: z.ZodObject<{
|
|
57
|
+
id: z.ZodNullable<z.ZodString>;
|
|
58
|
+
role: z.ZodString;
|
|
59
|
+
label: z.ZodString;
|
|
60
|
+
context: z.ZodNullable<z.ZodString>;
|
|
61
|
+
group: z.ZodNullable<z.ZodString>;
|
|
62
|
+
}, z.core.$strict>;
|
|
63
|
+
}, z.core.$strict>], "type">;
|
|
64
|
+
/** A nonempty, bounded collection of outcome checks. */
|
|
65
|
+
export declare const completionChecksSchema: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
66
|
+
type: z.ZodLiteral<"value">;
|
|
67
|
+
description: z.ZodString;
|
|
68
|
+
control: z.ZodObject<{
|
|
69
|
+
id: z.ZodNullable<z.ZodString>;
|
|
70
|
+
role: z.ZodString;
|
|
71
|
+
label: z.ZodString;
|
|
72
|
+
context: z.ZodNullable<z.ZodString>;
|
|
73
|
+
group: z.ZodNullable<z.ZodString>;
|
|
74
|
+
}, z.core.$strict>;
|
|
75
|
+
equals: z.ZodString;
|
|
76
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
77
|
+
type: z.ZodLiteral<"checked">;
|
|
78
|
+
description: z.ZodString;
|
|
79
|
+
control: z.ZodObject<{
|
|
80
|
+
id: z.ZodNullable<z.ZodString>;
|
|
81
|
+
role: z.ZodString;
|
|
82
|
+
label: z.ZodString;
|
|
83
|
+
context: z.ZodNullable<z.ZodString>;
|
|
84
|
+
group: z.ZodNullable<z.ZodString>;
|
|
85
|
+
}, z.core.$strict>;
|
|
86
|
+
equals: z.ZodBoolean;
|
|
87
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
88
|
+
type: z.ZodLiteral<"selected">;
|
|
89
|
+
description: z.ZodString;
|
|
90
|
+
control: z.ZodObject<{
|
|
91
|
+
id: z.ZodNullable<z.ZodString>;
|
|
92
|
+
role: z.ZodString;
|
|
93
|
+
label: z.ZodString;
|
|
94
|
+
context: z.ZodNullable<z.ZodString>;
|
|
95
|
+
group: z.ZodNullable<z.ZodString>;
|
|
96
|
+
}, z.core.$strict>;
|
|
97
|
+
equals: z.ZodArray<z.ZodString>;
|
|
98
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
99
|
+
type: z.ZodLiteral<"text">;
|
|
100
|
+
description: z.ZodString;
|
|
101
|
+
text: z.ZodString;
|
|
102
|
+
fresh: z.ZodBoolean;
|
|
103
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
104
|
+
type: z.ZodLiteral<"url">;
|
|
105
|
+
description: z.ZodString;
|
|
106
|
+
equals: z.ZodString;
|
|
107
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
108
|
+
type: z.ZodLiteral<"absent">;
|
|
109
|
+
description: z.ZodString;
|
|
110
|
+
control: z.ZodObject<{
|
|
111
|
+
id: z.ZodNullable<z.ZodString>;
|
|
112
|
+
role: z.ZodString;
|
|
113
|
+
label: z.ZodString;
|
|
114
|
+
context: z.ZodNullable<z.ZodString>;
|
|
115
|
+
group: z.ZodNullable<z.ZodString>;
|
|
116
|
+
}, z.core.$strict>;
|
|
117
|
+
}, z.core.$strict>], "type">>;
|
|
118
|
+
/** A validated observable outcome check. */
|
|
119
|
+
export type CompletionCheck = z.infer<typeof completionCheckSchema>;
|
|
120
|
+
/** The observed page information needed to evaluate outcome checks. */
|
|
121
|
+
export interface VerificationState {
|
|
122
|
+
url: string;
|
|
123
|
+
text: string;
|
|
124
|
+
truncated: boolean;
|
|
125
|
+
controls: {
|
|
126
|
+
target: {
|
|
127
|
+
id: string;
|
|
128
|
+
version: number;
|
|
129
|
+
};
|
|
130
|
+
role: string;
|
|
131
|
+
label: string;
|
|
132
|
+
context: string;
|
|
133
|
+
groups?: {
|
|
134
|
+
name: string;
|
|
135
|
+
}[] | undefined;
|
|
136
|
+
value?: string | undefined;
|
|
137
|
+
checked?: boolean | undefined;
|
|
138
|
+
selectedValues?: string[] | undefined;
|
|
139
|
+
}[];
|
|
140
|
+
}
|
|
141
|
+
/** Deterministic checks of observable outcomes. This does not infer intent or prove backend persistence. */
|
|
142
|
+
export declare function evaluateCompletionChecks(checks: readonly CompletionCheck[], state: VerificationState, baseline?: VerificationState): {
|
|
143
|
+
passed: boolean;
|
|
144
|
+
checks: {
|
|
145
|
+
description: string;
|
|
146
|
+
passed: boolean;
|
|
147
|
+
}[];
|
|
148
|
+
};
|
|
149
|
+
/** A bounded, encoded screenshot with its capture metadata. */
|
|
150
|
+
export declare const screenshotSchema: z.ZodObject<{
|
|
151
|
+
data: z.ZodString;
|
|
152
|
+
mimeType: z.ZodEnum<{
|
|
153
|
+
"image/png": "image/png";
|
|
154
|
+
"image/jpeg": "image/jpeg";
|
|
155
|
+
"image/webp": "image/webp";
|
|
156
|
+
}>;
|
|
157
|
+
width: z.ZodNumber;
|
|
158
|
+
height: z.ZodNumber;
|
|
159
|
+
capturedAt: z.ZodNumber;
|
|
160
|
+
url: z.ZodString;
|
|
161
|
+
}, z.core.$strict>;
|
|
162
|
+
//# sourceMappingURL=verification.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verification.d.ts","sourceRoot":"","sources":["../src/verification.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,4EAA4E;AAC5E,eAAO,MAAM,oBAAoB;;;;;;kBAM/B,CAAC;AAQH,+EAA+E;AAC/E,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4BA+BhC,CAAC;AAEH,wDAAwD;AACxD,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BAAgD,CAAC;AAEpF,4CAA4C;AAC5C,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAGpE,uEAAuE;AACvE,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE;QACR,MAAM,EAAE;YAAE,EAAE,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,CAAA;SAAE,CAAC;QACxC,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,EAAE,GAAG,SAAS,CAAC;QACxC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAC3B,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;QAC9B,cAAc,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;KACvC,EAAE,CAAC;CACL;AAgED,4GAA4G;AAC5G,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,SAAS,eAAe,EAAE,EAClC,KAAK,EAAE,iBAAiB,EACxB,QAAQ,GAAE,iBAAyB,GAClC;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,OAAO,CAAA;KAAE,EAAE,CAAA;CAAE,CAmBzE;AAED,+DAA+D;AAC/D,eAAO,MAAM,gBAAgB;;;;;;;;;;;kBAsCzB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// Copyright 2026 RuaKit contributors. SPDX-License-Identifier: MIT
|
|
2
|
+
var c=Object.defineProperty;var l=(t,n)=>c(t,"name",{value:n,configurable:!0});import{z as e}from"zod";const p=e.strictObject({id:e.string().min(1).max(200).nullable(),role:e.string().max(100),label:e.string().max(1e3),context:e.string().max(1e3).nullable(),group:e.string().max(200).nullable()}),u=p,o=e.string().trim().min(1).max(500),g=e.discriminatedUnion("type",[e.strictObject({type:e.literal("value"),description:o,control:u,equals:e.string().max(2e4)}),e.strictObject({type:e.literal("checked"),description:o,control:u,equals:e.boolean()}),e.strictObject({type:e.literal("selected"),description:o,control:u,equals:e.array(e.string().max(4e3)).max(100)}),e.strictObject({type:e.literal("text"),description:o,text:e.string().trim().min(1).max(2e3),fresh:e.boolean()}),e.strictObject({type:e.literal("url"),description:o,equals:e.string().min(1).max(4e3)}),e.strictObject({type:e.literal("absent"),description:o,control:u})]),q=e.array(g).min(1).max(20);function d(t,n){return t.role===n.role&&t.label===n.label&&(n.context===null||t.context===n.context)&&(n.group===null||t.groups?.some(s=>s.name===n.group)===!0)}l(d,"matchesControl");function x(t,n,s){const r=n.text.includes(t.text),i=n.controls.some(m=>m.label.includes(t.text)),a=!t.fresh||!s.text.includes(t.text);return r&&!i&&a}l(x,"matchesText");function b(t,n){if(t.type==="value")return n.value===t.equals;if(t.type==="checked")return n.checked===t.equals;const s=n.selectedValues;return s===void 0?!1:s.length===t.equals.length&&new Set(t.equals).size===t.equals.length&&t.equals.every(r=>s.includes(r))}l(b,"matchesControlValue");function f(t,n){const s=n.controls.filter(i=>d(i,t.control));if(t.type==="absent")return!n.truncated&&s.length===0;const r=s.filter(i=>t.control.id===null||i.target.id===t.control.id);return r.length!==1?!1:b(t,r[0])}l(f,"matchesControlCheck");function j(t,n,s=n){const r=t.map(i=>{let a;return i.type==="text"?a=x(i,n,s):i.type==="url"?a=n.url===i.equals:a=f(i,n),{description:i.description,passed:a}});return{passed:r.length>0&&r.every(i=>i.passed),checks:r}}l(j,"evaluateCompletionChecks");const v=e.strictObject({data:e.string().min(1).max(7e6).regex(/^[A-Za-z0-9+/]+={0,2}$/).refine(t=>t.length%4===0),mimeType:e.enum(["image/png","image/jpeg","image/webp"]),width:e.number().int().positive().max(8192),height:e.number().int().positive().max(8192),capturedAt:e.number().int().nonnegative(),url:e.string().max(4e3)}).superRefine((t,n)=>{try{const s=globalThis.atob(t.data),r=t.mimeType==="image/png"?s.startsWith(`\x89PNG\r
|
|
3
|
+
|
|
4
|
+
`):t.mimeType==="image/jpeg"?s.startsWith("\xFF\xD8\xFF"):s.startsWith("RIFF")&&s.slice(8,12)==="WEBP";(s.length>5*1024*1024||!r)&&n.addIssue({code:"custom",message:"Screenshot bytes must match the image type and fit within 5 MiB."})}catch{n.addIssue({code:"custom",message:"Screenshot data must contain valid base64 image bytes."})}});export{g as completionCheckSchema,q as completionChecksSchema,p as controlLocatorSchema,j as evaluateCompletionChecks,v as screenshotSchema};
|
|
5
|
+
//# sourceMappingURL=verification.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/verification.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright 2026 RuaKit contributors. SPDX-License-Identifier: MIT\nimport { z } from 'zod';\n\n/** Identifies a control by its observed identity and accessible context. */\nexport const controlLocatorSchema = z.strictObject({\n id: z.string().min(1).max(200).nullable(),\n role: z.string().max(100),\n label: z.string().max(1000),\n context: z.string().max(1000).nullable(),\n group: z.string().max(200).nullable(),\n});\n\n/** Reuse the same locator constraints for all control checks. */\nconst locator = controlLocatorSchema;\n\n/** Human-readable explanation of the outcome being checked. */\nconst description = z.string().trim().min(1).max(500);\n\n/** A single observable condition that can establish progress toward a goal. */\nexport const completionCheckSchema = z.discriminatedUnion('type', [\n z.strictObject({\n type: z.literal('value'),\n description,\n control: locator,\n equals: z.string().max(20000),\n }),\n z.strictObject({\n type: z.literal('checked'),\n description,\n control: locator,\n equals: z.boolean(),\n }),\n z.strictObject({\n type: z.literal('selected'),\n description,\n control: locator,\n equals: z.array(z.string().max(4000)).max(100),\n }),\n z.strictObject({\n type: z.literal('text'),\n description,\n text: z.string().trim().min(1).max(2000),\n fresh: z.boolean(),\n }),\n z.strictObject({\n type: z.literal('url'),\n description,\n equals: z.string().min(1).max(4000),\n }),\n z.strictObject({ type: z.literal('absent'), description, control: locator }),\n]);\n\n/** A nonempty, bounded collection of outcome checks. */\nexport const completionChecksSchema = z.array(completionCheckSchema).min(1).max(20);\n\n/** A validated observable outcome check. */\nexport type CompletionCheck = z.infer<typeof completionCheckSchema>;\n\n\n/** The observed page information needed to evaluate outcome checks. */\nexport interface VerificationState {\n url: string;\n text: string;\n truncated: boolean;\n controls: {\n target: { id: string; version: number };\n role: string;\n label: string;\n context: string;\n groups?: { name: string }[] | undefined;\n value?: string | undefined;\n checked?: boolean | undefined;\n selectedValues?: string[] | undefined;\n }[];\n}\n\ntype ObservedControl = VerificationState['controls'][number];\ntype ControlLocator = z.infer<typeof controlLocatorSchema>;\ntype ControlCheck = Extract<CompletionCheck, { control: ControlLocator }>;\n\n/** Match accessible characteristics independently of the observation's target ID. */\nfunction matchesControl(control: ObservedControl, locator: ControlLocator): boolean {\n return (\n control.role === locator.role &&\n control.label === locator.label &&\n (locator.context === null || control.context === locator.context) &&\n (locator.group === null ||\n control.groups?.some((group) => group.name === locator.group) === true)\n );\n}\n\n/** Check visible text without treating a control's caption as an acknowledgement. */\nfunction matchesText(\n check: Extract<CompletionCheck, { type: 'text' }>,\n state: VerificationState,\n baseline: VerificationState,\n): boolean {\n const isVisible = state.text.includes(check.text);\n const isControlLabel = state.controls.some((control) => control.label.includes(check.text));\n const isFresh = !check.fresh || !baseline.text.includes(check.text);\n\n return isVisible && !isControlLabel && isFresh;\n}\n\n/** Compare the observed control's state with the expected value. */\nfunction matchesControlValue(\n check: Exclude<ControlCheck, { type: 'absent' }>,\n control: ObservedControl,\n): boolean {\n if (check.type === 'value') return control.value === check.equals;\n if (check.type === 'checked') return control.checked === check.equals;\n\n const selectedValues = control.selectedValues;\n if (selectedValues === undefined) return false;\n\n return (\n selectedValues.length === check.equals.length &&\n new Set(check.equals).size === check.equals.length &&\n check.equals.every((value) => selectedValues.includes(value))\n );\n}\n\n/** Resolve a control check against the current observation. */\nfunction matchesControlCheck(check: ControlCheck, state: VerificationState): boolean {\n const semanticMatches = state.controls.filter((control) => matchesControl(control, check.control));\n\n // A recycled target ID must not hide a control when checking for absence.\n if (check.type === 'absent') return !state.truncated && semanticMatches.length === 0;\n\n const matches = semanticMatches.filter(\n (control) => check.control.id === null || control.target.id === check.control.id,\n );\n\n // A value can only be verified when the locator identifies exactly one control.\n if (matches.length !== 1) return false;\n return matchesControlValue(check, matches[0]!);\n}\n\n/** Deterministic checks of observable outcomes. This does not infer intent or prove backend persistence. */\nexport function evaluateCompletionChecks(\n checks: readonly CompletionCheck[],\n state: VerificationState,\n baseline: VerificationState = state,\n): { passed: boolean; checks: { description: string; passed: boolean }[] } {\n const results = checks.map((check) => {\n let passed: boolean;\n\n if (check.type === 'text') {\n passed = matchesText(check, state, baseline);\n } else if (check.type === 'url') {\n passed = state.url === check.equals;\n } else {\n passed = matchesControlCheck(check, state);\n }\n\n return { description: check.description, passed };\n });\n\n return {\n passed: results.length > 0 && results.every((result) => result.passed),\n checks: results,\n };\n}\n\n/** A bounded, encoded screenshot with its capture metadata. */\nexport const screenshotSchema = z\n .strictObject({\n data: z\n .string()\n .min(1)\n .max(7_000_000)\n .regex(/^[A-Za-z0-9+/]+={0,2}$/)\n .refine((data) => data.length % 4 === 0),\n mimeType: z.enum(['image/png', 'image/jpeg', 'image/webp']),\n width: z.number().int().positive().max(8192),\n height: z.number().int().positive().max(8192),\n capturedAt: z.number().int().nonnegative(),\n url: z.string().max(4000),\n })\n .superRefine((image, context) => {\n try {\n // Decode the payload before checking its size and file signature.\n const bytes = globalThis.atob(image.data);\n\n const signatureMatches =\n image.mimeType === 'image/png'\n ? bytes.startsWith('\\x89PNG\\r\\n\\x1a\\n')\n : image.mimeType === 'image/jpeg'\n ? bytes.startsWith('\\xff\\xd8\\xff')\n : bytes.startsWith('RIFF') && bytes.slice(8, 12) === 'WEBP';\n\n if (bytes.length > 5 * 1024 * 1024 || !signatureMatches) {\n context.addIssue({\n code: 'custom',\n message: 'Screenshot bytes must match the image type and fit within 5 MiB.',\n });\n }\n } catch {\n context.addIssue({\n code: 'custom',\n message: 'Screenshot data must contain valid base64 image bytes.',\n });\n }\n });\n"],
|
|
5
|
+
"mappings": ";+EACA,OAAS,KAAAA,MAAS,MAGX,MAAMC,EAAuBD,EAAE,aAAa,CACjD,GAAIA,EAAE,OAAM,EAAG,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,GAAKA,EAAM,MAAM,EAAG,EAAE,IAAM,QAEvDA,EAAM,OAAS,EAAI,KAAO,MAAQ,CAACC,IACrCF,EAAQ,SAAS,CACf,KAAM,SACN,QAAS,mEACV,CAEL,MAAQ,CACNA,EAAQ,SAAS,CACf,KAAM,SACN,QAAS,yDACV,CACH,CACF,CAAC",
|
|
6
|
+
"names": ["z", "controlLocatorSchema", "locator", "description", "completionCheckSchema", "completionChecksSchema", "matchesControl", "control", "group", "__name", "matchesText", "check", "state", "baseline", "isVisible", "isControlLabel", "isFresh", "matchesControlValue", "selectedValues", "value", "matchesControlCheck", "semanticMatches", "matches", "evaluateCompletionChecks", "checks", "results", "passed", "result", "screenshotSchema", "data", "image", "context", "bytes", "signatureMatches"]
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ruakit/schema",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0-alpha.1",
|
|
4
|
+
"description": "Planning and execution protocols for RuaKit",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"src",
|
|
10
|
+
"README.md",
|
|
11
|
+
"LICENSE",
|
|
12
|
+
"NOTICE"
|
|
13
|
+
],
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"zod": "4.6.5"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsc -p tsconfig.json && node ../shared/scripts/minify.mjs",
|
|
26
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
27
|
+
}
|
|
6
28
|
}
|
package/src/decision.ts
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// Copyright 2026 RuaKit contributors. SPDX-License-Identifier: MIT
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { completionChecksSchema, screenshotSchema } from "./verification.js";
|
|
4
|
+
|
|
5
|
+
/** Identifies a control in a particular observation. */
|
|
6
|
+
const target = z.strictObject({
|
|
7
|
+
id: z.string().min(1).max(200),
|
|
8
|
+
version: z.number().int().positive(),
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
/** Describes an accessible group containing a control. */
|
|
12
|
+
const controlGroup = z.strictObject({
|
|
13
|
+
role: z.enum([
|
|
14
|
+
"form",
|
|
15
|
+
"group",
|
|
16
|
+
"radiogroup",
|
|
17
|
+
"region",
|
|
18
|
+
"dialog",
|
|
19
|
+
"alertdialog",
|
|
20
|
+
]),
|
|
21
|
+
name: z.string().min(1).max(200),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
/** Describes an observed control and its current state. */
|
|
25
|
+
const control = z.strictObject({
|
|
26
|
+
target,
|
|
27
|
+
tag: z.string().max(100),
|
|
28
|
+
type: z.string().max(100).optional(),
|
|
29
|
+
role: z.string().max(100),
|
|
30
|
+
label: z.string().max(1000),
|
|
31
|
+
description: z.string().max(1000).optional(),
|
|
32
|
+
placeholder: z.string().max(1000).optional(),
|
|
33
|
+
groups: z.array(controlGroup).min(1).max(4).optional(),
|
|
34
|
+
groupsTruncated: z.boolean().optional(),
|
|
35
|
+
context: z.string().max(1000),
|
|
36
|
+
enabled: z.boolean(),
|
|
37
|
+
readOnly: z.boolean(),
|
|
38
|
+
value: z.string().max(20000).optional(),
|
|
39
|
+
checked: z.boolean().optional(),
|
|
40
|
+
expanded: z.boolean().optional(),
|
|
41
|
+
selectedValues: z.array(z.string().max(4000)).max(100).optional(),
|
|
42
|
+
options: z
|
|
43
|
+
.array(
|
|
44
|
+
z.strictObject({
|
|
45
|
+
value: z.string().max(4000),
|
|
46
|
+
label: z.string().max(1000),
|
|
47
|
+
enabled: z.boolean(),
|
|
48
|
+
}),
|
|
49
|
+
)
|
|
50
|
+
.max(200)
|
|
51
|
+
.optional(),
|
|
52
|
+
valid: z.boolean().optional(),
|
|
53
|
+
contentEditable: z.boolean().optional(),
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
/** Actions the runtime can perform on an observed target. */
|
|
57
|
+
export const actionSchema = z.discriminatedUnion("type", [
|
|
58
|
+
z.strictObject({ type: z.literal("click"), target }),
|
|
59
|
+
z.strictObject({ type: z.literal("focus"), target }),
|
|
60
|
+
z.strictObject({
|
|
61
|
+
type: z.literal("insertText"),
|
|
62
|
+
target,
|
|
63
|
+
text: z.string().max(20000),
|
|
64
|
+
}),
|
|
65
|
+
z.strictObject({
|
|
66
|
+
type: z.literal("key"),
|
|
67
|
+
target,
|
|
68
|
+
key: z.string().min(1).max(100),
|
|
69
|
+
altKey: z.boolean(),
|
|
70
|
+
ctrlKey: z.boolean(),
|
|
71
|
+
metaKey: z.boolean(),
|
|
72
|
+
shiftKey: z.boolean(),
|
|
73
|
+
}),
|
|
74
|
+
z.strictObject({
|
|
75
|
+
type: z.literal("fill"),
|
|
76
|
+
target,
|
|
77
|
+
value: z.string().max(4000),
|
|
78
|
+
}),
|
|
79
|
+
z.strictObject({
|
|
80
|
+
type: z.literal("select"),
|
|
81
|
+
target,
|
|
82
|
+
values: z.array(z.string().max(4000)).min(1).max(100),
|
|
83
|
+
}),
|
|
84
|
+
z.strictObject({ type: z.literal("check"), target, checked: z.boolean() }),
|
|
85
|
+
]);
|
|
86
|
+
|
|
87
|
+
/** The model requests permission for this exact action. Only the host can approve it. */
|
|
88
|
+
export const approvalDecisionSchema = z.strictObject({
|
|
89
|
+
type: z.literal("approval"),
|
|
90
|
+
message: z.string().trim().min(1).max(2000),
|
|
91
|
+
step: actionSchema,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
/** Decisions a planner can return for the current observation. */
|
|
95
|
+
export const decisionSchema = z.discriminatedUnion("type", [
|
|
96
|
+
z.strictObject({
|
|
97
|
+
type: z.literal("act"),
|
|
98
|
+
message: z.string().min(1).max(2000),
|
|
99
|
+
step: actionSchema,
|
|
100
|
+
}),
|
|
101
|
+
z.strictObject({
|
|
102
|
+
type: z.literal("complete"),
|
|
103
|
+
message: z.string().min(1).max(2000),
|
|
104
|
+
checks: completionChecksSchema,
|
|
105
|
+
}),
|
|
106
|
+
z.strictObject({
|
|
107
|
+
type: z.literal("prepare"),
|
|
108
|
+
message: z.string().min(1).max(2000),
|
|
109
|
+
checks: completionChecksSchema,
|
|
110
|
+
}),
|
|
111
|
+
z.strictObject({
|
|
112
|
+
type: z.literal("screenshot"),
|
|
113
|
+
message: z.string().min(1).max(2000),
|
|
114
|
+
}),
|
|
115
|
+
z.strictObject({
|
|
116
|
+
type: z.literal("clarify"),
|
|
117
|
+
message: z.string().min(1).max(500),
|
|
118
|
+
}),
|
|
119
|
+
z.strictObject({
|
|
120
|
+
type: z.literal("unsupported"),
|
|
121
|
+
message: z.string().min(1).max(2000),
|
|
122
|
+
}),
|
|
123
|
+
approvalDecisionSchema,
|
|
124
|
+
]);
|
|
125
|
+
|
|
126
|
+
/** A previous question and the user's answer. */
|
|
127
|
+
const clarification = z.strictObject({
|
|
128
|
+
question: z.string().max(500),
|
|
129
|
+
answer: z.string().max(2000),
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
/** The page observation on which the planner should base its decision. */
|
|
133
|
+
const snapshot = z.strictObject({
|
|
134
|
+
url: z.string().max(4000),
|
|
135
|
+
title: z.string().max(2000),
|
|
136
|
+
text: z.string().max(20000),
|
|
137
|
+
controls: z.array(control).max(200),
|
|
138
|
+
focused: target.nullable(),
|
|
139
|
+
truncated: z.boolean(),
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
/** Observation and conversation context sent to the planner. */
|
|
143
|
+
export const decisionRequestSchema = z.strictObject({
|
|
144
|
+
platform: z.string().max(200).optional(),
|
|
145
|
+
prompt: z.string().trim().min(1).max(2000),
|
|
146
|
+
clarifications: z.array(clarification).max(3),
|
|
147
|
+
snapshot,
|
|
148
|
+
history: z.array(decisionSchema).max(20),
|
|
149
|
+
checks: completionChecksSchema.nullable().optional(),
|
|
150
|
+
canScreenshot: z.boolean().optional(),
|
|
151
|
+
screenshot: screenshotSchema.optional(),
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
/** A validated request for a planner decision. */
|
|
155
|
+
export type DecisionRequest = z.infer<typeof decisionRequestSchema>;
|
|
156
|
+
/** A validated planner decision. */
|
|
157
|
+
export type Decision = z.infer<typeof decisionSchema>;
|
|
158
|
+
/** A decision asking the host to approve one action. */
|
|
159
|
+
export type ApprovalDecision = z.infer<typeof approvalDecisionSchema>;
|