@happyvertical/smrt-template-sveltekit 0.61.5 → 0.62.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/AGENTS.md +1 -1
- package/agents/cookbook-host.md +93 -85
- package/agents/cookbook-workflow-runs.md +102 -0
- package/cookbook-template/src/routes/settings/inference/+page.server.ts +1 -1
- package/dist/host/client.js +1 -1
- package/dist/host/server.d.ts +16 -46
- package/dist/host/server.js +301 -282
- package/dist/host/settings.d.ts +4 -22
- package/dist/host/settings.js +12 -9
- package/dist/host/workflow-runs.d.ts +201 -0
- package/dist/host/workflow-runs.js +612 -0
- package/dist/smrt-knowledge.okf.md +7 -2
- package/host/InferenceSettingsPage.svelte +9 -8
- package/mcp-apps-template/package.dependencies.json +2 -2
- package/package.json +46 -43
- package/template/package.json +17 -17
- package/template.config.js +17 -17
- package/agents/cookbook-design-runs.md +0 -164
- package/dist/host/design-runs.d.ts +0 -72
- package/dist/host/design-runs.js +0 -763
package/dist/host/settings.d.ts
CHANGED
|
@@ -9,30 +9,12 @@ export interface SettingsSession {
|
|
|
9
9
|
}
|
|
10
10
|
export declare const requireSettingsSession: (input: unknown) => SettingsSession;
|
|
11
11
|
export declare function readPayload<T>(request: Request): Promise<T>;
|
|
12
|
-
export declare function createInferenceSettingsPage(controller: InferenceSettingsController,
|
|
12
|
+
export declare function createInferenceSettingsPage(controller: InferenceSettingsController, assistantSettings?: ReturnType<typeof createCookbookHost>['assistantSettings']): {
|
|
13
13
|
load: ({ locals, url, depends }: import("@sveltejs/kit").ServerLoadEvent<Record<string, string>, Record<string, any>, string | null>) => Promise<{
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
unavailable: boolean;
|
|
17
|
-
name: import("@happyvertical/smrt-inference").WorkProfileName;
|
|
18
|
-
engine: import("@happyvertical/smrt-inference").InferenceEngineId;
|
|
19
|
-
model?: string;
|
|
20
|
-
effort: import("@happyvertical/smrt-inference").WorkReasoningEffort;
|
|
21
|
-
tier: "best" | "good" | "cheap";
|
|
22
|
-
budgets: import("@happyvertical/smrt-inference").WorkProfileBudgets;
|
|
23
|
-
autoEscalate: boolean;
|
|
24
|
-
previewBeforeApply: boolean;
|
|
25
|
-
modelSelection?: {
|
|
26
|
-
kind: "strongest" | "custom" | "configured" | "fallback";
|
|
27
|
-
requestedModel?: string;
|
|
28
|
-
resolvedModel?: string;
|
|
29
|
-
};
|
|
30
|
-
}[];
|
|
31
|
-
editable: boolean;
|
|
32
|
-
chatgptSignedIn: boolean;
|
|
33
|
-
settings: import("@happyvertical/smrt-preferences").WorkProfilePreferences;
|
|
14
|
+
assistant?: {
|
|
15
|
+
settings: import("@happyvertical/smrt-inference").AssistantSettings;
|
|
34
16
|
revision: string | null;
|
|
35
|
-
|
|
17
|
+
editable: boolean;
|
|
36
18
|
} | undefined;
|
|
37
19
|
tenantId: string;
|
|
38
20
|
canEdit: boolean;
|
package/dist/host/settings.js
CHANGED
|
@@ -22,7 +22,7 @@ export async function readPayload(request) {
|
|
|
22
22
|
error(400, 'Invalid payload');
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
export function createInferenceSettingsPage(controller,
|
|
25
|
+
export function createInferenceSettingsPage(controller, assistantSettings) {
|
|
26
26
|
const inferenceSettingsController = () => controller;
|
|
27
27
|
/** An outcome from the controller as the page's action result. */
|
|
28
28
|
function result(outcome) {
|
|
@@ -36,30 +36,33 @@ export function createInferenceSettingsPage(controller, workProfiles) {
|
|
|
36
36
|
// No key is ever sent to the browser, only whether one is stored.
|
|
37
37
|
return {
|
|
38
38
|
...(await inferenceSettingsController().load(session, url.searchParams.get('by'))),
|
|
39
|
-
...(
|
|
39
|
+
...(assistantSettings
|
|
40
40
|
? {
|
|
41
|
-
|
|
41
|
+
assistant: await assistantSettings.read({
|
|
42
|
+
locals,
|
|
43
|
+
url,
|
|
44
|
+
}),
|
|
42
45
|
}
|
|
43
46
|
: {}),
|
|
44
47
|
};
|
|
45
48
|
});
|
|
46
49
|
const actions = {
|
|
47
|
-
|
|
48
|
-
if (!
|
|
50
|
+
saveAssistant: async (event) => {
|
|
51
|
+
if (!assistantSettings)
|
|
49
52
|
error(404, 'Unavailable');
|
|
50
53
|
const payload = await readPayload(event.request);
|
|
51
|
-
const outcome = await
|
|
54
|
+
const outcome = await assistantSettings.write(event, payload);
|
|
52
55
|
return outcome.ok
|
|
53
56
|
? outcome
|
|
54
57
|
: fail(outcome.reason === 'conflict' ? 409 : 400, {
|
|
55
58
|
error: 'The change was refused.',
|
|
56
59
|
});
|
|
57
60
|
},
|
|
58
|
-
|
|
59
|
-
if (!
|
|
61
|
+
resetAssistant: async (event) => {
|
|
62
|
+
if (!assistantSettings)
|
|
60
63
|
error(404, 'Unavailable');
|
|
61
64
|
const payload = await readPayload(event.request);
|
|
62
|
-
const outcome = await
|
|
65
|
+
const outcome = await assistantSettings.reset(event, payload.revision);
|
|
63
66
|
return outcome.ok
|
|
64
67
|
? outcome
|
|
65
68
|
: fail(outcome.reason === 'conflict' ? 409 : 400, {
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { type AiRunBudget, type AiRunContext, type InferenceTier, type ReasoningEffort } from '@happyvertical/smrt-core';
|
|
2
|
+
import type { CookbookToolDefinition, CookbookToolName, CookbookToolResult } from '@happyvertical/smrt-core/cookbook/tools';
|
|
3
|
+
import type { InferenceEngineId } from '@happyvertical/smrt-inference/server';
|
|
4
|
+
import { type ResolvedPrompt } from '@happyvertical/smrt-prompts';
|
|
5
|
+
import { type WorkflowDefinition, type WorkflowRunState } from '@happyvertical/smrt-workflows';
|
|
6
|
+
import type { DatabaseInterface } from '@happyvertical/sql';
|
|
7
|
+
/**
|
|
8
|
+
* How a workflow run's steps run (#5005): the engine, the tier the change
|
|
9
|
+
* asks for and the model the engine's tier binding chose for it, the effort,
|
|
10
|
+
* and the owner's preview setting captured when the run started.
|
|
11
|
+
*/
|
|
12
|
+
export interface WorkflowRunExecution {
|
|
13
|
+
engine: InferenceEngineId;
|
|
14
|
+
tier: InferenceTier;
|
|
15
|
+
model?: string;
|
|
16
|
+
effort?: ReasoningEffort;
|
|
17
|
+
previewBeforeApply: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The cookbook change workflow's budget (#5005): the run's steps, tokens,
|
|
21
|
+
* time and repairs, and each step turn's tool-loop steps, per-call output,
|
|
22
|
+
* tokens, reply time and kept tool result size.
|
|
23
|
+
*/
|
|
24
|
+
export interface WorkflowRunBudget {
|
|
25
|
+
/** Steps of the workflow (its definition's step count). */
|
|
26
|
+
steps: number;
|
|
27
|
+
maxRunTokens: number;
|
|
28
|
+
runTimeoutMs: number;
|
|
29
|
+
repairRetries: number;
|
|
30
|
+
/** Tool-loop steps of one step's assistant turn. */
|
|
31
|
+
maxTurnSteps: number;
|
|
32
|
+
maxTokens: number;
|
|
33
|
+
maxTurnTokens: number;
|
|
34
|
+
requestTimeoutMs: number;
|
|
35
|
+
turnTimeoutMs: number;
|
|
36
|
+
toolResultChars: number;
|
|
37
|
+
}
|
|
38
|
+
export declare const WORKFLOW_RUN_BUDGET: Readonly<WorkflowRunBudget>;
|
|
39
|
+
/** The cookbook change workflow's definition key. */
|
|
40
|
+
export declare const COOKBOOK_CHANGE_WORKFLOW = "cookbook-host.change";
|
|
41
|
+
/** The registered prompt every step of the change workflow sends. */
|
|
42
|
+
export declare const COOKBOOK_CHANGE_STEP_PROMPT = "cookbook-host.change.step";
|
|
43
|
+
/**
|
|
44
|
+
* The step prompt (#5005): the person's request, the step and its stage, the
|
|
45
|
+
* pinned output schema, the earlier steps' accepted outputs and, on a
|
|
46
|
+
* repair, the invalid output with its errors. An app or tenant may override
|
|
47
|
+
* its text; the step's schema and host check still decide what is accepted.
|
|
48
|
+
*/
|
|
49
|
+
export declare const cookbookChangeStepPrompt: import("@happyvertical/smrt-prompts").PromptDefinition;
|
|
50
|
+
/** What a step's turn returns: the model's output (an object or JSON text). */
|
|
51
|
+
export interface ExecuteWorkflowStepInput {
|
|
52
|
+
ownerId: string;
|
|
53
|
+
tenantId: string | null;
|
|
54
|
+
threadId: string;
|
|
55
|
+
content: string;
|
|
56
|
+
stage: 'propose' | 'revise';
|
|
57
|
+
execution: WorkflowRunExecution;
|
|
58
|
+
permissions: readonly string[];
|
|
59
|
+
/** The step's registered prompt, resolved for this attempt. */
|
|
60
|
+
prompt: ResolvedPrompt;
|
|
61
|
+
schema: Record<string, unknown>;
|
|
62
|
+
/** The workflow run's context: the step's turn runs as its child. */
|
|
63
|
+
runContext: AiRunContext;
|
|
64
|
+
step: {
|
|
65
|
+
index: number;
|
|
66
|
+
count: number;
|
|
67
|
+
name: string;
|
|
68
|
+
};
|
|
69
|
+
signal: AbortSignal;
|
|
70
|
+
}
|
|
71
|
+
/** Host callbacks keep the normal authenticated assistant route and approvals. */
|
|
72
|
+
export interface CookbookWorkflowRunsOptions {
|
|
73
|
+
db: DatabaseInterface;
|
|
74
|
+
budget?: Partial<WorkflowRunBudget>;
|
|
75
|
+
authorize(ownerId: string, tenantId: string | null): Promise<void>;
|
|
76
|
+
authorizeThread?(ownerId: string, tenantId: string | null, threadId: string): Promise<void>;
|
|
77
|
+
/** Normal app.describe read; its pinned catalog only classifies work, never authorizes it. */
|
|
78
|
+
describeApp?(ownerId: string, tenantId: string | null): Promise<CookbookToolResult | undefined>;
|
|
79
|
+
executeOperation?(input: {
|
|
80
|
+
ownerId: string;
|
|
81
|
+
tenantId: string | null;
|
|
82
|
+
threadId: string;
|
|
83
|
+
runId: string;
|
|
84
|
+
actionId: string;
|
|
85
|
+
permissions: readonly string[];
|
|
86
|
+
operation: {
|
|
87
|
+
tool: CookbookToolName;
|
|
88
|
+
args: Record<string, unknown>;
|
|
89
|
+
};
|
|
90
|
+
signal: AbortSignal;
|
|
91
|
+
}): Promise<CookbookToolResult>;
|
|
92
|
+
/** Current core-owned structural schemas, resolved under the live owner. */
|
|
93
|
+
listOperations?(ownerId: string, tenantId: string | null): Promise<readonly Pick<CookbookToolDefinition, 'name' | 'inputSchema' | 'description'>[]>;
|
|
94
|
+
/** Run one step as an assistant turn (a child run of the workflow run). */
|
|
95
|
+
executeStep(input: ExecuteWorkflowStepInput): Promise<unknown>;
|
|
96
|
+
}
|
|
97
|
+
/** Wire progress of a workflow run; names and notes are the host's own. */
|
|
98
|
+
export interface CookbookWorkflowProgress {
|
|
99
|
+
runId: string;
|
|
100
|
+
step: {
|
|
101
|
+
index: number;
|
|
102
|
+
count: number;
|
|
103
|
+
name: string;
|
|
104
|
+
};
|
|
105
|
+
status: 'running' | 'checking' | 'waiting-approval' | 'stopped' | 'failed' | 'done';
|
|
106
|
+
note?: string;
|
|
107
|
+
}
|
|
108
|
+
interface ListCatalog {
|
|
109
|
+
revision: number;
|
|
110
|
+
lists: Array<{
|
|
111
|
+
id: string;
|
|
112
|
+
label: string;
|
|
113
|
+
synonyms: string[];
|
|
114
|
+
}>;
|
|
115
|
+
}
|
|
116
|
+
/** The run input: durable, never a credential or a captured Request. */
|
|
117
|
+
export interface CookbookWorkflowInput {
|
|
118
|
+
threadId: string;
|
|
119
|
+
content: string;
|
|
120
|
+
execution: WorkflowRunExecution;
|
|
121
|
+
/** The original authenticated permission ceiling; never model supplied. */
|
|
122
|
+
permissions: string[];
|
|
123
|
+
/** The app set its own step count: no adaptive early finish. */
|
|
124
|
+
fixedSteps: boolean;
|
|
125
|
+
listCatalog?: ListCatalog;
|
|
126
|
+
/** The output schema pinned at start (live owner operations). */
|
|
127
|
+
schema: Record<string, unknown>;
|
|
128
|
+
schemaPin: string;
|
|
129
|
+
/** The work needs more than the first step. */
|
|
130
|
+
expanded?: boolean;
|
|
131
|
+
previousCheck?: Record<string, unknown>;
|
|
132
|
+
pendingApprovalId?: string;
|
|
133
|
+
results?: CookbookToolResult[];
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Whether the run's current step is the one whose accepted proposal is
|
|
137
|
+
* applied: the last step, or an adaptive first step.
|
|
138
|
+
*/
|
|
139
|
+
export declare function isCookbookApplyStep(state: Pick<WorkflowRunState, 'step' | 'phase' | 'input' | 'pending'>): boolean;
|
|
140
|
+
/** The validated run input. */
|
|
141
|
+
export declare function readInput(input: unknown): CookbookWorkflowInput;
|
|
142
|
+
/**
|
|
143
|
+
* Public progress is host-owned: model prose, checkpoint notes and error
|
|
144
|
+
* text stay private. Adaptive work shows one planned step until it expands.
|
|
145
|
+
*/
|
|
146
|
+
export declare function presentCookbookWorkflowRun(state: Readonly<WorkflowRunState>, needsInformation?: boolean): CookbookWorkflowProgress;
|
|
147
|
+
/**
|
|
148
|
+
* The cookbook change workflow on smrt-workflows (#4994, #5005): one
|
|
149
|
+
* `workflow` run per request, its steps run as named handler jobs with claim
|
|
150
|
+
* fencing, each step an assistant turn (a child run) over the registered
|
|
151
|
+
* step prompt, its output checked against the pinned schema and by the host
|
|
152
|
+
* check, which applies the accepted proposal through the core cookbook
|
|
153
|
+
* service and holds for the owner where the service requires it. Create it
|
|
154
|
+
* once per database at startup, BEFORE the host's task runner starts
|
|
155
|
+
* (creating it later throws); dispose it after the runner stops.
|
|
156
|
+
*/
|
|
157
|
+
export declare function createCookbookWorkflowRuns(options: CookbookWorkflowRunsOptions): {
|
|
158
|
+
budget: WorkflowRunBudget;
|
|
159
|
+
definition: WorkflowDefinition;
|
|
160
|
+
/** Forget the definition; stop the task runner first. */
|
|
161
|
+
dispose: () => void;
|
|
162
|
+
forOwner(ownerId: string, tenantId: string | null): {
|
|
163
|
+
present: (state: WorkflowRunState) => Promise<CookbookWorkflowProgress>;
|
|
164
|
+
start(input: {
|
|
165
|
+
threadId: string;
|
|
166
|
+
content: string;
|
|
167
|
+
execution: WorkflowRunExecution;
|
|
168
|
+
/** Captured authenticated permission ceiling; never model supplied. */
|
|
169
|
+
permissions?: readonly string[];
|
|
170
|
+
/** The app set its own step count. */
|
|
171
|
+
fixedSteps?: boolean;
|
|
172
|
+
}): Promise<WorkflowRunState>;
|
|
173
|
+
/** The newest run of a thread (of this owner's newest 100). */
|
|
174
|
+
latest(threadId: string): Promise<WorkflowRunState | null>;
|
|
175
|
+
get: (id: string) => Promise<WorkflowRunState>;
|
|
176
|
+
/**
|
|
177
|
+
* Check a saved action against the run's accepted proposal before
|
|
178
|
+
* the core service executes or replays it.
|
|
179
|
+
*/
|
|
180
|
+
validateAction(id: string, actionId: string, tool: string, args: Record<string, unknown>): Promise<void>;
|
|
181
|
+
stop: (id: string) => Promise<WorkflowRunState>;
|
|
182
|
+
/**
|
|
183
|
+
* Resume a stopped run (raising its limits within the app's), or
|
|
184
|
+
* recover a run whose worker died.
|
|
185
|
+
*/
|
|
186
|
+
resume(id: string, raise?: AiRunBudget): Promise<WorkflowRunState>;
|
|
187
|
+
/**
|
|
188
|
+
* Carry an owner decision on the run's pending native hold into the
|
|
189
|
+
* run: approved (or approved and deferred while stopped) re-runs the
|
|
190
|
+
* check, which replays the held action once; denied, failed or
|
|
191
|
+
* expired fails the step. Harmless to repeat.
|
|
192
|
+
*/
|
|
193
|
+
settleHold(id: string, record: {
|
|
194
|
+
id: string;
|
|
195
|
+
status: string;
|
|
196
|
+
} | null | undefined): Promise<WorkflowRunState>;
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
/** The host's cookbook workflow runs. */
|
|
200
|
+
export type CookbookWorkflowRuns = ReturnType<typeof createCookbookWorkflowRuns>;
|
|
201
|
+
export {};
|