@punica/editor 1.0.6 → 1.0.7
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/dist/index.bundle.esm.js +1 -1
- package/dist/index.bundle.esm.js.map +1 -1
- package/dist/index.bundle.umd.js +1 -1
- package/dist/index.bundle.umd.js.map +1 -1
- package/package.json +28 -3
- package/types/index.d.ts +120 -11
- package/types/punica.module.bootstrap.d.ts +45 -0
- package/types/punica.module.capability.d.ts +359 -0
- package/types/punica.module.extensions.api.d.ts +740 -0
- package/types/punica.module.extensions.settings.d.ts +106 -0
- package/types/punica.module.flow.agent.d.ts +75 -0
- package/types/punica.module.flow.api.d.ts +128 -0
- package/types/punica.module.flow.d.ts +490 -0
- package/types/punica.module.flow.engine.d.ts +228 -0
- package/types/punica.module.flow.mcp.d.ts +26 -0
- package/types/punica.module.flow.notebook.d.ts +210 -0
- package/types/punica.module.flow.primitives.d.ts +700 -0
- package/types/punica.module.flow.shell.d.ts +374 -0
- package/types/punica.module.kernel.ai.d.ts +462 -0
- package/types/punica.module.kernel.commands.d.ts +49 -0
- package/types/punica.module.kernel.events.d.ts +274 -0
- package/types/punica.module.kernel.history.d.ts +20 -0
- package/types/punica.module.kernel.llm.d.ts +343 -0
- package/types/punica.module.kernel.notifications.d.ts +64 -0
- package/types/punica.module.kernel.policy.d.ts +273 -0
- package/types/punica.module.kernel.tasks.d.ts +107 -0
- package/types/punica.module.kernel.timeServer.d.ts +16 -0
- package/types/punica.module.runtime.api.d.ts +214 -0
- package/types/punica.module.runtime.capabilities.d.ts +175 -0
- package/types/punica.module.runtime.compute.d.ts +339 -0
- package/types/punica.module.runtime.datasets.d.ts +234 -0
- package/types/punica.module.runtime.fs.d.ts +385 -0
- package/types/punica.module.runtime.harness.d.ts +246 -0
- package/types/punica.module.runtime.host.d.ts +272 -0
- package/types/punica.module.runtime.inference.d.ts +164 -0
- package/types/punica.module.runtime.lifecycle.d.ts +15 -0
- package/types/punica.module.runtime.llm.d.ts +470 -0
- package/types/punica.module.runtime.mcp.d.ts +139 -0
- package/types/punica.module.runtime.modelRuntimes.d.ts +90 -0
- package/types/punica.module.runtime.models.d.ts +254 -0
- package/types/punica.module.runtime.search.d.ts +59 -0
- package/types/punica.module.runtime.secrets.d.ts +26 -0
- package/types/punica.module.runtime.tasks.d.ts +27 -0
- package/types/punica.module.runtime.vcs.d.ts +67 -0
- package/types/punica.module.runtime.vectors.d.ts +74 -0
- package/types/punica.module.runtime.workspace.d.ts +134 -0
- package/types/punica.module.shell.activityBar.d.ts +42 -0
- package/types/punica.module.shell.components.d.ts +87 -0
- package/types/punica.module.shell.contentTabs.d.ts +33 -0
- package/types/punica.module.shell.dragDrop.d.ts +25 -0
- package/types/punica.module.shell.keyboardShortcuts.d.ts +38 -0
- package/types/punica.module.shell.layout.d.ts +106 -0
- package/types/punica.module.shell.markdown.d.ts +36 -0
- package/types/punica.module.shell.panelTabs.d.ts +48 -0
- package/types/punica.module.shell.profile.d.ts +278 -0
- package/types/punica.module.shell.statusbar.d.ts +26 -0
- package/types/punica.module.shell.view.d.ts +455 -0
- package/types/punica.module.shell.views.d.ts +150 -0
- package/types/punica.module.test.d.ts +562 -0
- package/types/punica.module.activityBar.d.ts +0 -21
- package/types/punica.module.commands.d.ts +0 -21
- package/types/punica.module.dragDrop.d.ts +0 -23
- package/types/punica.module.extensions.d.ts +0 -157
- package/types/punica.module.history.d.ts +0 -18
- package/types/punica.module.keyboardShortcuts.d.ts +0 -29
- package/types/punica.module.layout.d.ts +0 -22
- package/types/punica.module.statusbar.d.ts +0 -21
- package/types/punica.module.timeServer.d.ts +0 -14
- package/types/punica.module.view.d.ts +0 -8
|
@@ -0,0 +1,462 @@
|
|
|
1
|
+
declare module 'punica' {
|
|
2
|
+
export namespace kernel {
|
|
3
|
+
export namespace AI {
|
|
4
|
+
export type StepStatus =
|
|
5
|
+
| 'pending'
|
|
6
|
+
| 'running'
|
|
7
|
+
| 'blocked'
|
|
8
|
+
| 'success'
|
|
9
|
+
| 'failed'
|
|
10
|
+
| 'cancelled';
|
|
11
|
+
|
|
12
|
+
export interface AiPlanStep {
|
|
13
|
+
stepId: string;
|
|
14
|
+
capabilityId: string;
|
|
15
|
+
input?: unknown;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface AiPlan {
|
|
19
|
+
planId: string;
|
|
20
|
+
query: string;
|
|
21
|
+
steps: AiPlanStep[];
|
|
22
|
+
createdAtMs: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface AiRunStep extends AiPlanStep {
|
|
26
|
+
status: StepStatus;
|
|
27
|
+
startedAtMs?: number;
|
|
28
|
+
finishedAtMs?: number;
|
|
29
|
+
correlationId?: string;
|
|
30
|
+
resultPayload?: unknown;
|
|
31
|
+
error?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface AiRun {
|
|
35
|
+
runId: string;
|
|
36
|
+
planId: string;
|
|
37
|
+
startedAtMs: number;
|
|
38
|
+
finishedAtMs?: number;
|
|
39
|
+
steps: AiRunStep[];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface PendingApproval {
|
|
43
|
+
pendingId: string;
|
|
44
|
+
kind: string;
|
|
45
|
+
id: string;
|
|
46
|
+
risk: string;
|
|
47
|
+
approval: string;
|
|
48
|
+
reason?: string;
|
|
49
|
+
correlationId?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Trace id of the invocation that hit the gate (an agent run id
|
|
52
|
+
* for agent-loop calls). Lets approval waiters and per-session UI
|
|
53
|
+
* match a pending to ITS run when concurrent runs gate the same
|
|
54
|
+
* capability.
|
|
55
|
+
*/
|
|
56
|
+
traceId?: string;
|
|
57
|
+
workspaceId?: string;
|
|
58
|
+
timestampMs: number;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Why an agent tool call settled the way it did.
|
|
63
|
+
* - `success` — the gateway returned a result.
|
|
64
|
+
* - `failed` — the gateway threw (validation, provider error, …).
|
|
65
|
+
* - `blocked` — the call was policy-gated and never approved
|
|
66
|
+
* (dismissed, timed out, or the run was cancelled while waiting).
|
|
67
|
+
*/
|
|
68
|
+
export type AgentToolCallStatus = 'success' | 'failed' | 'blocked';
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* One capability invocation the model decided to make during an
|
|
72
|
+
* agent turn, paired with how it resolved after dispatch through
|
|
73
|
+
* the gateway.
|
|
74
|
+
*/
|
|
75
|
+
export interface AgentToolCall {
|
|
76
|
+
/** Provider-supplied call id; correlates the result back to the call. */
|
|
77
|
+
id: string;
|
|
78
|
+
/** Capability id the model invoked (matches a tool catalog entry). */
|
|
79
|
+
name: string;
|
|
80
|
+
/**
|
|
81
|
+
* Arguments the call was finally dispatched with. When `repaired`
|
|
82
|
+
* is true these are the corrected arguments, not the model's
|
|
83
|
+
* original (schema-invalid) ones.
|
|
84
|
+
*/
|
|
85
|
+
arguments: Record<string, unknown>;
|
|
86
|
+
status: AgentToolCallStatus;
|
|
87
|
+
/** Gateway result when `status === 'success'`. */
|
|
88
|
+
resultPayload?: unknown;
|
|
89
|
+
/** Error message when `status === 'failed'` / `'blocked'`. */
|
|
90
|
+
error?: string;
|
|
91
|
+
/**
|
|
92
|
+
* True when the model's original arguments failed input-schema
|
|
93
|
+
* validation and were repaired (re-asked against the schema) before
|
|
94
|
+
* a successful dispatch. Surfaced so the UI can mark the call as
|
|
95
|
+
* auto-corrected.
|
|
96
|
+
*/
|
|
97
|
+
repaired?: boolean;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* A single iteration of the agent loop: the model's response for
|
|
102
|
+
* this turn plus any tool calls it made (resolved). A turn with no
|
|
103
|
+
* tool calls and assistant text is the final answer.
|
|
104
|
+
*/
|
|
105
|
+
export interface AgentTurn {
|
|
106
|
+
/** Zero-based turn index within the run. */
|
|
107
|
+
index: number;
|
|
108
|
+
/** Plain-text the model produced this turn (final answer or narration). */
|
|
109
|
+
assistantText?: string;
|
|
110
|
+
/** Reasoning trace, when the provider exposes a thinking channel. */
|
|
111
|
+
thinking?: string;
|
|
112
|
+
toolCalls: AgentToolCall[];
|
|
113
|
+
/**
|
|
114
|
+
* Token usage of this turn's LLM call, when the provider/stream
|
|
115
|
+
* surfaces it. Absent for providers that don't report usage
|
|
116
|
+
* (e.g. the Anthropic/OpenAI stream path before a host adapter).
|
|
117
|
+
*/
|
|
118
|
+
usage?: runtime.LlmUsage;
|
|
119
|
+
/** Wall-clock duration of this turn's LLM call, in milliseconds. */
|
|
120
|
+
latencyMs?: number;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Aggregated accountability roll-up for a whole agent run. Summed
|
|
125
|
+
* from each turn's `usage` plus the run's wall-clock duration.
|
|
126
|
+
* Token fields are always present (zero when no provider reported
|
|
127
|
+
* usage); `totalCost` only when a host pricing table fed `meta`.
|
|
128
|
+
*/
|
|
129
|
+
export interface AgentRunUsage {
|
|
130
|
+
inputTokens: number;
|
|
131
|
+
outputTokens: number;
|
|
132
|
+
totalTokens: number;
|
|
133
|
+
/**
|
|
134
|
+
* Cache-read subset of `inputTokens` across the run (vendor prompt
|
|
135
|
+
* caching). Present only when at least one turn reported cache
|
|
136
|
+
* activity — absence means the provider surfaced no cache signal,
|
|
137
|
+
* not that caching was cold.
|
|
138
|
+
*/
|
|
139
|
+
cacheReadTokens?: number;
|
|
140
|
+
/** Total cost in USD; present only when call meta carried it. */
|
|
141
|
+
totalCost?: number;
|
|
142
|
+
/** Wall-clock duration of the whole run, in milliseconds. */
|
|
143
|
+
latencyMs: number;
|
|
144
|
+
/** Number of turns (LLM calls) the run took. */
|
|
145
|
+
steps: number;
|
|
146
|
+
/** Total tool dispatches across the run. */
|
|
147
|
+
toolCalls: number;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Per-turn token telemetry published as `ai.agentTurnUsage` after each
|
|
152
|
+
* LLM call inside an agent run. `est*` fields are substrate-side
|
|
153
|
+
* estimates (chars/4 heuristic unless a host injected a real
|
|
154
|
+
* tokenizer); `reported*` fields echo what the provider surfaced.
|
|
155
|
+
* Feeds token-efficiency dashboards: tool-def overhead per turn,
|
|
156
|
+
* history growth, and cache hit rate are all derivable from the
|
|
157
|
+
* event stream without provider cooperation.
|
|
158
|
+
*/
|
|
159
|
+
export interface AgentTurnUsageEvent {
|
|
160
|
+
runId: string;
|
|
161
|
+
/** Zero-based turn index within the run. */
|
|
162
|
+
step: number;
|
|
163
|
+
/** Estimated tokens spent on the `tools` array this turn. */
|
|
164
|
+
estToolDefTokens: number;
|
|
165
|
+
/** Estimated tokens spent on the message history this turn. */
|
|
166
|
+
estHistoryTokens: number;
|
|
167
|
+
/** Estimated tokens of the system prompt. */
|
|
168
|
+
estSystemTokens: number;
|
|
169
|
+
reportedInputTokens?: number;
|
|
170
|
+
reportedOutputTokens?: number;
|
|
171
|
+
/** Vendor cache-read tokens for this turn, when reported. */
|
|
172
|
+
cacheReadTokens?: number;
|
|
173
|
+
/** Number of full tool definitions sent this turn. */
|
|
174
|
+
toolCount: number;
|
|
175
|
+
/** Number of catalog entries deferred (index-only, not full schema). */
|
|
176
|
+
deferredToolCount: number;
|
|
177
|
+
/** True when history compaction ran before this turn's LLM call. */
|
|
178
|
+
compactionApplied: boolean;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Why an agent run stopped.
|
|
183
|
+
* - `final` — the model produced a tool-call-free answer.
|
|
184
|
+
* - `maxSteps` — the step budget was exhausted first.
|
|
185
|
+
* - `cancelled` — the user requested cancellation (`ai.cancelRun`).
|
|
186
|
+
* - `blocked` — a policy-gated tool was not approved.
|
|
187
|
+
* - `error` — the loop hit an unrecoverable error (e.g. no LLM).
|
|
188
|
+
*/
|
|
189
|
+
export type AgentFinishReason =
|
|
190
|
+
| 'final'
|
|
191
|
+
| 'maxSteps'
|
|
192
|
+
| 'cancelled'
|
|
193
|
+
| 'blocked'
|
|
194
|
+
| 'error';
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Input to a single agent run. The catalog the model may call is
|
|
198
|
+
* narrowed by `toolFilter` (Faz 2 ships a curated subset; the full
|
|
199
|
+
* registry comes in Faz 3).
|
|
200
|
+
*/
|
|
201
|
+
export interface AgentRunInput {
|
|
202
|
+
query: string;
|
|
203
|
+
/**
|
|
204
|
+
* Persistent conversation to continue (`kernel.AI.sessions` id).
|
|
205
|
+
* When set, the run seeds its message history from the session's
|
|
206
|
+
* context view (warm continuation) and appends its turns back to
|
|
207
|
+
* the session on finish — every finish reason, so partial context
|
|
208
|
+
* survives cancel/maxSteps. Omitted ⇒ the run is cold and
|
|
209
|
+
* unpersisted, exactly as before sessions existed.
|
|
210
|
+
*/
|
|
211
|
+
sessionId?: string;
|
|
212
|
+
/**
|
|
213
|
+
* Optional capability catalog filter (mirrors
|
|
214
|
+
* `capability.schemaExport`'s filter shape). When omitted, the
|
|
215
|
+
* loop applies its built-in curated default.
|
|
216
|
+
*/
|
|
217
|
+
toolFilter?: Record<string, unknown>;
|
|
218
|
+
/** Maximum loop iterations before stopping with `maxSteps`. */
|
|
219
|
+
maxSteps?: number;
|
|
220
|
+
/**
|
|
221
|
+
* Quality/cost profile for the run. Providers may route models
|
|
222
|
+
* on it, and it selects the run's context budget (how much
|
|
223
|
+
* history is kept verbatim vs compacted, tool-result caps).
|
|
224
|
+
* Default: 'balanced'.
|
|
225
|
+
*/
|
|
226
|
+
profile?: runtime.LlmProfile;
|
|
227
|
+
/** Optional instruction-class id to source the system prompt from. */
|
|
228
|
+
instructionClass?: string;
|
|
229
|
+
/**
|
|
230
|
+
* Include `ivy-node`-origin capabilities (the generated `ivy.node.*`
|
|
231
|
+
* sample nodes) in the curated default catalog. Off by default — these
|
|
232
|
+
* are workflow building blocks, not general IDE actions, so a normal
|
|
233
|
+
* assistant query never sees them. Set `true` on the ivy-* generation
|
|
234
|
+
* path that wants the model to compose existing nodes. Ignored when an
|
|
235
|
+
* explicit `toolFilter` is supplied (that selection is verbatim).
|
|
236
|
+
*/
|
|
237
|
+
includeIvyNodes?: boolean;
|
|
238
|
+
/**
|
|
239
|
+
* Include `mcp`-origin capabilities (external MCP server tools) in the
|
|
240
|
+
* curated default catalog. Off by default — external MCP servers are
|
|
241
|
+
* third-party integrations rooted outside the workspace (a filesystem
|
|
242
|
+
* server rooted elsewhere, a GitHub commit surface, …); the autonomous
|
|
243
|
+
* agent reaching for them unprompted routes work outside the project
|
|
244
|
+
* (e.g. writing a file's content to an external target, leaving the
|
|
245
|
+
* workspace file empty). The product opts in per invocation when the
|
|
246
|
+
* user actually wants the agent to use MCP tools. Mirrors
|
|
247
|
+
* `includeIvyNodes` — a generic origin gate, not a per-server rule.
|
|
248
|
+
* Ignored when an explicit `toolFilter` is supplied (verbatim).
|
|
249
|
+
*/
|
|
250
|
+
includeMcp?: boolean;
|
|
251
|
+
/**
|
|
252
|
+
* Per-server MCP opt-in: the `mcp.<server>.*` server ids the agent may
|
|
253
|
+
* use (e.g. `['github', 'filesystem']`). An mcp-origin tool is included
|
|
254
|
+
* only when its server id is listed here (or `includeMcp` is true, the
|
|
255
|
+
* coarse allow-all). Empty/omitted ⇒ no MCP tools (workspace-scoped
|
|
256
|
+
* default). Lets the product surface a per-server picker instead of an
|
|
257
|
+
* all-or-nothing toggle. Ignored when an explicit `toolFilter` is
|
|
258
|
+
* supplied (verbatim).
|
|
259
|
+
*/
|
|
260
|
+
allowedMcpServers?: string[];
|
|
261
|
+
/**
|
|
262
|
+
* Deferred tool loading (tiered catalog). On by default for large
|
|
263
|
+
* curated catalogs: the model receives a small hot set of full
|
|
264
|
+
* tool definitions plus a one-line index of the rest, and loads
|
|
265
|
+
* full schemas on demand via `capability.search` /
|
|
266
|
+
* `capability.describe`. Set `false` to send the legacy flat
|
|
267
|
+
* narrowed catalog instead. Ignored when `toolFilter` is
|
|
268
|
+
* supplied (verbatim selection is always fully loaded).
|
|
269
|
+
*/
|
|
270
|
+
deferToolLoading?: boolean;
|
|
271
|
+
/**
|
|
272
|
+
* Size of the fully-loaded hot set when deferred loading is
|
|
273
|
+
* active (meta-tools not counted). Default ~16.
|
|
274
|
+
*/
|
|
275
|
+
hotSetSize?: number;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/** Terminal result of an agent run. */
|
|
279
|
+
export interface AgentRunResult {
|
|
280
|
+
runId: string;
|
|
281
|
+
finishReason: AgentFinishReason;
|
|
282
|
+
steps: AgentTurn[];
|
|
283
|
+
/** The model's final answer text, when `finishReason === 'final'`. */
|
|
284
|
+
finalText?: string;
|
|
285
|
+
/** Aggregated token/cost/latency roll-up for the run. */
|
|
286
|
+
usage?: AgentRunUsage;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Metadata for one persistent AI conversation session. Small enough to
|
|
291
|
+
* live in the session index blob — the transcript itself is stored per
|
|
292
|
+
* session and loaded lazily.
|
|
293
|
+
*/
|
|
294
|
+
export interface AiSessionMeta {
|
|
295
|
+
sessionId: string;
|
|
296
|
+
workspaceId?: string;
|
|
297
|
+
/**
|
|
298
|
+
* Display title. Auto-generated from the first user message
|
|
299
|
+
* (trimmed ~48 chars) until the user renames it.
|
|
300
|
+
*/
|
|
301
|
+
title: string;
|
|
302
|
+
createdAtMs: number;
|
|
303
|
+
updatedAtMs: number;
|
|
304
|
+
archived?: boolean;
|
|
305
|
+
/** Transcript length (messages), maintained on append. */
|
|
306
|
+
messageCount: number;
|
|
307
|
+
/** The agent run that last touched this session. */
|
|
308
|
+
lastRunId?: string;
|
|
309
|
+
/** Informational: model/mode used on the last run. */
|
|
310
|
+
modelId?: string;
|
|
311
|
+
agentMode?: boolean;
|
|
312
|
+
policyMode?: 'suggest' | 'execute';
|
|
313
|
+
/**
|
|
314
|
+
* Rough running token estimate of the transcript (chars/4). Input to
|
|
315
|
+
* compaction triggers — not a billing figure.
|
|
316
|
+
*/
|
|
317
|
+
tokenEstimate?: number;
|
|
318
|
+
/** Cumulative run consumption; absent until the first recorded run. */
|
|
319
|
+
usage?: AiSessionUsage;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Cumulative provider-reported consumption for one session, summed
|
|
324
|
+
* from each agent run's `AgentRunUsage` roll-up on finish. Unlike
|
|
325
|
+
* `tokenEstimate` (transcript-size heuristic), these are billing-grade
|
|
326
|
+
* figures. `totalCostUsd` is present only once a run carried host
|
|
327
|
+
* pricing, and is a lower bound when some runs lacked it.
|
|
328
|
+
*/
|
|
329
|
+
export interface AiSessionUsage {
|
|
330
|
+
inputTokens: number;
|
|
331
|
+
outputTokens: number;
|
|
332
|
+
totalTokens: number;
|
|
333
|
+
cacheReadTokens: number;
|
|
334
|
+
totalCostUsd?: number;
|
|
335
|
+
/** Number of agent runs accumulated into this session. */
|
|
336
|
+
runCount: number;
|
|
337
|
+
lastRunAtMs?: number;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* One transcript message. A superset of `runtime.LlmMessage` so the
|
|
342
|
+
* stored history can be replayed into an LLM request directly.
|
|
343
|
+
*/
|
|
344
|
+
export interface AiSessionMessage {
|
|
345
|
+
id: string;
|
|
346
|
+
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
347
|
+
content: string;
|
|
348
|
+
toolCalls?: Array<{
|
|
349
|
+
id: string;
|
|
350
|
+
name: string;
|
|
351
|
+
arguments: Record<string, unknown>;
|
|
352
|
+
}>;
|
|
353
|
+
toolCallId?: string;
|
|
354
|
+
name?: string;
|
|
355
|
+
createdAtMs: number;
|
|
356
|
+
/** The agent run that produced this message, when applicable. */
|
|
357
|
+
runId?: string;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* The compact replay set actually fed to the LLM when a run continues
|
|
362
|
+
* this session — the compaction hook. The full `transcript` stays
|
|
363
|
+
* intact for UI restore; `contextView` holds the token-bounded view
|
|
364
|
+
* (summary + recent tail). Absent contextView ⇒ consumers derive a
|
|
365
|
+
* tail-of-transcript view.
|
|
366
|
+
*/
|
|
367
|
+
export interface AiSessionContextView {
|
|
368
|
+
messages: AiSessionMessage[];
|
|
369
|
+
/** Prepended as a system message when present. */
|
|
370
|
+
summaryText?: string;
|
|
371
|
+
/** Transcript watermark: messages up to this id are summarized. */
|
|
372
|
+
compactedUpToMessageId?: string;
|
|
373
|
+
updatedAtMs: number;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/** Full stored record for one session. */
|
|
377
|
+
export interface AiSessionRecord {
|
|
378
|
+
version: 1;
|
|
379
|
+
meta: AiSessionMeta;
|
|
380
|
+
transcript: AiSessionMessage[];
|
|
381
|
+
contextView?: AiSessionContextView;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Pluggable compaction strategy (token-efficiency workstream plugs in
|
|
386
|
+
* via `AiSessionsApi.setCompactor`). The substrate default keeps a
|
|
387
|
+
* plain tail-of-transcript context view.
|
|
388
|
+
*/
|
|
389
|
+
export interface AiSessionCompactor {
|
|
390
|
+
shouldCompact(record: AiSessionRecord): boolean;
|
|
391
|
+
compact(record: AiSessionRecord): Promise<AiSessionContextView>;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Substrate-central AI session service (`punica.kernel.AI.sessions`).
|
|
396
|
+
* Persistent, workspace-scoped conversation sessions: the assistant UI
|
|
397
|
+
* lists/switches them, and `ai.agent.run` continues one when given a
|
|
398
|
+
* `sessionId`. Storage is host-injectable (approvalStore pattern);
|
|
399
|
+
* default persists to localStorage.
|
|
400
|
+
*/
|
|
401
|
+
export interface AiSessionsApi {
|
|
402
|
+
create(input?: { workspaceId?: string; title?: string }): AiSessionMeta;
|
|
403
|
+
/** Sorted by updatedAtMs desc. Filtered to a workspace when given. */
|
|
404
|
+
list(workspaceId?: string): AiSessionMeta[];
|
|
405
|
+
get(sessionId: string): AiSessionRecord | null;
|
|
406
|
+
rename(sessionId: string, title: string): boolean;
|
|
407
|
+
archive(sessionId: string, archived?: boolean): boolean;
|
|
408
|
+
delete(sessionId: string): boolean;
|
|
409
|
+
/**
|
|
410
|
+
* Append messages to the transcript (and bump meta). Content is
|
|
411
|
+
* size-capped; the transcript is bounded (oldest messages fall out
|
|
412
|
+
* past the cap). Fires the compactor when its trigger reports due.
|
|
413
|
+
*/
|
|
414
|
+
appendMessages(
|
|
415
|
+
sessionId: string,
|
|
416
|
+
messages: AiSessionMessage[],
|
|
417
|
+
opts?: { runId?: string }
|
|
418
|
+
): void;
|
|
419
|
+
/**
|
|
420
|
+
* The replay set for continuing this session in an LLM request:
|
|
421
|
+
* `contextView` when present, otherwise a tail of the transcript
|
|
422
|
+
* (trimmed so it never starts mid tool-call exchange).
|
|
423
|
+
*/
|
|
424
|
+
getContextMessages(sessionId: string): runtime.LlmMessage[];
|
|
425
|
+
setCompactor(compactor: AiSessionCompactor | undefined): void;
|
|
426
|
+
/**
|
|
427
|
+
* Accumulate one run's usage roll-up into `meta.usage` and publish
|
|
428
|
+
* `ai.sessionUpdated` (payload flag `usageRecorded: true`).
|
|
429
|
+
* Returns false when the session does not exist.
|
|
430
|
+
*/
|
|
431
|
+
recordUsage(sessionId: string, usage: AgentRunUsage): boolean;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
export const sessions: AiSessionsApi;
|
|
435
|
+
|
|
436
|
+
export interface AiApi {
|
|
437
|
+
initialize(): void;
|
|
438
|
+
/**
|
|
439
|
+
* Execute the last suggested plan. Pass `editedPlan` to run a
|
|
440
|
+
* user-edited copy instead (plan-before-act editing): it replaces the
|
|
441
|
+
* held plan before running. Omit to run the last plan as-is.
|
|
442
|
+
*/
|
|
443
|
+
runLastPlan(editedPlan?: AiPlan): Promise<AiRun>;
|
|
444
|
+
getLastPlan(): AiPlan | null;
|
|
445
|
+
getPendingApprovals(): PendingApproval[];
|
|
446
|
+
approvePending(pendingId: string, scope: kernel.ApprovalScope): boolean;
|
|
447
|
+
dismissPending(pendingId: string): boolean;
|
|
448
|
+
/**
|
|
449
|
+
* Run the agentic tool-use loop: the model repeatedly decides on
|
|
450
|
+
* capabilities to call as tools, the loop dispatches them through
|
|
451
|
+
* the gateway (policy/approval/audit), feeds results back, and
|
|
452
|
+
* continues until a final answer, the step budget, cancellation,
|
|
453
|
+
* or an unapproved gate. Each iteration publishes `ai.agent*`
|
|
454
|
+
* events for live rendering.
|
|
455
|
+
*/
|
|
456
|
+
runAgent(input: AgentRunInput): Promise<AgentRunResult>;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
export const manager: AiApi;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
declare module 'punica' {
|
|
2
|
+
export namespace kernel {
|
|
3
|
+
export namespace Commands {
|
|
4
|
+
interface IDisposable {
|
|
5
|
+
dispose(): void;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interface ICommand {
|
|
9
|
+
title: string;
|
|
10
|
+
/**
|
|
11
|
+
* Optional category (group label) for use in command palette or menus.
|
|
12
|
+
*/
|
|
13
|
+
category?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Optional human-readable description for use in command palette.
|
|
16
|
+
*/
|
|
17
|
+
description?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Optional list of keywords/aliases to improve searchability.
|
|
20
|
+
*/
|
|
21
|
+
keywords?: string[];
|
|
22
|
+
/**
|
|
23
|
+
* Optional context expression controlling when the command is visible.
|
|
24
|
+
* Syntax is implementation-defined (e.g. "editorLang == 'python'").
|
|
25
|
+
*/
|
|
26
|
+
when?: string;
|
|
27
|
+
disposable?: Disposable;
|
|
28
|
+
execute(...args: any[]): any;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface ICommandManager {
|
|
32
|
+
registerCommand(commandName: string, command: ICommand): void;
|
|
33
|
+
/**
|
|
34
|
+
* Execute a command and return its result. Commands may return a value or a Promise.
|
|
35
|
+
* Callers can `await` this for async commands.
|
|
36
|
+
*/
|
|
37
|
+
executeCommand(commandName: string, ...args: any[]): any;
|
|
38
|
+
disposeCommand(commandName: string): void;
|
|
39
|
+
/**
|
|
40
|
+
* Returns a snapshot of all registered commands and their metadata.
|
|
41
|
+
* This is primarily intended for use by tools like the command palette.
|
|
42
|
+
*/
|
|
43
|
+
getAllCommands?(): { id: string; command: ICommand }[];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const manager: ICommandManager;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|