@k2b/cloud 0.26.0 → 0.28.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/package.json +3 -3
- package/src/_internal/define-app.ts +8 -1
- package/src/_internal/process-identity.ts +7 -1
- package/src/_internal/registry-validation.ts +3 -0
- package/src/_internal/runtime-context.ts +1 -0
- package/src/ai/admin.ts +1 -0
- package/src/ai/browser-code-contracts.ts +46 -64
- package/src/ai/browser.ts +9 -1
- package/src/ai/capabilities.ts +82 -22
- package/src/ai/chat/blocks.tsx +16 -7
- package/src/ai/chat/builtin-tools.tsx +31 -23
- package/src/ai/chat/file-tools.tsx +4 -1
- package/src/ai/chat/live-turn.browser-harness.tsx +15 -5
- package/src/ai/chat/message-actions.tsx +123 -101
- package/src/ai/chat/message-utils.ts +30 -1
- package/src/ai/chat/messages.ts +206 -2
- package/src/ai/chat/presentation.tsx +94 -28
- package/src/ai/chat/tool-groups.ts +1 -1
- package/src/ai/chat/turn-error.ts +21 -0
- package/src/ai/chat/turn-view.tsx +102 -16
- package/src/ai/chat/user-message.tsx +19 -14
- package/src/ai/chat/visual-tools.tsx +1 -1
- package/src/ai/client/controller.ts +83 -37
- package/src/ai/client/file-source.ts +20 -3
- package/src/ai/client/projection.ts +7 -2
- package/src/ai/code-mode-skill.ts +32 -36
- package/src/ai/code-runtime-tools.ts +14 -1
- package/src/ai/code-source-contracts.ts +56 -6
- package/src/ai/code-source-tools.ts +10 -3
- package/src/ai/credentials.ts +17 -3
- package/src/ai/data-analysis-skill.ts +3 -3
- package/src/ai/default-tools.ts +15 -16
- package/src/ai/executor.ts +281 -141
- package/src/ai/file-context.ts +14 -2
- package/src/ai/file-tools.ts +17 -3
- package/src/ai/files-store.ts +134 -11
- package/src/ai/grids-skill.ts +2 -2
- package/src/ai/index.ts +9 -0
- package/src/ai/memories.ts +14 -0
- package/src/ai/migrate.ts +125 -0
- package/src/ai/model-request-settings.ts +98 -0
- package/src/ai/open-tool-calls.ts +87 -0
- package/src/ai/protocol.ts +6 -0
- package/src/ai/provider.ts +7 -1
- package/src/ai/quota-provider.ts +2 -2
- package/src/ai/request-headers.ts +117 -0
- package/src/ai/routes.ts +40 -6
- package/src/ai/run-timeout.ts +4 -5
- package/src/ai/runtime.ts +9 -1
- package/src/ai/settings.ts +19 -2
- package/src/ai/skill-seeds.ts +35 -7
- package/src/ai/skills.ts +26 -0
- package/src/ai/solid.ts +1 -1
- package/src/ai/store.ts +155 -71
- package/src/ai/stream.ts +180 -37
- package/src/ai/structured.ts +20 -5
- package/src/ai/system-prompt.ts +8 -0
- package/src/ai/tool-call-names.ts +45 -0
- package/src/ai/turn-failure.ts +100 -0
- package/src/ai/turn-policy.ts +248 -0
- package/src/ai/types.ts +52 -4
- package/src/api/admin-ai-quotas.ts +36 -1
- package/src/api/admin-core-settings.ts +16 -23
- package/src/api/admin-outgoing-mail.ts +242 -0
- package/src/api/index.ts +2 -0
- package/src/browser/FileChooser.tsx +11 -0
- package/src/browser/file-chooser-messages.ts +2 -0
- package/src/cli/admin/ai-quotas.ts +70 -1
- package/src/cli/admin/index.ts +8 -0
- package/src/cli/admin/notifications.ts +6 -0
- package/src/cli/admin/outgoing-mail.ts +215 -0
- package/src/contracts/app.ts +2 -0
- package/src/contracts/index.ts +1 -0
- package/src/contracts/outgoing-mail.ts +265 -0
- package/src/contracts/registry.ts +2 -0
- package/src/services/help/store.ts +2 -1
- package/src/services/index.ts +13 -0
- package/src/services/notifications/batches.ts +139 -79
- package/src/services/notifications/channels.ts +33 -13
- package/src/services/notifications/dispatcher.ts +57 -5
- package/src/services/notifications/email-frame.fixture.html +51 -0
- package/src/services/notifications/{email.ts → email-frame.ts} +12 -45
- package/src/services/notifications/email-mail.ts +101 -0
- package/src/services/notifications/index.ts +49 -36
- package/src/services/notifications/observability.ts +9 -1
- package/src/services/notifications/platform.ts +1 -1
- package/src/services/notifications/runtime.ts +9 -3
- package/src/services/outgoing-mail/admin.ts +84 -0
- package/src/services/outgoing-mail/attachments.ts +135 -0
- package/src/services/outgoing-mail/bulk.ts +11 -0
- package/src/services/outgoing-mail/dispatcher.ts +231 -0
- package/src/services/outgoing-mail/drain.ts +60 -0
- package/src/services/outgoing-mail/enqueue.ts +180 -0
- package/src/services/outgoing-mail/index.ts +112 -0
- package/src/services/outgoing-mail/message.ts +14 -0
- package/src/services/outgoing-mail/messages.ts +431 -0
- package/src/services/outgoing-mail/retention.ts +48 -0
- package/src/services/outgoing-mail/runtime.ts +72 -0
- package/src/services/outgoing-mail/send.ts +130 -0
- package/src/services/outgoing-mail/store.ts +397 -0
- package/src/services/outgoing-mail/sync.ts +39 -0
- package/src/services/outgoing-mail/test-send.ts +40 -0
- package/src/services/outgoing-mail/transport.ts +17 -0
- package/src/services/pdf/markdown.ts +22 -4
- package/src/services/postgres.ts +15 -0
- package/src/services/settings/core-settings.ts +19 -38
- package/src/services/settings/store.ts +5 -1
- package/src/shared/ai-model-request-settings.ts +21 -0
- package/src/shared/ai-platform-prompt.ts +49 -5
- package/src/shared/ai-request-options.ts +185 -0
- package/src/shared/markdown/extensions/links.ts +28 -20
- package/src/shared/markdown/index.ts +14 -5
- package/src/shared/markdown/shared.ts +0 -7
- package/src/ssr/GlobalAnnouncements.island.tsx +1 -1
- package/src/ssr/admin-navigation.ts +1 -1
- package/src/ssr/platform-messages.ts +3 -1
- package/src/ssr/workspace-navigation.ts +7 -1
- package/src/styles/effects.css +15 -17
- package/src/styles/tokens.css +2 -0
- package/src/styles/utilities-markdown-editor.css +4 -39
- package/src/styles/utilities-markdown-table.css +14 -17
|
@@ -6,6 +6,8 @@ import type { RequestActor } from "../server";
|
|
|
6
6
|
import { signInvocationToken } from "../services/identity/invocation-token";
|
|
7
7
|
import { withActiveIdentitySigner } from "../services/identity/key-ring";
|
|
8
8
|
import { LOCALE_HEADER } from "../shared/locale";
|
|
9
|
+
import { TIMEZONE_COOKIE } from "../shared/time";
|
|
10
|
+
import { CodeToolFailure } from "./browser-code-contracts";
|
|
9
11
|
import { resolveAiCapabilityActor } from "./capability-execution";
|
|
10
12
|
import { CODE_CAPABILITY_TOKEN_HEADER, codeCapabilityOperation } from "./code-capability-transport";
|
|
11
13
|
import { authorizeCodeExecution } from "./code-execution";
|
|
@@ -25,6 +27,7 @@ type Context = ToolContext & {
|
|
|
25
27
|
conversationId?: string;
|
|
26
28
|
turnId?: string;
|
|
27
29
|
locale?: string;
|
|
30
|
+
timeZone?: string;
|
|
28
31
|
reportProgress?: (message: string) => Promise<void>;
|
|
29
32
|
};
|
|
30
33
|
|
|
@@ -97,6 +100,11 @@ export const runManagedCodeTool =
|
|
|
97
100
|
const headers = new Headers({ authorization: `Bearer ${signed.token}`, "content-type": "application/json" });
|
|
98
101
|
headers.set(CODE_CAPABILITY_TOKEN_HEADER, callback.token);
|
|
99
102
|
if (context.locale) headers.set(LOCALE_HEADER, context.locale);
|
|
103
|
+
const timeZone = runConfig.timeZone ?? context.timeZone;
|
|
104
|
+
headers.set(
|
|
105
|
+
"cookie",
|
|
106
|
+
[`theme=${runConfig.theme ?? "light"}`, ...(timeZone ? [`${TIMEZONE_COOKIE}=${encodeURIComponent(timeZone)}`] : [])].join("; "),
|
|
107
|
+
);
|
|
100
108
|
const response = await fetch(new URL(`/_internal/assistant/tools/${name}`, app.baseUrl), {
|
|
101
109
|
method: "POST",
|
|
102
110
|
headers,
|
|
@@ -160,7 +168,12 @@ export async function waitForManagedCodeCall(
|
|
|
160
168
|
seen.add(approval.id);
|
|
161
169
|
if (approval.decision === null) await request({ id: approval.id, approved });
|
|
162
170
|
}
|
|
163
|
-
if (state.status === "done")
|
|
171
|
+
if (state.status === "done") {
|
|
172
|
+
// Nessi records a thrown error as a failed tool result the model can act on.
|
|
173
|
+
const failure = CodeToolFailure.safeParse(state.result);
|
|
174
|
+
if (failure.success) throw new Error([failure.data.error, failure.data.guidance].filter(Boolean).join(" "));
|
|
175
|
+
return z.json().parse(state.result);
|
|
176
|
+
}
|
|
164
177
|
if (state.status === "lost")
|
|
165
178
|
throw new Error("The isolated code host was lost. The call was not replayed; inspect saved data before starting a new run.");
|
|
166
179
|
await new Promise<void>((resolve, reject) => {
|
|
@@ -41,14 +41,60 @@ const DatabaseSql = z.object({
|
|
|
41
41
|
|
|
42
42
|
const CodeWriteInput = Id.extend({
|
|
43
43
|
expectedRevision: z.number().int().positive(),
|
|
44
|
-
entry: ArtifactPath.optional(),
|
|
44
|
+
entry: ArtifactPath.optional().describe("index.html for an app with an interface, or the script that code_run executes."),
|
|
45
45
|
files: z
|
|
46
46
|
.array(z.union([ArtifactFile, z.object({ path: ArtifactPath, fromFile: AiFileReference }).strict()]))
|
|
47
47
|
.min(1)
|
|
48
48
|
.max(64),
|
|
49
49
|
});
|
|
50
50
|
|
|
51
|
+
const DbName = z
|
|
52
|
+
.string()
|
|
53
|
+
.regex(/^[A-Za-z][A-Za-z0-9_]*$/)
|
|
54
|
+
.max(63);
|
|
55
|
+
const DbColumn = z
|
|
56
|
+
.object({
|
|
57
|
+
name: DbName.refine(
|
|
58
|
+
(name) => !["id", "created_at", "updated_at", "created_by", "updated_by"].includes(name.toLowerCase()),
|
|
59
|
+
"Omit Cloud-managed columns.",
|
|
60
|
+
),
|
|
61
|
+
type: z.enum(["text", "integer", "real", "boolean", "json", "date", "datetime"]),
|
|
62
|
+
not_null: z.boolean().optional(),
|
|
63
|
+
unique: z.boolean().optional(),
|
|
64
|
+
index: z.boolean().optional(),
|
|
65
|
+
})
|
|
66
|
+
.strict();
|
|
67
|
+
const TableWrite = z.enum(["everyone", "own", "managers"]);
|
|
68
|
+
const DatabaseSchemaInput = z.discriminatedUnion("operation", [
|
|
69
|
+
Id.extend({
|
|
70
|
+
operation: z.literal("tables.create"),
|
|
71
|
+
name: DbName,
|
|
72
|
+
columns: z.array(DbColumn).min(1).max(1000),
|
|
73
|
+
write: TableWrite.default("everyone"),
|
|
74
|
+
}),
|
|
75
|
+
Id.extend({
|
|
76
|
+
operation: z.literal("tables.update"),
|
|
77
|
+
table: DbName,
|
|
78
|
+
changes: z
|
|
79
|
+
.object({
|
|
80
|
+
write: TableWrite.optional(),
|
|
81
|
+
rename: DbName.optional(),
|
|
82
|
+
add_columns: z.array(DbColumn).optional(),
|
|
83
|
+
drop_columns: z.array(DbName).optional(),
|
|
84
|
+
rename_columns: z.record(DbName, DbName).optional(),
|
|
85
|
+
})
|
|
86
|
+
.strict(),
|
|
87
|
+
}),
|
|
88
|
+
Id.extend({ operation: z.literal("schema.get"), table: DbName }),
|
|
89
|
+
Id.extend({ operation: z.literal("tables.list") }),
|
|
90
|
+
]);
|
|
91
|
+
|
|
51
92
|
export const CODE_SOURCE_TOOLS = {
|
|
93
|
+
code_database: {
|
|
94
|
+
description:
|
|
95
|
+
"Manage app tables and schema. Manage permission required. Table write rules are everyone (default), own (only creators update/delete), or managers. Cloud sets created_by/updated_by from trusted identity. Schema belongs here, never in runtime scripts.",
|
|
96
|
+
input: DatabaseSchemaInput,
|
|
97
|
+
},
|
|
52
98
|
code_files: {
|
|
53
99
|
description:
|
|
54
100
|
"List authorized files in one explicit chat, Project or App shared store. Returns locations, metadata and nextAfter. Use code_file_stat to obtain the opaque version before copying; does not load bytes into model context.",
|
|
@@ -118,18 +164,20 @@ export const CODE_SOURCE_TOOLS = {
|
|
|
118
164
|
},
|
|
119
165
|
code_storage_list: {
|
|
120
166
|
description:
|
|
121
|
-
"Inspect
|
|
167
|
+
"Inspect shared files/JSON with Manage, or only your personal JSON with scope user and Use. Returns storageRevision, counts and a page of key/bytes/mediaType/version metadata; no file contents. Follow nextAfter.",
|
|
122
168
|
input: Id.extend({
|
|
169
|
+
scope: z.enum(["shared", "user"]).default("shared").describe("user shows only the signed-in viewer’s personal JSON data."),
|
|
123
170
|
area: z.enum(["files", "kv"]),
|
|
124
171
|
after: z.string().max(240).default(""),
|
|
125
172
|
limit: z.number().int().min(1).max(1000).default(100),
|
|
126
|
-
}),
|
|
173
|
+
}).refine((input) => input.scope !== "user" || input.area === "kv", "Personal storage supports JSON keys only."),
|
|
127
174
|
},
|
|
128
175
|
code_storage_delete: {
|
|
129
176
|
description:
|
|
130
|
-
"Delete one shared file/JSON key
|
|
177
|
+
"Delete one shared file/JSON key or clear an area with fresh review and Manage. Scope user deletes only your personal JSON and requires Use. Source, publications and database are preserved. Read code_storage_list first.",
|
|
131
178
|
review: true,
|
|
132
179
|
input: Id.extend({
|
|
180
|
+
scope: z.enum(["shared", "user"]).default("shared"),
|
|
133
181
|
area: z.enum(["files", "kv", "all"]),
|
|
134
182
|
key: z.string().min(1).max(240).optional().describe("Delete this exact key; omit to clear the entire area. Not valid with area all."),
|
|
135
183
|
expectedStorageRevision: z
|
|
@@ -137,7 +185,9 @@ export const CODE_SOURCE_TOOLS = {
|
|
|
137
185
|
.int()
|
|
138
186
|
.positive()
|
|
139
187
|
.describe("storageRevision from code_storage_list; concurrent writes invalidate the review."),
|
|
140
|
-
})
|
|
188
|
+
})
|
|
189
|
+
.refine((input) => input.area !== "all" || input.key === undefined, "all clears both areas and cannot select a key")
|
|
190
|
+
.refine((input) => input.scope !== "user" || input.area === "kv", "Personal storage supports JSON keys only."),
|
|
141
191
|
},
|
|
142
192
|
code_access_read: {
|
|
143
193
|
description:
|
|
@@ -252,7 +302,7 @@ export const CODE_SOURCE_TOOLS = {
|
|
|
252
302
|
},
|
|
253
303
|
code_create: {
|
|
254
304
|
description:
|
|
255
|
-
"Create a private reusable App with
|
|
305
|
+
"Create a private reusable App: an index.html interface with optional style.css and app.js, published actions and optional persistence. Starts with a minimal index.html. For one-off analysis, use code_run with code instead. Returns id and entry path; write source with code_write. Optional icon uses the complete class, e.g. ti ti-chart-bar; omit it when unsure. Does not run or share anything.",
|
|
256
306
|
input: ArtifactCreate.pick({ title: true, description: true, icon: true }),
|
|
257
307
|
},
|
|
258
308
|
code_write: {
|
|
@@ -27,6 +27,7 @@ const WRITE_TOOLS = new Set([
|
|
|
27
27
|
"code_publish",
|
|
28
28
|
"code_restore",
|
|
29
29
|
"code_database_export",
|
|
30
|
+
"code_database",
|
|
30
31
|
...Object.entries(CODE_SOURCE_TOOLS)
|
|
31
32
|
.filter(([, definition]) => "review" in definition && definition.review)
|
|
32
33
|
.map(([name]) => name),
|
|
@@ -62,12 +63,17 @@ export function createCodeSourceTool(name: CodeSourceToolName) {
|
|
|
62
63
|
code_database_clear: "clear",
|
|
63
64
|
code_database_reset: "reset",
|
|
64
65
|
};
|
|
65
|
-
const databaseOperation =
|
|
66
|
+
const databaseOperation =
|
|
67
|
+
name === "code_database" ? z.object({ operation: z.string() }).parse(input).operation : databaseOperations[name];
|
|
66
68
|
let authorizeDatabase: (() => Promise<void>) | undefined;
|
|
67
69
|
if (context.turnId && databaseOperation) {
|
|
68
70
|
const config = await aiConversations.getTurnRunConfig({ conversationId: context.conversationId, turnId: context.turnId });
|
|
69
71
|
if (config?.kind !== "compact" && config?.background) {
|
|
70
|
-
const {
|
|
72
|
+
const {
|
|
73
|
+
id,
|
|
74
|
+
table,
|
|
75
|
+
name: tableName,
|
|
76
|
+
} = z.object({ id: z.string(), table: z.string().optional(), name: z.string().optional() }).parse(input);
|
|
71
77
|
const conversationId = context.conversationId,
|
|
72
78
|
turnId = context.turnId;
|
|
73
79
|
authorizeDatabase = async () => {
|
|
@@ -76,7 +82,7 @@ export function createCodeSourceTool(name: CodeSourceToolName) {
|
|
|
76
82
|
await aiChatTasks.authorizeRuntime({
|
|
77
83
|
mandate: config.mandate,
|
|
78
84
|
kind: "database",
|
|
79
|
-
input: { resourceId: id, operation: databaseOperation },
|
|
85
|
+
input: { resourceId: id, operation: databaseOperation, table: table ?? tableName },
|
|
80
86
|
});
|
|
81
87
|
};
|
|
82
88
|
}
|
|
@@ -163,6 +169,7 @@ export const createCodeSourceTools = () => [
|
|
|
163
169
|
createCodeSourceTool("code_file_stat"),
|
|
164
170
|
createCodeSourceTool("code_file_copy"),
|
|
165
171
|
createCodeSourceTool("code_database_export"),
|
|
172
|
+
createCodeSourceTool("code_database"),
|
|
166
173
|
createCodeSourceTool("code_manage_read"),
|
|
167
174
|
createCodeSourceTool("code_delete"),
|
|
168
175
|
createCodeSourceTool("code_database_read"),
|
package/src/ai/credentials.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { sql } from "bun";
|
|
2
2
|
import { toPgTextArray } from "../services/postgres";
|
|
3
3
|
import { decryptValue, encryptValue } from "../services/settings/crypto";
|
|
4
|
+
import type { AiRequestHeaderPatch } from "./request-headers";
|
|
4
5
|
|
|
5
6
|
type SqlClient = typeof sql;
|
|
6
7
|
|
|
@@ -90,7 +91,12 @@ export const pruneAiCredentials = async (keepProfileIds: readonly string[], db:
|
|
|
90
91
|
*/
|
|
91
92
|
export const splitAiProfileCredentials = (
|
|
92
93
|
rawValue: unknown,
|
|
93
|
-
): {
|
|
94
|
+
): {
|
|
95
|
+
profilesJson: string;
|
|
96
|
+
credentials: Array<{ profileId: string; secret: string }>;
|
|
97
|
+
profileIds: string[];
|
|
98
|
+
requestHeaders: AiRequestHeaderPatch[];
|
|
99
|
+
} | null => {
|
|
94
100
|
if (typeof rawValue !== "string") return null;
|
|
95
101
|
const text = rawValue;
|
|
96
102
|
let parsed: unknown;
|
|
@@ -104,21 +110,29 @@ export const splitAiProfileCredentials = (
|
|
|
104
110
|
const profiles: unknown[] = [];
|
|
105
111
|
const credentials: Array<{ profileId: string; secret: string }> = [];
|
|
106
112
|
const profileIds: string[] = [];
|
|
113
|
+
const requestHeaders: AiRequestHeaderPatch[] = [];
|
|
107
114
|
|
|
108
115
|
for (const entry of parsed) {
|
|
109
116
|
if (!entry || typeof entry !== "object") {
|
|
110
117
|
profiles.push(entry);
|
|
111
118
|
continue;
|
|
112
119
|
}
|
|
113
|
-
const {
|
|
120
|
+
const {
|
|
121
|
+
apiKey,
|
|
122
|
+
requestHeaders: headerPatch,
|
|
123
|
+
requestHeaderNames: _headerNames,
|
|
124
|
+
credentialSetting: _legacy,
|
|
125
|
+
...profile
|
|
126
|
+
} = entry as Record<string, unknown>;
|
|
114
127
|
const profileId = typeof profile.id === "string" ? profile.id.trim() : "";
|
|
115
128
|
if (profileId) {
|
|
116
129
|
profile.id = profileId;
|
|
117
130
|
profileIds.push(profileId);
|
|
131
|
+
if (headerPatch !== undefined) requestHeaders.push({ profileId, patch: headerPatch });
|
|
118
132
|
if (typeof apiKey === "string" && apiKey.trim()) credentials.push({ profileId, secret: apiKey.trim() });
|
|
119
133
|
}
|
|
120
134
|
profiles.push(profile);
|
|
121
135
|
}
|
|
122
136
|
|
|
123
|
-
return { profilesJson: JSON.stringify(profiles), credentials, profileIds };
|
|
137
|
+
return { profilesJson: JSON.stringify(profiles), credentials, profileIds, requestHeaders };
|
|
124
138
|
};
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
import type { AiSkillTemplate } from "./skills";
|
|
3
3
|
export const ASSISTANT_DATA_ANALYSIS_SKILL = {
|
|
4
4
|
"key": "assistant:data-analysis",
|
|
5
|
-
"version":
|
|
5
|
+
"version": 8,
|
|
6
6
|
"name": "assistant-data-analysis",
|
|
7
|
-
"description": "Analyze source data, explain metrics and comparisons, and build evidence-backed reports or
|
|
8
|
-
"instructions": "# Analyze data and deliver an inspectable result\n\nStart with the question the reader needs to answer. Choose a direct answer,\nan
|
|
7
|
+
"description": "Analyze source data, explain metrics and comparisons, and build evidence-backed reports or HTML dashboards in Assistant Code Mode. Use for multi-step analysis, data exploration, and dashboards; a simple chart only needs the Code Mode charts reference.",
|
|
8
|
+
"instructions": "# Analyze data and deliver an inspectable result\n\nStart with the question the reader needs to answer. Choose a direct answer,\nan app shown in this chat, an exported file, or a reusable Studio app accordingly.\nFor a one-time visual analysis, prefer a chat app; filters and buttons do not by\nthemselves require a Studio App. Load `assistant-code-mode` for execution and read\nits `references/apps.md` and `references/charts.md` for interfaces and charts.\nLoading this skill does not install a library or grant access.\n\n## Keep a working plan\n\nFor work with several real steps, use `todo_write` to keep a short chat plan.\nReplace the full `todos` list each time; give each item a stable `id`, actionable\n`content`, and `status` (`pending`, `in_progress`, `completed`, or `cancelled`).\nAt most one step is active. Update as work changes, including user corrections;\nmark a step completed only after doing and checking it. Preserve exact commands\nwhen they matter. Skip this tool for a simple calculation or conversational reply.\n\nFor analysis, useful steps are reconcile source data, build the analysis, and\nverify totals, filters and conclusions. A rendered dashboard alone is not proof\nthat its numbers are correct. Keep blocked source work open and explain why.\n\n## Establish the data\n\nIdentify the actual source, unit of observation, time window, timezone, and\nlatest complete period. Read files or discover the relevant Cloud capabilities\nbefore selecting fields. External APIs use `cloud.http.fetch`; credentials are entered\nonly through the trusted `code_secret` dialog.\n\nInspect a bounded sample, missing values, duplicate keys, types, and coverage.\nReconcile totals and join cardinalities before drawing conclusions. Keep raw\nnumbers separate from display formatting. Distinguish zero from unavailable data;\nstate exclusions and denominator choices. Do not substitute fixture data for a\nblocked source unless the user requested a mockup.\n\nKeep the source query or transformation in the saved source or an accompanying\nfile so another run can reproduce the result. Preserve the source identity and\nretrieval timestamp, without credentials or credential-bearing URLs.\n\n## Build one consistent analysis\n\nDerive charts, metrics, and tables from the same reviewed data. Aggregate large\ninputs in a script before they reach an app; an app shows aggregates, not raw\nexports. Give exact values a table, for example in a `<details>` element under\nthe chart.\n\nChoose the simplest chart that answers the question. Use tables for exact\nrecords, bars for category comparisons, lines for ordered trends, and distributions\nfor spread. State units, comparison windows, and whether a percent is a fraction\nor an already scaled number. Do not imply causation from correlation.\n\nLead reports with the finding, then supporting evidence and limitations.\nLead dashboards with the important measurements, then trends and diagnostic\nbreakdowns. Use shared filters only when they affect all claimed views. Keep the\ninitial view useful without interaction. Avoid unrelated metrics added merely to\nfill a grid.\n\nShow the source context in the app: whether it is a snapshot, when the data was\nretrieved, its sources, and relevant notes. A timestamp records when the data\nwas retrieved; it does not prove that the upstream source is complete. Label\npartial or fixture data visibly.\n\n## Validate before delivery\n\nCompute in a script with `code_run` and inspect the result. Put the filter and\naggregation logic of an app into a module the script can import too\n(`lib/totals.js`), and test it there with filters, empty results and failed\nloads. Reconcile the values the app will show with the reviewed totals and check\nthat filters describe the data actually displayed. A successful schema\nvalidation does not establish analytical correctness. Apps are not rendered in\na test yet; read the static findings of `code_write` and `code_present`, and say\nwhat the person should check.\n\nValidate the logic the app actually uses, rather than pasting its formulas into a\nsecond test script. Keep an independent expectation from the input data: row\ncounts, unmatched joins, totals and representative boundary cases. For targets,\nstate their grain (for example month × region) and aggregate each target once;\nmultiple selected regions must sum their distinct targets. Compare inspected raw\nKPI values and plotted series with independent expectations. A formatted value\nmatching after rounding does not validate the raw ratio. Never round fractions before formatting them as percent. Preserve precision\nuntil display formatting. Test reset, one/multiple/all selections, empty results,\nand complete versus partial periods. A newly generated timestamp is not source\nfreshness: keep the real retrieval or file-snapshot timestamp stable.\n\nFor a Studio App data snapshot, export the validated dataset with `cloud.download` and\n`code_export`, then copy its exact path/version into the App's files with\n`code_file_copy` (see the Code Mode file transfers reference); importing private\nfiles into an App receives fresh review. Read it in the app with\n`JSON.parse(await (await cloud.files.read(\"data.json\")).text())`. Never rebuild a\ntruncated dataset by copying tool output. Keep transformations and source\nidentity alongside the snapshot.\n\nHuman approval and uncertain HTTP outcomes follow the Code Mode HTTP contract.\nDo not replay an external mutation to refresh a chart. Separate local filtering\nfrom external loading; an Apply button can avoid a request for every slider move.\n\n## Save, share, and hand off\n\nFor chat apps, test the numbers with `code_run`, then deliver with\n`code_present({title, files})`. A successful run alone is not visible to the\nuser. Retain source identity, reviewed input data and their real retrieval\ntimestamp. Put writes and external reloads behind explicit buttons; opening an\nold result must not repeat earlier actions. The user can download the current\nview as PDF or static HTML.\n\nFor reusable Studio Apps, reuse one Cloud resource for later revisions of the same report or dashboard.\nSave its source, test that revision, and use the normal Code Mode publication\nworkflow when publication is requested. Publishing a version and granting reader\naccess are separate operations. Preserve existing access; a dashboard request\ndoes not authorize broadening it. Personal secrets are never copied to readers.\n\nA published source version is not automatically a frozen data snapshot. A frozen\nreport must retain the reviewed data explicitly in its authorized resource or\noutput file. A live app must implement its loader and display the retrieval time;\nloading once is not continuous monitoring. No background refresh exists unless\nimplemented through an appropriate supported workflow.\n\nPresent the chat app, resource link or exported file, the data timestamp, and material\ncoverage limitations. Say whether it is a snapshot or reloads from its sources.\nIf publication fails, retain the tested resource and report the failed stage;\ndo not claim success or create a different public destination. Sites-specific\nhosting, access policies, and editor storage are not part of this Cloud workflow.",
|
|
9
9
|
"extraFrontmatter": {}
|
|
10
10
|
} satisfies AiSkillTemplate;
|
package/src/ai/default-tools.ts
CHANGED
|
@@ -3,9 +3,9 @@ import { createCloudAiTranscribeAudioTool } from "./audio-tool";
|
|
|
3
3
|
import {
|
|
4
4
|
CODE_RUNTIME_TOOL_NAMES,
|
|
5
5
|
CodeActionInput,
|
|
6
|
+
CodeCheckInput,
|
|
6
7
|
CodeExportInput,
|
|
7
8
|
CodeInspectInput,
|
|
8
|
-
CodeInteractInput,
|
|
9
9
|
CodeOpenInput,
|
|
10
10
|
CodePresentInput,
|
|
11
11
|
CodeRunInput,
|
|
@@ -110,7 +110,7 @@ export const createCloudAiCodeTools = () => [
|
|
|
110
110
|
defineAiTool({
|
|
111
111
|
name: "code_secret",
|
|
112
112
|
description:
|
|
113
|
-
"Open a trusted Secret input dialog. The user enters the value directly into encrypted Assistant storage; only configured/name returns. Never ask for a credential in chat, survey
|
|
113
|
+
"Open a trusted Secret input dialog. The user enters the value directly into encrypted Assistant storage; only configured/name returns. Never ask for a credential in chat, survey or app fields. Personal secrets are scoped to this chat or resource and bound to the exact HTTPS origin, header and prefix. Use cloud.http.secret(name,{prefix}) in cloud.http.fetch headers; load assistant-code-mode for HTTP details. Web UI required for secret entry; stored secrets also work from CLI.",
|
|
114
114
|
inputSchema: CodeSecretInput,
|
|
115
115
|
outputSchema: z.object({ configured: z.boolean(), name: z.string() }),
|
|
116
116
|
approval: "never",
|
|
@@ -128,27 +128,18 @@ export const createCloudAiCodeTools = () => [
|
|
|
128
128
|
promptHint:
|
|
129
129
|
"For file analysis, data transformations or combining Cloud data, run a short one-off script with code_run. Load assistant-code-mode for its runtime APIs; no saved app is required.",
|
|
130
130
|
description:
|
|
131
|
-
"Run
|
|
131
|
+
"Run one-off script code OR a saved script resource in the isolated worker. Optional resourceId binds one-off code to existing app data (Manage required), without editing its source. Includes cloud.capabilities.run(name,input) to chain Cloud capabilities in JavaScript; load assistant-code-mode for its runtime APIs. Scripts read explicit chat inputPaths. Returns output, logs and captured files for agent inspection only. Apps with an index.html interface do not run here: show them with code_open or code_present. Runs use real shared and personal data; database writes and capability effects keep normal permissions and approvals.",
|
|
132
132
|
inputSchema: CodeRunInput,
|
|
133
133
|
outputSchema: z.json(),
|
|
134
134
|
approval: "never",
|
|
135
135
|
}).server(runManagedCodeTool("code_run")),
|
|
136
136
|
defineAiTool({
|
|
137
137
|
name: "code_inspect",
|
|
138
|
-
description:
|
|
139
|
-
"Inspect a test run: errors, logs, output, controls and pending modal. Use nodeId to inspect table rows or list items; follow pagination only as needed.",
|
|
138
|
+
description: "Inspect a script run: status, progress, errors, logs, output and captured files. Use waitMs to wait for background work.",
|
|
140
139
|
inputSchema: CodeInspectInput,
|
|
141
140
|
outputSchema: z.json(),
|
|
142
141
|
approval: "never",
|
|
143
142
|
}).server(runManagedCodeTool("code_inspect")),
|
|
144
|
-
defineAiTool({
|
|
145
|
-
name: "code_interact",
|
|
146
|
-
description:
|
|
147
|
-
"Operate a control or answer a pending modal using its exact snapshot ID. Buttons need only id; controls use event:{type:change,value:...} or event:{type:select,key:...}. Use answer for modal replies, or answer:null to cancel. Copy an interactions example from code_inspect; never send JSON as a string. Use steps:[{id,event?},...] for up to three known sequential interactions; stops on errors, modals or background work. Returns one resulting state with completedSteps and nextStep.",
|
|
148
|
-
inputSchema: CodeInteractInput,
|
|
149
|
-
outputSchema: z.json(),
|
|
150
|
-
approval: "never",
|
|
151
|
-
}).server(runManagedCodeTool("code_interact")),
|
|
152
143
|
defineAiTool({
|
|
153
144
|
name: "code_stop",
|
|
154
145
|
description: "Stop and release an isolated test run.",
|
|
@@ -158,15 +149,24 @@ export const createCloudAiCodeTools = () => [
|
|
|
158
149
|
}).server(runManagedCodeTool("code_stop")),
|
|
159
150
|
defineAiTool({
|
|
160
151
|
name: "code_open",
|
|
161
|
-
description:
|
|
152
|
+
description:
|
|
153
|
+
"Show the app beside the chat without starting it; HTML apps require a passing code_check for the current files and tables. For one-off calculations, return the result instead of opening an app.",
|
|
162
154
|
inputSchema: CodeOpenInput,
|
|
163
155
|
outputSchema: z.json(),
|
|
164
156
|
approval: "never",
|
|
165
157
|
}).client(),
|
|
158
|
+
defineAiTool({
|
|
159
|
+
name: "code_check",
|
|
160
|
+
description:
|
|
161
|
+
"Mandatory HTML app self-test: write files and steps.json (at most 20 main-flow steps), call code_check({id} OR {files}), look at EVERY screenshot with view_image, fix and check again, then code_open/code_present/code_publish. Runs desktop 1280×800 and phone 390×844 in opposite themes on separate throwaway copies of database, shared KV/files and only your own KV.user. Steps run in both views; reload keeps the copy. Match accessible role/name, label or text exactly, then case-insensitively, then by substring; ambiguous targets fail with candidates, placeholders are never names. Fill numbers with a dot. Upload file is an app-relative source path or chat file path/name. AI runs for real; HTTP, capability effects and approvals are unavailable; read-only granted capabilities run except in background turns. Returns passed, content hash (files, steps and tables), height, issues, calls, captured downloads, three PNG chat paths and an untrusted aria tree (4 KiB). Passing means not broken: inspect screenshots for cut-off, red, tight or doubled content. Self-test is a workflow guard, not a security mechanism. Aborting closes pages and discards copies. Bounded to 45 seconds, 1000 copied rows/16 MiB (schema only beyond), 64 downloads/250 MiB total/50 MiB per file.",
|
|
162
|
+
inputSchema: CodeCheckInput,
|
|
163
|
+
outputSchema: z.json(),
|
|
164
|
+
approval: "never",
|
|
165
|
+
}).server(runManagedCodeTool("code_check")),
|
|
166
166
|
defineAiTool({
|
|
167
167
|
name: "code_present",
|
|
168
168
|
description:
|
|
169
|
-
"
|
|
169
|
+
"Show an HTML app as a card in this chat after a passing code_check for exactly these files and table definitions. Pass files (index.html plus optional style.css and app.js) for a one-off app without saved data, or the id of a saved app to run it live with its data. The person starts the card with a click. Static problems such as CDN scripts, inline handlers or a missing index.html are rejected before anything is saved. For a reusable app beside the chat use code_open.",
|
|
170
170
|
inputSchema: CodePresentInput,
|
|
171
171
|
outputSchema: z.json(),
|
|
172
172
|
approval: "never",
|
|
@@ -193,7 +193,6 @@ export const CLOUD_AI_DEFERRED_BUILTIN_TOOL_NAMES = new Set<string>([
|
|
|
193
193
|
"markdown_to_pdf",
|
|
194
194
|
"html_to_pdf",
|
|
195
195
|
"present",
|
|
196
|
-
"calculate",
|
|
197
196
|
"read_cloud_resource",
|
|
198
197
|
]);
|
|
199
198
|
|