palbase 0.43.2 → 0.44.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.
Files changed (52) hide show
  1. package/dist/ai/index.js +2 -2
  2. package/dist/backend/engine.js +2 -2
  3. package/dist/backend/env.js +1 -1
  4. package/dist/backend/index.js +3 -3
  5. package/dist/backend/stack.js +1 -1
  6. package/dist/backend/test.js +2 -2
  7. package/dist/chunks/{5AFQHJYE.js → 2FPKHWVW.js} +2 -2
  8. package/dist/chunks/{P5EFS7JB.js → 3EUGTM7R.js} +1 -1
  9. package/dist/chunks/{RLFOMLA6.js → 4WWSBV72.js} +1 -1
  10. package/dist/chunks/{ZGFYTDBX.js → 5CC3IGUQ.js} +1 -1
  11. package/dist/chunks/{OLMU3ODF.js → ANV23OPS.js} +2 -2
  12. package/dist/chunks/{E6BZRE2N.js → BTO2F3RA.js} +2 -2
  13. package/dist/chunks/{FCF3UM3A.js → BVLE3M57.js} +2 -2
  14. package/dist/chunks/{CW6YXFVV.js → CGP6K74O.js} +1 -1
  15. package/dist/chunks/{26QIRZHC.js → DFT3KHRH.js} +2 -2
  16. package/dist/chunks/{NDSHGZTF.js → FKDHMJRY.js} +1 -1
  17. package/dist/chunks/{GHB6JKVO.js → GIQ62AMP.js} +2 -2
  18. package/dist/chunks/{X6P5WU56.js → GJEJ43IS.js} +2 -2
  19. package/dist/chunks/{UHAO6RWA.js → ISRUSUM5.js} +2 -2
  20. package/dist/chunks/{5ZJSSVUB.js → K3G3QG6H.js} +2 -2
  21. package/dist/chunks/{7L3EJBD5.js → MFWSGSEL.js} +2 -2
  22. package/dist/chunks/{MLUWULWR.js → RJYYBHRE.js} +7 -7
  23. package/dist/chunks/{F2T72KU7.js → RRCMPGSQ.js} +2 -2
  24. package/dist/chunks/{5V42WCTP.js → SLIPXW3L.js} +2 -2
  25. package/dist/chunks/{6VXBCORH.js → VFXD5N7B.js} +1 -1
  26. package/dist/chunks/{HJ6MXPE3.js → WESL6FVS.js} +2 -2
  27. package/dist/chunks/X6LXRZ3W.js +18 -0
  28. package/dist/chunks/{YDJSWRID.js → XMIGNCRO.js} +2 -2
  29. package/dist/chunks/{B6G5JODS.js → YBHGKJML.js} +1 -1
  30. package/dist/cli.js +152 -152
  31. package/dist/cloud/index.js +2 -2
  32. package/dist/refuse/ai.js +1 -1
  33. package/dist/refuse/backend.js +1 -1
  34. package/dist/refuse/cloud.js +1 -1
  35. package/dist/refuse/server.js +1 -1
  36. package/dist/server/index.js +2 -2
  37. package/dist/server/testing.js +2 -2
  38. package/dist/web/index.js +2 -2
  39. package/dist/web/message.js +2 -2
  40. package/dist/web/palbe.js +2 -2
  41. package/dist/web/paywall.js +2 -2
  42. package/dist/web/push-sw.js +1 -1
  43. package/dist/web/ssr.js +2 -2
  44. package/dist/web/vite.js +2 -2
  45. package/package.json +2 -2
  46. package/types/ai/src/ai.d.ts +21 -1
  47. package/types/ai/src/chats.d.ts +107 -3
  48. package/types/ai/src/index.d.ts +3 -2
  49. package/types/ai/src/pools.d.ts +177 -0
  50. package/types/ai/src/tools.d.ts +71 -3
  51. package/types/internal/src/modules/machines.d.ts +4 -4
  52. package/dist/chunks/XLZYPS2V.js +0 -18
@@ -1,6 +1,6 @@
1
1
  import type * as modules from '../../internal/src/modules/index.js';
2
2
  import { type ToolResult } from '../../internal/src/tool-output.js';
3
- import { type AgentDefinitionInput, type BackendAgent, type BackendRepo } from './tools.js';
3
+ import { type AgentDefinitionInput, type BackendAgent, type BackendRepo, type WorkspaceTree } from './tools.js';
4
4
  type Module = ReturnType<typeof modules.ai.client>;
5
5
  export type Chat = modules.ai.Chat;
6
6
  export type ChatMessage = modules.ai.ChatMessage;
@@ -51,6 +51,15 @@ export interface EndpointInput {
51
51
  parameters?: Record<string, unknown>;
52
52
  /** Every call waits for a person's yes. */
53
53
  approval?: boolean;
54
+ /**
55
+ * True for an endpoint of the project's own — an MCP server or an https tool — that reads or writes a chat's
56
+ * workspace: each call tells it the tree it is made at (an MCP server in its _meta palbase/workspace, an https tool
57
+ * in its context.workspace: the chat's id, manifestId and seq), and the tree its answer names is waited for. Left out
58
+ * (false): any server's address — a third party's API or MCP server — told nothing of the chat's workspace (an https
59
+ * tool is told the turn's chatId as ever), a tree it answers ignored. An endpoint put before https tools took the
60
+ * setting is told nothing until it is put again with it. The backend's own tools are told the workspace always.
61
+ */
62
+ workspace?: boolean;
54
63
  }
55
64
  export interface MemberInput {
56
65
  userId: string;
@@ -106,6 +115,12 @@ export interface CreateChat {
106
115
  */
107
116
  trailers?: CommitTrailer[];
108
117
  };
118
+ /**
119
+ * The project's runner pool its workspace runs on (ai.pools), by its id or its name: its sessions run on the
120
+ * project's own machines enrolled there, a Mac or a Linux box. Left out, the platform's own Linux machines. A chat
121
+ * that names one works in a workspace; one the project has not is refused (400).
122
+ */
123
+ pool?: string;
109
124
  signal?: AbortSignal;
110
125
  }
111
126
  /** A repository the project's chats work in, as the module keeps it. */
@@ -495,7 +510,72 @@ export interface Voices {
495
510
  signal?: AbortSignal;
496
511
  }): Promise<ChatVoice>;
497
512
  }
498
- /** A chat's workspace, from its server: a file of a tree it published, a repository put in it at work. */
513
+ /** What a write of a chat's workspace left: the tree it is at now — what a tool answers with ai.answer(output, { workspaceTree }). */
514
+ export interface WorkspaceWrite {
515
+ /** The file. */
516
+ path: string;
517
+ /** The tree the workspace is at now: a file of it is read by it (workspace.file's manifest). */
518
+ manifestId: string;
519
+ /** Its place in the workspace's history. */
520
+ seq: number;
521
+ }
522
+ /** A token of a chat's workspace, never said again: what it may do, what it is for, when it expires. */
523
+ export interface WorkspaceToken {
524
+ /** Its id: revoked by it. */
525
+ id: string;
526
+ /** read: the workspace followed; write: followed and written, both ways. */
527
+ access: 'read' | 'write' | (string & {});
528
+ /** What it is for — the machine's name: a conflict names its writer by it. */
529
+ label?: string;
530
+ expiresAt: string;
531
+ /** The workspace's id in the store. */
532
+ workspaceId: string;
533
+ }
534
+ /**
535
+ * A workspace token as it is minted: the token and where it syncs, said once — on the machine,
536
+ * `PALAI_WORKSPACE_TOKEN=<token> palai workspace sync --url <syncUrl> <dir>`, or the token on standard input with
537
+ * `--token-file -`; never on the command line (palai has no --token: any process on the machine could read it).
538
+ */
539
+ export interface WorkspaceTokenMinted extends WorkspaceToken {
540
+ /** The token, said once: given palai workspace sync in PALAI_WORKSPACE_TOKEN, or on its standard input (--token-file -). */
541
+ token: string;
542
+ /** Where the workspace's token routes are, at the project's own address: `palai workspace sync --url <syncUrl> <dir>`. */
543
+ syncUrl: string;
544
+ }
545
+ /**
546
+ * The tokens of a chat's workspace, from its server: a machine of the customer's — a developer's computer, a CI
547
+ * runner — syncs the workspace with one (palai workspace sync), live and both ways (write) or followed (read). While
548
+ * one lives the chat's workspace events are told (ai.workspace.published, ai.workspace.conflict).
549
+ */
550
+ export interface WorkspaceTokens {
551
+ /**
552
+ * Mints one, said once: it lives ttlSeconds (1 to 604 800; an hour when left out) — no longer than an environment's
553
+ * token it is minted with — and answers at the project's own address alone (syncUrl). A member who mints one (the
554
+ * project letting its app's users in) mints it for an hour at most; it is theirs alone, and stops answering when they
555
+ * leave the chat or the project turns clients off. A chat whose first turn has not opened its workspace has it opened
556
+ * now; a chat of no workspace: 409 no_workspace.
557
+ */
558
+ create(id: string, token: {
559
+ access: 'read' | 'write';
560
+ ttlSeconds?: number;
561
+ label?: string;
562
+ signal?: AbortSignal;
563
+ }): Promise<WorkspaceTokenMinted>;
564
+ /** Its tokens — access, label, when each expires — none of them said again: the server's every one, a member's their own. */
565
+ list(id: string, options?: {
566
+ signal?: AbortSignal;
567
+ }): Promise<WorkspaceToken[]>;
568
+ /** Revoked at once: every token route refuses it from then, and an event stream open with it ends. A member revokes their own. */
569
+ revoke(id: string, tokenId: string, options?: {
570
+ signal?: AbortSignal;
571
+ }): Promise<void>;
572
+ }
573
+ /**
574
+ * A file's bytes as a workspace write takes them: text (written as UTF-8), bytes, a Blob, or a stream of bytes — a
575
+ * stream is read here whole first (64 MiB at most), so the write says its length, as the workspace's store asks.
576
+ */
577
+ export type WorkspaceFileBody = string | Uint8Array | Blob | ReadableStream<Uint8Array>;
578
+ /** A chat's workspace, from its server: a file of a tree it published, written or removed, a repository put in it at work, its sync tokens. */
499
579
  export interface Workspaces {
500
580
  /**
501
581
  * A file of the chat's workspace, its bytes: from the tree it is at now, or from the one an ai.workspace.published
@@ -516,6 +596,26 @@ export interface Workspaces {
516
596
  branch?: string;
517
597
  signal?: AbortSignal;
518
598
  }): Promise<Chat>;
599
+ /**
600
+ * Writes one file of the chat's workspace, its bytes the body (64 MiB at most: a larger one is refused here, before it
601
+ * is sent — a stream as soon as it passes the bound — and by the module, 413 file_too_large): published over
602
+ * whatever the workspace's head holds — the write is deliberate, no conflict is made of it — and synced to every
603
+ * machine that holds the workspace, the session's own before the agent's next command; it is told as
604
+ * ai.workspace.published. path is relative to its root (repo/src/config.json): 1 to 2048 bytes, each segment 255 at
605
+ * most. A stream body is read whole before the write is sent, so it says its length. A backend tool that writes answers
606
+ * the tree it left: ai.answer(output, { workspaceTree: written }). A chat whose first turn has not opened its
607
+ * workspace has it opened now; a chat of no workspace: 409 no_workspace.
608
+ */
609
+ write(id: string, path: string, body: WorkspaceFileBody, options?: {
610
+ contentType?: string;
611
+ signal?: AbortSignal;
612
+ }): Promise<WorkspaceWrite>;
613
+ /** Removes one file of the chat's workspace, as a write is made: synced to every machine that holds it. */
614
+ remove(id: string, path: string, options?: {
615
+ signal?: AbortSignal;
616
+ }): Promise<WorkspaceWrite>;
617
+ /** The tokens a machine of the customer's syncs the workspace with (palai workspace sync). */
618
+ readonly tokens: WorkspaceTokens;
519
619
  }
520
620
  export interface Chats {
521
621
  create(chat: CreateChat): Promise<Chat>;
@@ -638,11 +738,15 @@ export interface Chats {
638
738
  * The answer of a client tool's call (a tool event's call_id): true when it is the one taken, false when another came
639
739
  * first. As a member (as): the app of the member whose turn it is answers it (403 not_your_turn otherwise). A
640
740
  * backend tool that returned ai.deferred() — its ToolContext's chatId and callId — is answered here too, by the
641
- * server as itself (never as a member), within the while it named.
741
+ * server as itself (never as a member), within the while it named. A tool that wrote the chat's workspace names the
742
+ * tree its writes left (workspaceTree: chats.workspace.write's answer, { manifestId, seq }, either or both), as an
743
+ * answer given at once does (ai.answer(output, { workspaceTree })): the agent's next command waits for the session's
744
+ * machine to have it.
642
745
  */
643
746
  answer(id: string, callId: string, output: ToolResult, options?: {
644
747
  isError?: boolean;
645
748
  as?: string;
749
+ workspaceTree?: WorkspaceTree;
646
750
  }): Promise<boolean>;
647
751
  /** A message for one of the agent's subagents at work (an agent event's run_id, a tool call's ctx.runId), at its next step — as a member, held to their rules. */
648
752
  sendToSubagent(id: string, runId: string, text: string, options?: {
@@ -4,7 +4,8 @@ export { AISchemaError, prepare } from './schema.js';
4
4
  export { ToolError } from './tools.js';
5
5
  export type { Infer, StandardSchema } from './schema.js';
6
6
  export { partial } from './partial.js';
7
- export type { AISettings, Agent, AgentTool, AgentVersion, Agents, Chat, ChatEvents, ChatGoal, ChatMessage, ChatStreamPart, ChatToolCall, ChatVoice, Chats, CommitTrailer, CreateChat, Decision, Endpoint, EndpointInput, Endpoints, ForkChat, GoalChange, Goals, MemberInput, MessageAttachment, MessageFile, MessageImage, Repo, Repos, SendMessage, SetGoal, Settings, StartVoice, TurnAdvisorCost, TurnArtifact, TurnCost, TurnRunCost, TurnToolCall, VoiceCommand, Voices, Workspaces, } from './chats.js';
8
- export type { AdvisorDefinition, AgentContext, AgentDefinitionInput, BackendAgent, BackendAgentOptions, BackendRepo, BackendTool, BackendToolOptions, ChatContext, ClientTool, ClientToolOptions, DeferredAnswer, Effort, HttpsToolRef, McpToolRef, PlatformToolName, PlatformToolRef, PreparedOutput, RepoTokenContext, RepoTokens, SubagentDefinition, Thinking, Tool, ToolAnswer, ToolContext, TurnDefinition, TurnMessage, } from './tools.js';
7
+ export type { AISettings, Agent, AgentTool, AgentVersion, Agents, Chat, ChatEvents, ChatGoal, ChatMessage, ChatStreamPart, ChatToolCall, ChatVoice, Chats, CommitTrailer, CreateChat, Decision, Endpoint, EndpointInput, Endpoints, ForkChat, GoalChange, Goals, MemberInput, MessageAttachment, MessageFile, MessageImage, Repo, Repos, SendMessage, SetGoal, Settings, StartVoice, TurnAdvisorCost, TurnArtifact, TurnCost, TurnRunCost, TurnToolCall, VoiceCommand, Voices, WorkspaceFileBody, WorkspaceToken, WorkspaceTokenMinted, WorkspaceTokens, WorkspaceWrite, Workspaces, } from './chats.js';
8
+ export type { EnvVariable, EnvVariables, Pool, PoolKey, PoolKeyEnroll, PoolKeyMinted, PoolKeys, PoolMachine, PoolMachines, PoolState, Pools } from './pools.js';
9
+ export type { AdvisorDefinition, AgentContext, AgentDefinitionInput, BackendAgent, BackendAgentOptions, BackendRepo, BackendTool, BackendToolOptions, ChatContext, ClientTool, ClientToolOptions, DeferredAnswer, Effort, HttpsToolRef, McpToolRef, PlatformToolName, PlatformToolRef, PreparedOutput, RepoTokenContext, RepoTokens, SubagentDefinition, Thinking, Tool, ToolAnswer, ToolContext, ToolReply, ToolWorkspace, TurnDefinition, TurnMessage, WorkspaceTree, } from './tools.js';
9
10
  export type { AgentEvent, ChatEvent, GoalEvent, GoalKind, HistoryEvent, HistoryItem, MessageEvent, Publication, ResetEvent, TextEvent, ThinkingEvent, ToolEvent, ToolStatus, TranscriptEvent, TurnEnd, TurnEvent, TurnStatus, VoiceEvent, WaitingReason, } from '../../internal/src/chat.js';
10
11
  export type { ToolPart, ToolResult } from '../../internal/src/tool-output.js';
@@ -0,0 +1,177 @@
1
+ import type * as modules from '../../internal/src/modules/index.js';
2
+ type Module = ReturnType<typeof modules.ai.client>;
3
+ /** A runner pool of the project's: its machines of one type — an operating system and an architecture. */
4
+ export interface Pool {
5
+ /** Its id: named by it, or by its name. */
6
+ id: string;
7
+ name: string;
8
+ os: 'linux' | 'macos' | (string & {});
9
+ arch: 'amd64' | 'arm64' | (string & {});
10
+ createdAt?: string;
11
+ /** A listed pool's: how many machines it has. */
12
+ machines?: number;
13
+ /** A listed pool's: how many sessions its machines take at once, and hold now. */
14
+ capacityTotal?: number;
15
+ capacityUsed?: number;
16
+ /** A listed pool's: how many sessions wait for a place. */
17
+ waiting?: number;
18
+ }
19
+ /** A pool's single-use enrolment key: never said again once it is minted. */
20
+ export interface PoolKey {
21
+ /** Its id: revoked by it. */
22
+ id: string;
23
+ label?: string;
24
+ createdAt?: string;
25
+ /** When it can no longer be used. */
26
+ expiresAt?: string;
27
+ /** When a machine last enrolled with it. */
28
+ lastUsedAt?: string;
29
+ revokedAt?: string;
30
+ }
31
+ /**
32
+ * Where a machine enrols, said with a key as it is minted: `palai enroll --url <url> --key-file <file>`, with
33
+ * `--server-name <serverName>` when the door's certificate names another host, and `--ca-file <file>` holding
34
+ * caCertificate when the door's certificate is not publicly trusted.
35
+ */
36
+ export interface PoolKeyEnroll {
37
+ url: string;
38
+ serverName?: string;
39
+ /** The CA the door's certificate is signed by (PEM): saved to a file, palai enroll --ca-file. */
40
+ caCertificate?: string;
41
+ }
42
+ /** A key as it is minted: the key, said once, and where a machine enrols with it. */
43
+ export interface PoolKeyMinted extends PoolKey {
44
+ key: string;
45
+ /** The enrolment address: palai enroll --url. */
46
+ enrollUrl?: string;
47
+ enroll?: PoolKeyEnroll;
48
+ }
49
+ /** A machine of a pool: what it takes and holds, and whether it takes a new session. */
50
+ export interface PoolMachine {
51
+ /** Its id: cordoned, resumed and deleted by it (ai.machines). */
52
+ id: string;
53
+ /** online, offline, or cordoned (it takes no new session). */
54
+ state: 'online' | 'offline' | 'cordoned' | (string & {});
55
+ /** How many sessions it takes at once (palai enroll --capacity), and holds now. */
56
+ capacity: number;
57
+ used: number;
58
+ /** Its label, as it enrolled. */
59
+ label?: string;
60
+ os?: string;
61
+ arch?: string;
62
+ /** Since when it holds none; null: it holds one. */
63
+ idleSince: string | null;
64
+ lastSeenAt: string | null;
65
+ registeredAt: string | null;
66
+ }
67
+ /** A pool's state: what the project's own scaling loop reads to add a machine or take one away. */
68
+ export interface PoolState {
69
+ pool: {
70
+ id: string;
71
+ name: string;
72
+ os: string;
73
+ arch: string;
74
+ };
75
+ capacityTotal: number;
76
+ capacityUsed: number;
77
+ /** How many sessions wait for a place, and since when the oldest waits (null: none waits). */
78
+ waiting: number;
79
+ oldestWaitingSince: string | null;
80
+ machines: PoolMachine[];
81
+ }
82
+ /** A pool's enrolment keys: a machine enrols with one once (`palai enroll --url <enrollUrl> --key-file <file> --capacity <n>`). */
83
+ export interface PoolKeys {
84
+ /**
85
+ * Mints one, said once — here, never again — with where a machine enrols (enrollUrl, enroll): saved to a file on the
86
+ * machine, `palai enroll --url <enrollUrl> --key-file <file> --capacity <n>` (and --server-name, --ca-file when enroll
87
+ * says them) — never on a command line, where any process on the machine could read it; n is how many sessions the
88
+ * machine runs at once (1 or more, default 1). A machine enrolled with it serves the project's sessions once whoever
89
+ * minted it is gone: it is never minted for an environment's token.
90
+ */
91
+ create(pool: string, options?: {
92
+ label?: string;
93
+ signal?: AbortSignal;
94
+ }): Promise<PoolKeyMinted>;
95
+ /** Its keys, none said. */
96
+ list(pool: string, options?: {
97
+ signal?: AbortSignal;
98
+ }): Promise<PoolKey[]>;
99
+ /** No machine enrols with it any more. */
100
+ revoke(keyId: string, options?: {
101
+ signal?: AbortSignal;
102
+ }): Promise<void>;
103
+ }
104
+ /** The project's runner pools: machines of its own its chats' workspaces run on, managed — and scaled — by the project. */
105
+ export interface Pools {
106
+ /** Makes one, of one type: its machines' os (linux, macos) and arch (amd64, arm64). A name taken already: 409 pool_exists. */
107
+ create(pool: {
108
+ name: string;
109
+ os: 'linux' | 'macos';
110
+ arch: 'amd64' | 'arm64';
111
+ signal?: AbortSignal;
112
+ }): Promise<Pool>;
113
+ /** Every pool of the project's, with what its machines hold and how many sessions wait. */
114
+ list(options?: {
115
+ signal?: AbortSignal;
116
+ }): Promise<Pool[]>;
117
+ /**
118
+ * Deletes a pool with no machine left in it, by its id or its name: cordon each machine, delete it once it holds no
119
+ * session (ai.machines.delete), then the pool. One with machines: 409 pool_not_empty.
120
+ */
121
+ delete(pool: string, options?: {
122
+ signal?: AbortSignal;
123
+ }): Promise<void>;
124
+ /** What its owner's scaling loop reads: its machines, the sessions they take and hold, and how many wait. */
125
+ state(pool: string, options?: {
126
+ signal?: AbortSignal;
127
+ }): Promise<PoolState>;
128
+ readonly keys: PoolKeys;
129
+ }
130
+ /** The machines of the project's pools, by their id (a pool's state names them). */
131
+ export interface PoolMachines {
132
+ /** It takes no new session; the sessions it holds go on. */
133
+ cordon(id: string, options?: {
134
+ signal?: AbortSignal;
135
+ }): Promise<void>;
136
+ /** A cordoned machine takes sessions again. */
137
+ resume(id: string, options?: {
138
+ signal?: AbortSignal;
139
+ }): Promise<void>;
140
+ /** A cordoned machine that holds no session leaves its pool, its palai agent refused from then (409 machine_not_cordoned, machine_busy). */
141
+ delete(id: string, options?: {
142
+ signal?: AbortSignal;
143
+ }): Promise<void>;
144
+ }
145
+ /** One of the project's variables: its name, never its value. */
146
+ export interface EnvVariable {
147
+ key: string;
148
+ /** Whether it is a secret (said so in the list); every value is masked in a transcript either way. */
149
+ secret: boolean;
150
+ updatedAt: string;
151
+ }
152
+ /**
153
+ * The project's variables: every command of every session of its agents begun from now has them — on the platform's
154
+ * Linux machines and on its own pools — beside an agent's own (its definition's env), masked in a transcript. A value
155
+ * is sealed where the sessions run: never answered, never logged.
156
+ */
157
+ export interface EnvVariables {
158
+ /** Sets one, or sets it anew: a value of 1 byte to 32 KiB, no NUL; a secret unless secret: false. */
159
+ set(key: string, value: string, options?: {
160
+ secret?: boolean;
161
+ signal?: AbortSignal;
162
+ }): Promise<EnvVariable>;
163
+ /** Sessions begun from now no longer have it. */
164
+ unset(key: string, options?: {
165
+ signal?: AbortSignal;
166
+ }): Promise<void>;
167
+ /** Their names, sorted — whether each is a secret, and when it was set: never a value. */
168
+ list(options?: {
169
+ signal?: AbortSignal;
170
+ }): Promise<EnvVariable[]>;
171
+ }
172
+ export declare function poolsOf(module: Module): {
173
+ pools: Pools;
174
+ machines: PoolMachines;
175
+ env: EnvVariables;
176
+ };
177
+ export {};
@@ -47,6 +47,30 @@ export interface ToolContext extends ChatContext {
47
47
  runId: string;
48
48
  /** The subagent that made the call, by its name; null: the agent itself. */
49
49
  subagent: string | null;
50
+ /**
51
+ * The chat's workspace as the session last wrote it, its writes flushed before the call — absent when the chat
52
+ * works in none. Read a file of it at that tree (chats.workspace.file(chatId, path, { manifest: manifestId })); a
53
+ * tool that writes the workspace (chats.workspace.write) answers the tree its writes left with ai.answer(output, {
54
+ * workspaceTree }), and the agent's next command sees it.
55
+ */
56
+ workspace?: ToolWorkspace;
57
+ }
58
+ /** The tree of a chat's workspace a tool is called at: what the session had written, flushed before the call. */
59
+ export interface ToolWorkspace {
60
+ /** The chat whose workspace it is. */
61
+ chatId: string;
62
+ /** The tree: a file of it is read by it (chats.workspace.file's manifest). */
63
+ manifestId?: string;
64
+ /** Its place in the workspace's history. */
65
+ seq?: number;
66
+ }
67
+ /**
68
+ * The tree a tool's writes left a chat's workspace at — what chats.workspace.write answered ({ manifestId, seq }),
69
+ * either or both: the session's machine takes it before the agent's next command.
70
+ */
71
+ export interface WorkspaceTree {
72
+ manifestId?: string;
73
+ seq?: number;
50
74
  }
51
75
  /** The message that opened a turn, as the backend that defines its agent is told of it. */
52
76
  export interface TurnMessage {
@@ -93,7 +117,7 @@ export interface BackendToolOptions<S extends StandardSchema> {
93
117
  * takes longer returns ai.deferred() at once — a chat's call waits, and the
94
118
  * project's server answers it later with chats.answer(ctx.chatId, ctx.callId, output).
95
119
  */
96
- run(input: Infer<S>, ctx: ToolContext): ToolResult | DeferredAnswer | Promise<ToolResult | DeferredAnswer>;
120
+ run(input: Infer<S>, ctx: ToolContext): ToolResult | DeferredAnswer | ToolReply | Promise<ToolResult | DeferredAnswer | ToolReply>;
97
121
  /** Every call waits for a person's yes (a member of the chat, or the server). */
98
122
  approval?: boolean;
99
123
  /** The project's machine it runs on (default backend). */
@@ -111,14 +135,20 @@ export interface BackendTool<S extends StandardSchema = StandardSchema> {
111
135
  /** The run, its input checked first: what the framework answers the platform's call with — an answer, or one to come (deferred). */
112
136
  call(input: unknown, ctx: ToolContext): Promise<ToolAnswer>;
113
137
  }
114
- /** A backend tool's answer as the platform takes it: now (output), or later — the project's server gives it (chats.answer). */
138
+ /** A backend tool's answer as the platform takes it: now (output, and the tree its writes left the workspace at), or later — the project's server gives it (chats.answer). */
115
139
  export type ToolAnswer = {
116
140
  output: ToolContent[];
117
141
  is_error: boolean;
142
+ workspace_tree?: WireWorkspaceTree;
118
143
  } | {
119
144
  deferred: true;
120
145
  expires_in_seconds?: number;
121
146
  };
147
+ /** A workspace's tree as the platform takes it in a tool's answer. */
148
+ export type WireWorkspaceTree = {
149
+ manifest_id?: string;
150
+ seq?: number;
151
+ };
122
152
  declare const DEFERRED: unique symbol;
123
153
  /** What a backend tool's run returns when its answer comes later: ai.deferred(). */
124
154
  export interface DeferredAnswer {
@@ -136,6 +166,23 @@ export interface DeferredAnswer {
136
166
  export declare function deferred(options?: {
137
167
  expiresInSeconds?: number;
138
168
  }): DeferredAnswer;
169
+ declare const REPLY: unique symbol;
170
+ /** What a backend tool's run returns with what it says beside its output: ai.answer(output, { workspaceTree }). */
171
+ export interface ToolReply {
172
+ readonly [REPLY]: true;
173
+ readonly output: ToolResult;
174
+ readonly workspaceTree?: WorkspaceTree;
175
+ }
176
+ /** The tree a tool says its writes left, as the platform takes it — refused here when the platform would drop it. */
177
+ export declare function workspaceTreeOf(t: unknown, what: string): WireWorkspaceTree;
178
+ /**
179
+ * A backend tool's output with the tree its writes left the chat's workspace at (chats.workspace.write's answer):
180
+ * the session's machine takes that tree before the agent's next command, so the agent sees what the tool wrote. A
181
+ * tool that wrote and then failed says it with its ToolError (new ToolError(message, { workspaceTree })).
182
+ */
183
+ export declare function answer(output: ToolResult, options: {
184
+ workspaceTree: WorkspaceTree;
185
+ }): ToolReply;
139
186
  export interface ClientToolOptions<S extends StandardSchema> {
140
187
  name: string;
141
188
  description: string;
@@ -252,6 +299,15 @@ export interface AgentDefinitionInput {
252
299
  thinking?: Thinking;
253
300
  /** The language of the person the turn works for, a BCP 47 tag (tr, en-GB): the model writes to them in it on every step, and so do its subagents. */
254
301
  language?: string;
302
+ /**
303
+ * The agent's own variables, name → value (64 at most; a name upper-case letters, digits and _, a letter first, not
304
+ * PALAI_…; a value 32 KiB at most): every command of its sessions has them, on every pool, beside the project's
305
+ * (ai.env.set), masked in a transcript. A value is never read back — a definition read says each name with '' — and a
306
+ * name written with '' keeps the value it has.
307
+ */
308
+ env?: Record<string, string>;
309
+ /** A shell script each of its sessions runs once at its start, before the agent's first command, on every pool (64 KiB at most). */
310
+ setup?: string;
255
311
  /**
256
312
  * The shape of its one-shot answers (ai.generate({ agent, prompt })): a zod (valibot, arktype) object schema, or
257
313
  * ai.schema(name, schema) — checked as generate's schema is, here, when the definition is written. A chat's turns
@@ -327,9 +383,17 @@ export interface DeclaredAI {
327
383
  * may name what the chat is not to read); the whole of it is in the app's log.
328
384
  */
329
385
  export declare class ToolError extends Error {
330
- constructor(message: string);
386
+ /** The tree the tool's writes left the chat's workspace at before it failed: what it wrote, the agent sees all the same. */
387
+ readonly workspaceTree?: WorkspaceTree;
388
+ constructor(message: string, options?: {
389
+ workspaceTree?: WorkspaceTree;
390
+ });
331
391
  }
332
392
  export declare const AGENT_NAME: RegExp;
393
+ export declare const POOL_REF: RegExp;
394
+ export declare const LABEL_RULE = "128 bytes at most, no control, format (bidi, zero-width) or line-separator character";
395
+ /** Whether a label is one the module takes: 128 bytes at most, shown as it was written. */
396
+ export declare function shownAsWritten(label: unknown): label is string;
333
397
  /** The input's JSON Schema: an object, written out (no references), as a provider takes a tool's parameters. */
334
398
  export declare function parametersOf(schema: StandardSchema | undefined, what: string): Record<string, unknown>;
335
399
  export declare function backendTool<S extends StandardSchema>(o: BackendToolOptions<S>): BackendTool<S>;
@@ -375,6 +439,10 @@ export declare function backendAgentOf(v: unknown): {
375
439
  export declare function toolRef(t: Tool, what: string): ToolRef;
376
440
  /** The most tool calls a turn or a one-shot answer makes: the engine's own bound. */
377
441
  export declare const MAX_TOOL_CALLS = 10000;
442
+ export declare const ENV_KEY: RegExp;
443
+ export declare const MAX_ENV_VALUE_BYTES: number;
444
+ /** Whether a name is one a variable may have: never one of PALAI_…, the engine's own. */
445
+ export declare function envKeyOk(key: unknown): key is string;
378
446
  /** The shape of an agent's one-shot answers as the module takes it: the JSON Schema generate's schema is sent as. */
379
447
  export declare function outputOf(v: StandardSchema | PreparedOutput, what: string): Record<string, unknown>;
380
448
  /** A definition's bound on its tool calls, refused here as the module would refuse it. */
@@ -206,7 +206,7 @@ export type Machine = {
206
206
  */
207
207
  health_path?: string;
208
208
  /**
209
- * How many copies of the machine run while it is awake, up to 100 (one on Free), over two nodes at least and no node holding more than half of them: a request is sent to one of them, a copy or a node that goes leaves the others serving, and the cluster takes one of them away at a time at most. Every copy is of the machine's size and counts as such against the project's limits and its machine time (a minute in which the number changed is counted at the most it was). What a copy keeps in its own memory or on its own disk the others do not see — a session, a counter, a cache, a timer: a machine with more than one keeps those where every copy reaches them. The machine finds the number in PALBASE_REPLICAS. A long-lived connection (a WebSocket) stays with the copy that took it.
209
+ * How many copies of the machine run while it is awake, up to 100 (one on Free), over two nodes at least and a few to a node (each of up to three on a node of its own, at most 29 of a hundred on one): a request is sent to one of them, a copy or a node that goes leaves the others serving, the cluster takes one of them away at a time at most (a tenth of ten or more), and a new version comes up a quarter of them at a time beside the copies that serve. Every copy is of the machine's size and counts as such against the project's limits and its machine time (a minute in which the number changed is counted at the most it was). What a copy keeps in its own memory or on its own disk the others do not see — a session, a counter, a cache, a timer: a machine with more than one keeps those where every copy reaches them. The machine finds the number in PALBASE_REPLICAS. A long-lived connection (a WebSocket) stays with the copy that took it.
210
210
  */
211
211
  replicas: number;
212
212
  /**
@@ -306,7 +306,7 @@ export type MachineCreate = {
306
306
  */
307
307
  health_path?: string;
308
308
  /**
309
- * How many copies of the machine run while it is awake, up to 100 (one on Free), over two nodes at least and no node holding more than half of them: a request is sent to one of them, a copy or a node that goes leaves the others serving, and the cluster takes one of them away at a time at most. Every copy is of the machine's size and counts as such against the project's limits and its machine time (a minute in which the number changed is counted at the most it was). What a copy keeps in its own memory or on its own disk the others do not see — a session, a counter, a cache, a timer: a machine with more than one keeps those where every copy reaches them. The machine finds the number in PALBASE_REPLICAS. A long-lived connection (a WebSocket) stays with the copy that took it. One when left out.
309
+ * How many copies of the machine run while it is awake, up to 100 (one on Free), over two nodes at least and a few to a node (each of up to three on a node of its own, at most 29 of a hundred on one): a request is sent to one of them, a copy or a node that goes leaves the others serving, the cluster takes one of them away at a time at most (a tenth of ten or more), and a new version comes up a quarter of them at a time beside the copies that serve. Every copy is of the machine's size and counts as such against the project's limits and its machine time (a minute in which the number changed is counted at the most it was). What a copy keeps in its own memory or on its own disk the others do not see — a session, a counter, a cache, a timer: a machine with more than one keeps those where every copy reaches them. The machine finds the number in PALBASE_REPLICAS. A long-lived connection (a WebSocket) stays with the copy that took it. One when left out.
310
310
  */
311
311
  replicas?: number;
312
312
  /**
@@ -663,11 +663,11 @@ export type DatabaseUpdate = {
663
663
  */
664
664
  size?: "dedicated-1x" | "dedicated-2x" | "free" | "hobby" | "standard-16x" | "standard-1x" | "standard-2x" | "standard-32x" | "standard-4x" | "standard-8x" | "starter";
665
665
  /**
666
- * What it holds, grown, in GB: more than it holds, 1 or a multiple of 5, up to 4,000 — never less (409 `storage_shrinks`), and six hours at least after it last grew (409 `storage_grew_recently`, Retry-After). It grows where it is, serving on; it holds the same through a change of size.
666
+ * What it holds, grown, in GB: more than it holds, 1 or a multiple of 5, up to 4,000 — never less (409 `storage_shrinks`), and six hours at least after it last grew (409 `storage_grew_recently`, Retry-After) — at once, though, when its organization's owners were told it is 90% full or full at what it holds (`database.storage_warning`, `database.storage_full`). It grows where it is, serving on; it holds the same through a change of size.
667
667
  */
668
668
  storage_gb?: number;
669
669
  /**
670
- * Whether it grows by itself: 90% full, by half, to the next multiple of 5 GB, six hours at least after it last grew; off when left out. Of a size on a disk of its own.
670
+ * Whether it grows by itself: 90% full, by half, to the next multiple of 5 GB, six hours at least after it last grew; as it was when left out. Of a size on a disk of its own.
671
671
  */
672
672
  storage_autoscaling?: boolean;
673
673
  };