@pikku/core 0.12.94 → 0.12.95

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/CHANGELOG.md +136 -0
  2. package/dist/services/email-template.d.ts +43 -0
  3. package/dist/services/email-template.js +139 -0
  4. package/dist/services/http-personas.d.ts +6 -1
  5. package/dist/services/http-personas.js +4 -1
  6. package/dist/services/index.d.ts +1 -0
  7. package/dist/services/index.js +1 -0
  8. package/dist/wirings/agent/agent-prepare.d.ts +14 -0
  9. package/dist/wirings/agent/agent-prepare.js +24 -0
  10. package/dist/wirings/agent/index.d.ts +1 -1
  11. package/dist/wirings/agent/index.js +1 -1
  12. package/dist/wirings/scheduler/scheduler-runner.js +0 -1
  13. package/dist/wirings/virtual-user/index.d.ts +1 -0
  14. package/dist/wirings/virtual-user/index.js +1 -0
  15. package/dist/wirings/virtual-user/virtual-user-derive.js +9 -0
  16. package/dist/wirings/virtual-user/virtual-user-scaffold.d.ts +267 -0
  17. package/dist/wirings/virtual-user/virtual-user-scaffold.js +400 -0
  18. package/dist/wirings/workflow/index.d.ts +1 -0
  19. package/dist/wirings/workflow/index.js +1 -0
  20. package/dist/wirings/workflow/pikku-workflow-service.js +3 -9
  21. package/dist/wirings/workflow/workflow-queue-routing.d.ts +18 -0
  22. package/dist/wirings/workflow/workflow-queue-routing.js +35 -0
  23. package/dist/wirings/workflow/workflow-status-stream.d.ts +28 -0
  24. package/dist/wirings/workflow/workflow-status-stream.js +105 -0
  25. package/package.json +1 -1
  26. package/src/public-surface.json +17 -1
  27. package/src/services/email-template.test.ts +311 -0
  28. package/src/services/email-template.ts +254 -0
  29. package/src/services/http-personas.ts +10 -2
  30. package/src/services/index.ts +8 -0
  31. package/src/services/persona-sign-in.test.ts +22 -0
  32. package/src/wirings/agent/agent-helpers.test.ts +63 -0
  33. package/src/wirings/agent/agent-prepare.ts +25 -0
  34. package/src/wirings/agent/index.ts +1 -0
  35. package/src/wirings/scheduler/scheduler-runner.test.ts +178 -0
  36. package/src/wirings/scheduler/scheduler-runner.ts +0 -1
  37. package/src/wirings/virtual-user/index.ts +20 -0
  38. package/src/wirings/virtual-user/virtual-user-derive.test.ts +28 -0
  39. package/src/wirings/virtual-user/virtual-user-derive.ts +9 -0
  40. package/src/wirings/virtual-user/virtual-user-scaffold.test.ts +795 -0
  41. package/src/wirings/virtual-user/virtual-user-scaffold.ts +634 -0
  42. package/src/wirings/workflow/index.ts +4 -0
  43. package/src/wirings/workflow/pikku-workflow-service.test.ts +71 -2
  44. package/src/wirings/workflow/pikku-workflow-service.ts +5 -11
  45. package/src/wirings/workflow/workflow-child-run-session.test.ts +79 -0
  46. package/src/wirings/workflow/workflow-queue-routing.ts +44 -0
  47. package/src/wirings/workflow/workflow-status-stream.test.ts +354 -0
  48. package/src/wirings/workflow/workflow-status-stream.ts +144 -0
  49. package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,139 @@
1
+ ## 0.12.95
2
+
3
+ ### Patch Changes
4
+
5
+ - 1cc50ef: Queue a workflow step that names another workflow, instead of running it inside its parent.
6
+
7
+ `dispatchStep` decided by reading `workflowQueued` off `rpc` meta, but `addWorkflow` never registers there, so a child workflow could never be queued. It always took the inline path: the parent started the child with `inline: true` and then sat in an unbounded `awaitRunEnd` poll, holding its run lock and that lock's connection until the child ended — and the child, being inline, ran its own `sleep` as a real in-process wait rather than a suspension. A parent whose child polled for fifteen minutes held two lock connections for fifteen minutes, and enough of them exhausted the lock pool and stalled every other run behind it.
8
+
9
+ A step naming a workflow now queues whenever a queue service exists, reaching the `ChildWorkflowStartedException` path that already unwinds the parent and resumes it when the child completes. An inline parent still runs its children inline.
10
+
11
+ - a3deea4: Stop the scheduler declaring `auth: false` for every task.
12
+
13
+ A task whose middleware sets a session runs a session-taking function, and the
14
+ hardcoded `auth: false` made the runner log "requires a session but auth was
15
+ explicitly disabled — use pikkuSessionlessFunc instead" on every single run.
16
+ Nothing else changes: a task with no session still throws `MissingSessionError`
17
+ when its function needs one.
18
+
19
+ - 2a02288: Let a virtual user run against a deployed stage.
20
+
21
+ Until now the scaffolded run could only sign its personas in with
22
+ `SCENARIO_ACTOR_SECRET`, which only `pikku dev` serves — so a run against a
23
+ deployed target failed before its first turn. `runVirtualUser` now takes an
24
+ optional short-lived Fabric operator token, handed in by whoever starts the run
25
+ and passed through to `createPersonas` as `operator`.
26
+
27
+ Handed in rather than fetched on demand: a stage that could ask for a token
28
+ would be holding a credential able to mint admin sessions for itself for as long
29
+ as the box lives. It holds one receipt, for one run, and the receipt expires. It
30
+ is never written to the run record — only `FABRIC_OPERATOR_TOKEN` in the
31
+ environment is read, and only as the fallback for a run nobody handed a token to.
32
+
33
+ `HttpPersonasConfig.signInPath` now applies to the operator path too, so an app
34
+ that mounts auth under `/api` can say so once.
35
+
36
+ The framework's own virtual-user RPCs no longer enter a virtual user's
37
+ catalogue. A persona whose role carries `virtualUser:*` could otherwise start
38
+ further runs, read back every run's transcript — an adversarial run's steps are
39
+ working exploits against the same app — and put a persona on a schedule that
40
+ outlives it.
41
+
42
+ The scheduled tick now runs as the platform user, and starts its runs through
43
+ the same door a person uses.
44
+
45
+ The scaffolded `startVirtualUserRun` RPC is gone — not the `startVirtualUserRun`
46
+ helper `@pikku/core/virtual-user` now exports, which is the shared record-writer
47
+ `runVirtualUser` calls. The RPC existed only so the tick could record a run
48
+ without holding a session, which meant the persona checks, the
49
+ production-disposition rule and the record lived in two places that would
50
+ eventually disagree. The tick calls `runVirtualUser` over RPC instead, and the
51
+ scaffold emits `virtualUserPlatformSession` to give it an identity:
52
+
53
+ ```ts
54
+ wireScheduler({
55
+ name: 'virtualUsers',
56
+ schedule: '0 * * * *',
57
+ middleware: [virtualUserPlatformSession],
58
+ func: tickVirtualUserSchedules,
59
+ })
60
+ ```
61
+
62
+ `pikku-platform` is the platform's own principal and already exists for exactly
63
+ this — a reserved user row created with no credential account of any kind, so no
64
+ sign-in method can resolve it, and one the user directory already filters out, so
65
+ unlike a seeded service account it costs no phantom member in any list, seat
66
+ count or bill.
67
+
68
+ The middleware is attached to the task rather than declared as tag middleware
69
+ over `/rpc`, which cannot set a session at all: `runScheduledTask` builds its
70
+ wire with a `sessionService`, so the session set here is the one the function is
71
+ frozen with. A tick wired without it is refused for want of a session, and one
72
+ carrying the wrong scope is refused on `virtualUser:run` — both now covered by
73
+ tests.
74
+
75
+ A Fabric operator can now actually start the run it signs in to start.
76
+
77
+ `fabric()` granted its operator row `admin` and nothing else. `admin` is this
78
+ package's own root — pikku's parent-grant rule walks down from a root that is
79
+ held, and the virtual-user scaffold declares `virtualUser` as a root of its own
80
+ precisely so a role can carry `virtualUser:run` without also implying
81
+ administration. So the operator was refused by `runVirtualUser`, the one
82
+ function the operator sign-in exists to reach.
83
+
84
+ The operator is now granted the roots in `OPERATOR_SCOPE_ROOTS`
85
+ (`admin`, `virtualUser`) rather than a bare `admin`. Listed rather than
86
+ collapsed to `*`, which would make every operator a superuser on every app for
87
+ the sake of one function: an operator still holds nothing in the application's
88
+ own domain, and a root the app never declared is skipped rather than stored.
89
+
90
+ The grant is also re-checked on every operator sign-in instead of only when the
91
+ row is created. It is deliberately logged rather than thrown, so a single
92
+ failure used to leave that operator permanently unprivileged with nothing to
93
+ retry it, and a root added to the set later would never have reached the
94
+ operators that already existed.
95
+
96
+ The scaffolds no longer keep their logic inside the CLI's template strings.
97
+
98
+ Code written as text inside a template literal is never compiled, never linted,
99
+ and testable only by matching the source the CLI emits — so a dead branch or a
100
+ duplicated loop survives there indefinitely. Five scaffolds were carrying real
101
+ logic that way, and it now lives in `@pikku/core` alongside the types it uses,
102
+ leaving each serializer to emit only what is genuinely per-application.
103
+
104
+ - **virtual-user** — 677 lines: the run driver, the persona and disposition
105
+ rules, the schedule writer and the serializers, now
106
+ `@pikku/core/virtual-user`. The guarantee that an operator token never
107
+ reaches the run record used to be a regex over emitted text; it is now
108
+ structural, because `startVirtualUserRun` has no parameter to pass one to.
109
+ - **workflow** — the two status streams were an ~80-line poll loop each,
110
+ identical apart from three fields, now one `streamWorkflowRunStatus` told
111
+ whether to be detailed. Fixes three latent bugs both copies shared: a
112
+ `setInterval(async …)` whose poll threw produced an unhandled rejection; a
113
+ poll that threw left the channel open rather than ending the stream; and the
114
+ interval fired whether or not the previous poll had returned, so a slow store
115
+ put two polls in flight and sent the init frame twice.
116
+ - **emails** — ~190 lines of HTML escaping, trusted-root allowlist and
117
+ single-pass substitution, now `renderEmail` in `@pikku/core/services`. This
118
+ was the security-sensitive one, and compiling it surfaced a bug the template
119
+ string had been hiding: `{{ content }}` was written unescaped in every render
120
+ rather than only in the layout it is the slot for, so a caller passing
121
+ `data.content` to a template that named it got raw HTML out. Nested lookups
122
+ also used `in`, which walks the prototype chain; nothing inherited actually
123
+ reached the output — every step past a prototype hit lands on a function,
124
+ which is neither traversed nor written — so that one is a closed door rather
125
+ than a fixed leak.
126
+ - **agent** — both callers built the same options object; now
127
+ `agentCallOptions`, typed against `AgentInput` rather than a second copy of
128
+ its shape.
129
+ - **console** — two branches that could only survive uncompiled: a catch block
130
+ identical to its try, and an if/else whose arms were the same call.
131
+
132
+ Behaviour is unchanged throughout, and the emitted modules are the same modules
133
+ — the emails scaffold's ten escaping tests pass untouched through core. The five
134
+ serializers shrink from 1,936 lines to 1,281, and what they used to emit is now
135
+ covered by 75 tests that run the code rather than by regexes over the text.
136
+
1
137
  ## 0.12.94
2
138
 
3
139
  ### Patch Changes
@@ -0,0 +1,43 @@
1
+ /**
2
+ * The renderer behind a generated `pikku-emails.gen.ts`.
3
+ *
4
+ * The generated module supplies the assets — theme, locale strings, partials and
5
+ * the templates themselves — and a typed wrapper over `renderEmail`. Everything
6
+ * here is the same for every application, which is why it lives in core rather
7
+ * than in the string the CLI writes: this is HTML escaping, and code inside a
8
+ * template literal is never compiled, never linted, and testable only by
9
+ * matching the text it emits.
10
+ */
11
+ export interface EmailTemplateHashes {
12
+ contentHash: string;
13
+ htmlHash: string;
14
+ subjectHash: string;
15
+ textHash: string;
16
+ }
17
+ export interface EmailTemplateAssets {
18
+ html: string;
19
+ subject: string;
20
+ text: string;
21
+ variables: ReadonlyArray<string>;
22
+ hashes: Record<string, EmailTemplateHashes>;
23
+ }
24
+ export interface EmailAssets {
25
+ theme: Record<string, unknown>;
26
+ locales: Record<string, Record<string, unknown>>;
27
+ partials: Record<string, string>;
28
+ templates: Record<string, EmailTemplateAssets>;
29
+ }
30
+ export interface RenderEmailRequest {
31
+ name: string;
32
+ locale?: string;
33
+ data?: Record<string, unknown>;
34
+ }
35
+ export interface RenderedEmailResult {
36
+ locale: string;
37
+ subject: string;
38
+ html: string;
39
+ text?: string;
40
+ variables: ReadonlyArray<string>;
41
+ hash: string;
42
+ }
43
+ export declare const renderEmail: ({ theme, locales, partials, templates }: EmailAssets, { name, locale: requestedLocale, data }: RenderEmailRequest) => RenderedEmailResult;
@@ -0,0 +1,139 @@
1
+ /**
2
+ * The renderer behind a generated `pikku-emails.gen.ts`.
3
+ *
4
+ * The generated module supplies the assets — theme, locale strings, partials and
5
+ * the templates themselves — and a typed wrapper over `renderEmail`. Everything
6
+ * here is the same for every application, which is why it lives in core rather
7
+ * than in the string the CLI writes: this is HTML escaping, and code inside a
8
+ * template literal is never compiled, never linted, and testable only by
9
+ * matching the text it emits.
10
+ */
11
+ const HTML_ESCAPES = {
12
+ '&': '&amp;',
13
+ '<': '&lt;',
14
+ '>': '&gt;',
15
+ '"': '&quot;',
16
+ "'": '&#39;',
17
+ };
18
+ const escapeHtml = (value) => value.replace(/[&<>"']/g, (char) => HTML_ESCAPES[char] ?? char);
19
+ // Matches the raw {{{ value }}} form before the escaped {{ value }} form, so the
20
+ // opt-in escape hatch is never mistaken for a normal substitution.
21
+ const TEMPLATE_TOKEN = /\{\{\{\s*([^{}]+?)\s*\}\}\}|\{\{\s*([^}]+?)\s*\}\}/g;
22
+ const PARTIAL_TOKEN = /\{\{\s*>\s*([a-zA-Z0-9-_/.]+)\s*\}\}/g;
23
+ const MAX_TEMPLATE_DEPTH = 5;
24
+ // theme.json and the locale files ship with the templates, so they are treated as
25
+ // template-author input: expanded before caller data and allowed to contain their
26
+ // own placeholders. Everything else is caller-supplied.
27
+ const TRUSTED_ROOTS = ['theme', 't'];
28
+ const isTrustedKey = (key) => TRUSTED_ROOTS.includes(String(key.split('.')[0]));
29
+ const getNestedValue = (source, path) => {
30
+ const segments = path.split('.');
31
+ let current = source;
32
+ for (const segment of segments) {
33
+ // `hasOwn`, not `in`: `in` walks the prototype chain, so a path is answered
34
+ // by what an object inherits rather than only by what it carries. Nothing
35
+ // inherited reaches the output today — every step past a prototype hit lands
36
+ // on a function, which is neither traversed nor written — so this closes the
37
+ // lookup rather than fixing a value that escapes through it.
38
+ if (!current ||
39
+ typeof current !== 'object' ||
40
+ !Object.hasOwn(current, segment)) {
41
+ return '';
42
+ }
43
+ current = current[segment];
44
+ }
45
+ return typeof current === 'string' || typeof current === 'number'
46
+ ? String(current)
47
+ : '';
48
+ };
49
+ const readToken = (rawTriple, rawDouble) => {
50
+ const raw = typeof rawTriple === 'string';
51
+ return { raw, key: String(raw ? rawTriple : rawDouble).trim() };
52
+ };
53
+ const expandPartials = (source, partials, depth = 0) => {
54
+ if (depth >= MAX_TEMPLATE_DEPTH)
55
+ return source;
56
+ let found = false;
57
+ const expanded = source.replace(PARTIAL_TOKEN, (_match, partialName) => {
58
+ found = true;
59
+ const partial = partials[String(partialName).trim()];
60
+ return typeof partial === 'string' ? partial : '';
61
+ });
62
+ return found ? expandPartials(expanded, partials, depth + 1) : expanded;
63
+ };
64
+ const expandTrusted = (source, context, escape) => {
65
+ let rendered = source;
66
+ for (let i = 0; i < MAX_TEMPLATE_DEPTH; i += 1) {
67
+ let found = false;
68
+ const next = rendered.replace(TEMPLATE_TOKEN, (match, rawTriple, rawDouble) => {
69
+ const { raw, key } = readToken(rawTriple, rawDouble);
70
+ if (!isTrustedKey(key))
71
+ return match;
72
+ found = true;
73
+ const value = getNestedValue(context, key);
74
+ return raw || !escape ? value : escapeHtml(value);
75
+ });
76
+ if (!found || next === rendered)
77
+ break;
78
+ rendered = next;
79
+ }
80
+ return rendered;
81
+ };
82
+ // A single substitution pass — the replacement text is never rescanned, so a
83
+ // caller-supplied value can never be reinterpreted as a template.
84
+ const substitute = (source, context, escape, slot) => source.replace(TEMPLATE_TOKEN, (_match, rawTriple, rawDouble) => {
85
+ const { raw, key } = readToken(rawTriple, rawDouble);
86
+ // `content` is the layout's slot for the body that was already rendered and
87
+ // escaped, so it is the one value written in raw. Only the layout gets it:
88
+ // honouring it everywhere would let a caller pass `data.content` into a
89
+ // template that happens to name it and have it emitted unescaped.
90
+ if (slot !== undefined && key === slot) {
91
+ return typeof context[slot] === 'string' ? context[slot] : '';
92
+ }
93
+ if (key.startsWith('>')) {
94
+ return '';
95
+ }
96
+ const value = getNestedValue(context, key);
97
+ return raw || !escape ? value : escapeHtml(value);
98
+ });
99
+ const renderTemplate = (source, partials, context, escape, slot) => {
100
+ const composed = expandTrusted(expandPartials(source, partials), context, escape);
101
+ return substitute(composed, context, escape, slot);
102
+ };
103
+ export const renderEmail = ({ theme, locales, partials, templates }, { name, locale: requestedLocale, data }) => {
104
+ const locale = requestedLocale ?? 'en';
105
+ const template = templates[name];
106
+ if (!template) {
107
+ throw new Error(`Unknown email template: ${name}`);
108
+ }
109
+ const strings = locales[locale];
110
+ if (!strings) {
111
+ throw new Error(`Unknown email locale: ${locale}`);
112
+ }
113
+ const values = data ?? {};
114
+ const appName = (typeof values.appName === 'string' && values.appName) ||
115
+ getNestedValue(theme, 'appName');
116
+ const baseContext = {
117
+ ...values,
118
+ locale,
119
+ theme,
120
+ t: strings,
121
+ appName,
122
+ };
123
+ const subject = renderTemplate(template.subject, partials, baseContext, false).trim();
124
+ const htmlBody = renderTemplate(template.html, partials, { ...baseContext, subject }, true);
125
+ const html = partials.layout
126
+ ? renderTemplate(partials.layout, partials, { ...baseContext, subject, content: htmlBody }, true, 'content')
127
+ : htmlBody;
128
+ const text = template.text
129
+ ? renderTemplate(template.text, partials, { ...baseContext, subject }, false).trim()
130
+ : undefined;
131
+ return {
132
+ locale,
133
+ subject,
134
+ html,
135
+ ...(text ? { text } : {}),
136
+ variables: template.variables,
137
+ hash: template.hashes[locale]?.contentHash ?? '',
138
+ };
139
+ };
@@ -27,7 +27,12 @@ export interface HttpPersonasConfig {
27
27
  operator?: OperatorSignInOptions;
28
28
  /** Persona id → the declaration with its address filled in. */
29
29
  personas: Record<string, ResolvedPersona>;
30
- /** Sign-in path under apiUrl. Default: the actor plugin's `/auth/sign-in/actor`. */
30
+ /**
31
+ * Sign-in path under apiUrl, for whichever of the two paths is in use — an
32
+ * app that mounts auth under `/api` moves both. Default: the actor plugin's
33
+ * `/auth/sign-in/actor`, or `/auth/sign-in/fabric` for an operator.
34
+ * {@link OperatorSignInOptions.signInPath} overrides it.
35
+ */
31
36
  signInPath?: string;
32
37
  /** Where the session (and its roles) is read back. Default `/auth/get-session`. */
33
38
  sessionPath?: string;
@@ -32,7 +32,10 @@ export class HttpPersona {
32
32
  this.config = config;
33
33
  this.jar = createCookieJar(config.apiUrl);
34
34
  if (config.operator) {
35
- this.signIn = new OperatorSignIn(config.apiUrl, config.operator);
35
+ this.signIn = new OperatorSignIn(config.apiUrl, {
36
+ ...config.operator,
37
+ signInPath: config.operator.signInPath ?? config.signInPath,
38
+ });
36
39
  }
37
40
  else if (config.secret) {
38
41
  this.signIn = new ActorSignIn(config.apiUrl, config.secret, config.signInPath ?? '/auth/sign-in/actor');
@@ -21,6 +21,7 @@ export type { ContentService, SignContentKeyArgs, SignURLArgs, GetUploadURLArgs,
21
21
  export type { ScenarioPersona, ResolvedPersona, ScenarioPersonas, } from './personas-service.js';
22
22
  export type { JWTService } from './jwt-service.js';
23
23
  export type { EmailService, SendEmailInput, SendEmailResult, SendHTMLEmailInput, SendTemplateEmailInput, SendTextEmailInput, } from './email-service.js';
24
+ export { renderEmail, type EmailAssets, type EmailTemplateAssets, type EmailTemplateHashes, type RenderEmailRequest, type RenderedEmailResult, } from './email-template.js';
24
25
  export { DEFAULT_WEBHOOK_RETRIES, PIKKU_OUTGOING_WEBHOOK_QUEUE_NAME, WebhookService, type SendWebhookInput, type SendWebhookResult, type WebhookAttemptResult, type WebhookDeliveryRecord, type WebhookDeliveryWithAttempts, type WebhookJobData, type WebhookServiceConfig, } from './webhook-service.js';
25
26
  export type { Logger } from './logger.js';
26
27
  export type { SecretService, SecretValues } from './secret-service.js';
@@ -17,6 +17,7 @@ export { InMemoryTriggerService } from './in-memory-trigger-service.js';
17
17
  export { InMemoryAgentRunStateService } from './in-memory-agent-run-state-service.js';
18
18
  export { LocalGatewayService } from './local-gateway-service.js';
19
19
  export { FileScenarioRunStore, scenarioArtifactContentType, scenarioRunSummary, } from './file-scenario-run-store.js';
20
+ export { renderEmail, } from './email-template.js';
20
21
  export { DEFAULT_WEBHOOK_RETRIES, PIKKU_OUTGOING_WEBHOOK_QUEUE_NAME, WebhookService, } from './webhook-service.js';
21
22
  export { SchedulerService } from './scheduler-service.js';
22
23
  export { TypedCredentialService } from './typed-credential-service.js';
@@ -28,6 +28,20 @@ export declare function canAccessThread(storedResourceId: string, session: {
28
28
  userId?: string;
29
29
  orgId?: string;
30
30
  } | undefined): boolean;
31
+ /**
32
+ * An agent call with the fields nobody supplied left out.
33
+ *
34
+ * Omitted rather than passed as `undefined`, because an explicit `undefined`
35
+ * overrides the agent's own declared default with nothing — a request that
36
+ * names no model would silently unset the one the agent declares.
37
+ *
38
+ * Shared by the scaffolded `run` and `stream` routes, which receive the same
39
+ * input and differ only in what they do with the reply. `agentName` is not part
40
+ * of it: both callers pass that separately, because `rpc.agent.run` and
41
+ * `rpc.agent.stream` take it as their first argument and type the rest
42
+ * against it.
43
+ */
44
+ export declare const agentCallOptions: (input: AgentInput) => AgentInput;
31
45
  export type StreamAgentOptions = {
32
46
  requiresToolApproval?: 'all' | 'explicit' | false;
33
47
  onRunCreated?: (runId: string) => void;
@@ -65,6 +65,30 @@ export function canAccessThread(storedResourceId, session) {
65
65
  return false;
66
66
  return principals.some((principal) => isOwnedByPrincipal(storedResourceId, principal));
67
67
  }
68
+ /**
69
+ * An agent call with the fields nobody supplied left out.
70
+ *
71
+ * Omitted rather than passed as `undefined`, because an explicit `undefined`
72
+ * overrides the agent's own declared default with nothing — a request that
73
+ * names no model would silently unset the one the agent declares.
74
+ *
75
+ * Shared by the scaffolded `run` and `stream` routes, which receive the same
76
+ * input and differ only in what they do with the reply. `agentName` is not part
77
+ * of it: both callers pass that separately, because `rpc.agent.run` and
78
+ * `rpc.agent.stream` take it as their first argument and type the rest
79
+ * against it.
80
+ */
81
+ export const agentCallOptions = (input) => ({
82
+ message: input.message,
83
+ threadId: input.threadId,
84
+ resourceId: input.resourceId,
85
+ ...(input.attachments ? { attachments: input.attachments } : {}),
86
+ ...(input.model ? { model: input.model } : {}),
87
+ ...(input.temperature !== undefined
88
+ ? { temperature: input.temperature }
89
+ : {}),
90
+ ...(input.context ? { context: input.context } : {}),
91
+ });
68
92
  export const APPROVAL_REQUIRED = Symbol('pikku.ai.approvalRequired');
69
93
  /**
70
94
  * In-process brand proving a credential request was produced by pikku itself and
@@ -7,6 +7,6 @@ export { voiceInput, NoSpeechDetectedError, SPOKEN_TURN, SPOKEN_TRANSCRIPT, } fr
7
7
  export { voiceOutput, unspeakableScripts, voiceForText, type SpeakableScripts, type VoiceOutputState, } from './voice-output.js';
8
8
  export { AgentInterruptedError, signalRunInterrupt } from './agent-interrupt.js';
9
9
  export type { AgentInterruption, AgentInterruptResult, InterruptibleRunHandle, } from './agent-interrupt.js';
10
- export { type RunAgentParams, type StreamAgentOptions, ToolApprovalRequired, ToolCredentialRequired, canAccessThread, isOwnedByPrincipal, threadOwnerConstraint, } from './agent-prepare.js';
10
+ export { type RunAgentParams, type StreamAgentOptions, ToolApprovalRequired, ToolCredentialRequired, agentCallOptions, canAccessThread, isOwnedByPrincipal, threadOwnerConstraint, } from './agent-prepare.js';
11
11
  export { addAgent } from './agent-registry.js';
12
12
  export type { AgentInput, AgentsMeta, AgentMemoryConfig, AgentStep, AgentContentPart, AgentRunRow, AgentRunService, AgentRunState, AgentMessage, AgentStreamChannel, AgentStreamEvent, AgentThread, CoreAgent, PendingApproval, PikkuAgentMiddlewareHooks, } from './agent.types.js';
@@ -6,5 +6,5 @@ export { streamAgent, resumeAgent, interruptAgent } from './agent-stream.js';
6
6
  export { voiceInput, NoSpeechDetectedError, SPOKEN_TURN, SPOKEN_TRANSCRIPT, } from './voice-input.js';
7
7
  export { voiceOutput, unspeakableScripts, voiceForText, } from './voice-output.js';
8
8
  export { AgentInterruptedError, signalRunInterrupt } from './agent-interrupt.js';
9
- export { ToolApprovalRequired, ToolCredentialRequired, canAccessThread, isOwnedByPrincipal, threadOwnerConstraint, } from './agent-prepare.js';
9
+ export { ToolApprovalRequired, ToolCredentialRequired, agentCallOptions, canAccessThread, isOwnedByPrincipal, threadOwnerConstraint, } from './agent-prepare.js';
10
10
  export { addAgent } from './agent-registry.js';
@@ -68,7 +68,6 @@ export async function runScheduledTask({ name, session, traceId, }) {
68
68
  await runPikkuFunc('scheduler', meta.name, meta.pikkuFuncId, {
69
69
  singletonServices,
70
70
  createWireServices,
71
- auth: false,
72
71
  data: () => undefined,
73
72
  inheritedMiddleware: meta.middleware,
74
73
  wireMiddleware: task.middleware,
@@ -29,3 +29,4 @@ export { type AgentReachability, type ReachableAgent, } from './virtual-user-age
29
29
  export { IntentStack, intentsForPersona } from './virtual-user-intents.js';
30
30
  export { deriveCatalogue, deriveIntents, type SchemaMap, } from './virtual-user-derive.js';
31
31
  export { personaVirtualUserTarget, type PersonaTargetOptions, } from './virtual-user-target.js';
32
+ export { executeVirtualUserRun, logVirtualUserTick, requireVirtualUserRunStore, requireVirtualUserScheduleStore, runnablePersona, serializeVirtualUserRun, serializeVirtualUserSchedule, serializeVirtualUserSteps, signInPathFor, startVirtualUserRun, VIRTUAL_USER_VARIABLES, virtualUserScheduleRunInput, writeVirtualUserSchedule, type ExecuteVirtualUserRunParams, type ScaffoldPersonas, type StartedVirtualUserRun, type StartVirtualUserRunParams, type WriteVirtualUserScheduleParams, } from './virtual-user-scaffold.js';
@@ -7,3 +7,4 @@ export { catalogueClassification, catalogueLookup, isReadOnly, reachableCatalogu
7
7
  export { IntentStack, intentsForPersona } from './virtual-user-intents.js';
8
8
  export { deriveCatalogue, deriveIntents, } from './virtual-user-derive.js';
9
9
  export { personaVirtualUserTarget, } from './virtual-user-target.js';
10
+ export { executeVirtualUserRun, logVirtualUserTick, requireVirtualUserRunStore, requireVirtualUserScheduleStore, runnablePersona, serializeVirtualUserRun, serializeVirtualUserSchedule, serializeVirtualUserSteps, signInPathFor, startVirtualUserRun, VIRTUAL_USER_VARIABLES, virtualUserScheduleRunInput, writeVirtualUserSchedule, } from './virtual-user-scaffold.js';
@@ -24,6 +24,15 @@ export const deriveCatalogue = (functions, schemas = {}) => {
24
24
  // knowledge: decisions/internals/only-exposed-functions-enter-a-virtual-user-catalogue.md
25
25
  if (meta.expose !== true)
26
26
  continue;
27
+ // A virtual user is not offered the machinery that runs virtual users. A
28
+ // persona whose role carries `virtualUser:*` would otherwise be able to
29
+ // start further runs, read every run's findings — an adversarial run's
30
+ // transcript is working exploits against this same app — and put a persona
31
+ // on a schedule that outlives it. Same reasoning as the scenario-step rule
32
+ // above: the tool is about the run, not about the product being explored.
33
+ if (meta.scopes?.some((scope) => scope.split(':')[0] === 'virtualUser')) {
34
+ continue;
35
+ }
27
36
  const inputSchema = meta.inputSchemaName
28
37
  ? schemas[meta.inputSchemaName]
29
38
  : undefined;