@tencent-adp/portal-cli 0.0.4 → 0.0.6

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.
@@ -8,6 +8,14 @@ export declare class PortalAcpAgent {
8
8
  private readonly workbench;
9
9
  private readonly baseUrl;
10
10
  private readonly sessions;
11
+ private connection;
12
+ /**
13
+ * One task table for the whole agent: a command started in a turn outlives
14
+ * that turn, and its exit is what wakes the session back up.
15
+ */
16
+ private readonly tools;
17
+ /** Which session started each background task, so the exit reaches it. */
18
+ private readonly taskOwners;
11
19
  constructor(client: PortalClient, spaceId: string, workbench: WorkbenchTarget, baseUrl?: string);
12
20
  initialize(): InitializeResponse;
13
21
  newSession(params: NewSessionRequest): NewSessionResponse;
@@ -15,6 +23,32 @@ export declare class PortalAcpAgent {
15
23
  listSessions(params: ListSessionsRequest): ListSessionsResponse;
16
24
  setConfig(params: SetSessionConfigOptionRequest): SetSessionConfigOptionResponse;
17
25
  prompt(params: PromptRequest, acp: AgentContext): Promise<PromptResponse>;
26
+ /** Remembers which session started a task, so its exit reaches that session. */
27
+ private noteTaskOwner;
28
+ /**
29
+ * A background command finished. The model is told in a turn of its own, but
30
+ * only once the current turn is over: interrupting a reply the user is reading
31
+ * to announce a build would be worse than waiting.
32
+ */
33
+ private notifyTaskExit;
34
+ /**
35
+ * Delivers one queued background-task notice as its own turn.
36
+ *
37
+ * Returns as soon as the turn starts, so a caller finishing its own turn never
38
+ * waits on this one. The turn ends by re-entering drainQueue, which is what
39
+ * keeps a backlog flowing in arrival order.
40
+ */
41
+ private drainQueue;
42
+ /**
43
+ * Queues a notice, or starts its turn right away when nothing is running.
44
+ *
45
+ * A running turn is never interrupted: the notice waits for it to end, and
46
+ * prompt() drains the queue at that moment.
47
+ */
48
+ enqueueNotice(sessionId: string, text: string): void;
49
+ /** The connection-scoped client context, set once the transport connects. */
50
+ setConnectionContext(context: AgentContext): void;
51
+ private connectionContext;
18
52
  cancel(sessionId: string): void;
19
53
  private openSession;
20
54
  private record;
package/dist/acp/agent.js CHANGED
@@ -3,6 +3,7 @@ import { PROTOCOL_VERSION, RequestError } from '@agentclientprotocol/sdk';
3
3
  import { createSessionId } from '../cli/session.js';
4
4
  import { portalBaseUrl, readSessions, rememberSession } from '../cli/sessions.js';
5
5
  import { defaultReasoningEffort, isReasoningEffort, pickModel, } from '../portal/target.js';
6
+ import { createLocalTools } from '../tools/local.js';
6
7
  import { replayHistory } from './history.js';
7
8
  import { sessionConfigOptions } from './options.js';
8
9
  import { promptText } from './prompt.js';
@@ -26,6 +27,16 @@ export class PortalAcpAgent {
26
27
  workbench;
27
28
  baseUrl;
28
29
  sessions = new Map();
30
+ connection = null;
31
+ /**
32
+ * One task table for the whole agent: a command started in a turn outlives
33
+ * that turn, and its exit is what wakes the session back up.
34
+ */
35
+ tools = createLocalTools({
36
+ onTaskExit: (snapshot) => this.notifyTaskExit(snapshot),
37
+ });
38
+ /** Which session started each background task, so the exit reaches it. */
39
+ taskOwners = new Map();
29
40
  constructor(client, spaceId, workbench, baseUrl = '') {
30
41
  this.client = client;
31
42
  this.spaceId = spaceId;
@@ -103,6 +114,7 @@ export class PortalAcpAgent {
103
114
  session.abort?.abort();
104
115
  const abort = new AbortController();
105
116
  session.abort = abort;
117
+ session.turnActive = true;
106
118
  try {
107
119
  return await runAcpTurn({
108
120
  session,
@@ -113,6 +125,11 @@ export class PortalAcpAgent {
113
125
  acp,
114
126
  message: promptText(params.prompt),
115
127
  signal: abort.signal,
128
+ tools: this.tools,
129
+ onTaskStarted: (taskId) => this.noteTaskOwner(session.cwd, taskId),
130
+ // Checking a task is a safe point mid-turn: hand over what queued up
131
+ // rather than waiting for the turn to end.
132
+ onTaskChecked: () => session.queue.splice(0).map((notice) => notice.text),
116
133
  });
117
134
  }
118
135
  catch (error) {
@@ -123,8 +140,100 @@ export class PortalAcpAgent {
123
140
  finally {
124
141
  if (session.abort === abort)
125
142
  session.abort = null;
143
+ session.turnActive = false;
144
+ // The turn is over for any reason: this is where a queued background
145
+ // notice gets its turn. Nothing polls.
146
+ this.drainQueue(session);
126
147
  }
127
148
  }
149
+ /** Remembers which session started a task, so its exit reaches that session. */
150
+ noteTaskOwner(cwd, taskId) {
151
+ const session = [...this.sessions.values()].find((item) => item.cwd === cwd);
152
+ if (session)
153
+ this.taskOwners.set(taskId, session.id);
154
+ }
155
+ /**
156
+ * A background command finished. The model is told in a turn of its own, but
157
+ * only once the current turn is over: interrupting a reply the user is reading
158
+ * to announce a build would be worse than waiting.
159
+ */
160
+ notifyTaskExit(snapshot) {
161
+ const sessionId = this.taskOwners.get(snapshot.taskId);
162
+ if (!sessionId)
163
+ return;
164
+ this.taskOwners.delete(snapshot.taskId);
165
+ const status = snapshot.exitCode === null
166
+ ? '已退出(退出码未知)'
167
+ : `已退出(exit ${snapshot.exitCode})`;
168
+ const output = snapshot.output.trim().length > 0
169
+ ? `\n\n输出:\n${snapshot.output.trim()}`
170
+ : '\n\n(没有输出)';
171
+ this.enqueueNotice(sessionId, `后台任务 ${snapshot.taskId} ${status}。${output}`);
172
+ }
173
+ /**
174
+ * Delivers one queued background-task notice as its own turn.
175
+ *
176
+ * Returns as soon as the turn starts, so a caller finishing its own turn never
177
+ * waits on this one. The turn ends by re-entering drainQueue, which is what
178
+ * keeps a backlog flowing in arrival order.
179
+ */
180
+ drainQueue(session) {
181
+ if (session.turnActive)
182
+ return;
183
+ const next = session.queue.shift();
184
+ if (!next)
185
+ return;
186
+ session.turnActive = true;
187
+ const abort = new AbortController();
188
+ session.abort = abort;
189
+ void runAcpTurn({
190
+ session,
191
+ client: this.client,
192
+ spaceId: this.spaceId,
193
+ agentId: this.workbench.agentId,
194
+ models: this.workbench.models,
195
+ // The connection-scoped context: a request-scoped one belongs to a prompt
196
+ // that has already returned, so its notifications have nowhere to go.
197
+ acp: this.connectionContext(),
198
+ message: next.text,
199
+ signal: abort.signal,
200
+ tools: this.tools,
201
+ })
202
+ .catch((error) => {
203
+ if (!abort.signal.aborted) {
204
+ console.error(`background turn failed: ${error instanceof Error ? error.stack : String(error)}`);
205
+ }
206
+ })
207
+ .finally(() => {
208
+ if (session.abort === abort)
209
+ session.abort = null;
210
+ session.turnActive = false;
211
+ this.drainQueue(session);
212
+ });
213
+ }
214
+ /**
215
+ * Queues a notice, or starts its turn right away when nothing is running.
216
+ *
217
+ * A running turn is never interrupted: the notice waits for it to end, and
218
+ * prompt() drains the queue at that moment.
219
+ */
220
+ enqueueNotice(sessionId, text) {
221
+ const session = this.sessions.get(sessionId);
222
+ if (!session)
223
+ return;
224
+ session.queue.push({ text });
225
+ if (!session.turnActive)
226
+ this.drainQueue(session);
227
+ }
228
+ /** The connection-scoped client context, set once the transport connects. */
229
+ setConnectionContext(context) {
230
+ this.connection = context;
231
+ }
232
+ connectionContext() {
233
+ if (!this.connection)
234
+ throw new Error('ACP connection context is not ready yet');
235
+ return this.connection;
236
+ }
128
237
  cancel(sessionId) {
129
238
  this.sessions.get(sessionId)?.abort?.abort();
130
239
  }
@@ -155,6 +264,8 @@ export class PortalAcpAgent {
155
264
  : defaultReasoningEffort(model, process.env.PORTAL_REASONING_EFFORT || this.workbench.defaultReasoningEffort),
156
265
  sentThoughts: new Map(),
157
266
  abort: null,
267
+ turnActive: false,
268
+ queue: [],
158
269
  };
159
270
  this.sessions.set(id, session);
160
271
  return session;
@@ -8,9 +8,16 @@ import { PortalAcpAgent, portalInitialize } from './agent.js';
8
8
  export async function serveAcp() {
9
9
  let started;
10
10
  let canShowLoginUrl = false;
11
+ // The connection-scoped context. It exists before any request arrives, which
12
+ // is what lets a background task notify the client outside a prompt.
13
+ let connection;
11
14
  const stream = acp.ndJsonStream(Writable.toWeb(process.stdout), Readable.toWeb(process.stdin));
12
15
  const start = (interactive, request) => {
13
- const run = createAgent(interactive, request, canShowLoginUrl);
16
+ const run = createAgent(interactive, request, canShowLoginUrl).then((agent) => {
17
+ if (connection)
18
+ agent.setConnectionContext(connection);
19
+ return agent;
20
+ });
14
21
  started = run;
15
22
  run.catch(() => {
16
23
  if (started === run)
@@ -26,6 +33,12 @@ export async function serveAcp() {
26
33
  return start(false);
27
34
  };
28
35
  acp.agent({ name: 'portal' })
36
+ .onConnect((ctx) => {
37
+ connection = ctx.client;
38
+ // An agent may already exist from a previous connection; hand it the new
39
+ // context so background notices keep a live channel.
40
+ void started?.then((agent) => agent.setConnectionContext(ctx.client)).catch(() => undefined);
41
+ })
29
42
  .onRequest(acp.methods.agent.initialize, (ctx) => {
30
43
  canShowLoginUrl = ctx.params.clientCapabilities?.elicitation?.url != null;
31
44
  return portalInitialize(browserLoginRequired());
@@ -1,3 +1,7 @@
1
+ /** A background task that finished while a turn was still running. */
2
+ export interface QueuedNotice {
3
+ text: string;
4
+ }
1
5
  export interface AcpSession {
2
6
  id: string;
3
7
  cwd: string;
@@ -8,5 +12,15 @@ export interface AcpSession {
8
12
  /** Reasoning text already sent to the client, keyed by thought messageId. */
9
13
  sentThoughts: Map<string, string>;
10
14
  abort: AbortController | null;
15
+ /**
16
+ * True while a turn is running. A turn ends for any reason (reply, error,
17
+ * cancel) and the queue is drained at that moment, so no polling is needed.
18
+ */
19
+ turnActive: boolean;
20
+ /**
21
+ * Background-task notices that arrived while a turn was running. FIFO: each
22
+ * one is delivered as its own turn, in arrival order.
23
+ */
24
+ queue: QueuedNotice[];
11
25
  }
12
26
  //# sourceMappingURL=session.d.ts.map
@@ -1,6 +1,7 @@
1
1
  import { type AgentContext, type PromptResponse } from '@agentclientprotocol/sdk';
2
2
  import type { PortalClient } from '../portal/client.js';
3
3
  import type { RuntimeModel } from '../portal/target.js';
4
+ import type { createLocalTools } from '../tools/local.js';
4
5
  import type { AcpSession } from './session.js';
5
6
  export declare function runAcpTurn(input: {
6
7
  session: AcpSession;
@@ -11,5 +12,8 @@ export declare function runAcpTurn(input: {
11
12
  models: RuntimeModel[];
12
13
  message: string;
13
14
  signal: AbortSignal;
15
+ tools: ReturnType<typeof createLocalTools>;
16
+ onTaskStarted?: (taskId: string) => void;
17
+ onTaskChecked?: () => string[];
14
18
  }): Promise<PromptResponse>;
15
19
  //# sourceMappingURL=turn.d.ts.map
package/dist/acp/turn.js CHANGED
@@ -1,22 +1,13 @@
1
1
  import path from 'node:path';
2
2
  import { methods } from '@agentclientprotocol/sdk';
3
3
  import { rememberSession } from '../cli/sessions.js';
4
- import { chatBody, QuestionDeclined, runChat } from '../portal/chat.js';
5
- import { runLocalTool } from '../tools/local.js';
4
+ import { chatBody, runChat } from '../portal/chat.js';
5
+ import { ASK_USER_TOOL_NAME } from '../tools/local.js';
6
6
  export async function runAcpTurn(input) {
7
7
  const result = await runChat({
8
8
  message: input.message,
9
9
  cwd: input.session.cwd,
10
- ask: (question) => askUser(input, question),
11
- replyQuestion: (question, reply) => input.client.replyQuestion({
12
- spaceId: input.spaceId,
13
- agentId: input.agentId,
14
- interactionId: question.interactionId,
15
- expectedVersion: question.version,
16
- answers: reply.answers,
17
- rejected: reply.rejected,
18
- signal: input.signal,
19
- }),
10
+ ask: (questions) => askUser(input, questions),
20
11
  onText: (text) => update(input, {
21
12
  sessionUpdate: 'agent_message_chunk',
22
13
  content: { type: 'text', text },
@@ -87,29 +78,105 @@ function unseenThoughtSuffix(input, thought) {
87
78
  input.session.sentThoughts.set(thought.id, thought.text);
88
79
  return suffix;
89
80
  }
90
- async function askUser(input, question) {
81
+ async function askUser(input, questions) {
91
82
  const answers = [];
92
- for (const [index, item] of question.questions.entries()) {
93
- const response = await input.acp.request(methods.client.session.requestPermission, {
94
- sessionId: input.session.id,
95
- toolCall: {
96
- toolCallId: `${question.interactionId}-${index}`,
97
- title: item.question || item.header || '需要你回答',
98
- kind: 'other',
99
- status: 'pending',
100
- rawInput: { question: item.question, options: item.options },
83
+ try {
84
+ for (const [index, item] of questions.entries()) {
85
+ const toolCallId = `${input.session.id}-ask-${index}`;
86
+ const title = item.question || item.header || '需要你回答';
87
+ // Multiple choice cannot be expressed as permission buttons: Zed renders
88
+ // every option as a single-click allow, so a user can never pick more than
89
+ // one. An elicitation form with an array field renders real checkboxes and
90
+ // only submits on an explicit accept.
91
+ answers.push(item.multiple
92
+ ? await askMultiSelect(input, toolCallId, title, item)
93
+ : await askSingleSelect(input, toolCallId, title, item));
94
+ }
95
+ return { answers };
96
+ }
97
+ catch (error) {
98
+ if (error instanceof QuestionDeclined)
99
+ return { declined: true };
100
+ throw error;
101
+ }
102
+ }
103
+ /** The user closed the question form without answering. */
104
+ class QuestionDeclined extends Error {
105
+ }
106
+ async function askMultiSelect(input, toolCallId, title, item) {
107
+ await update(input, {
108
+ sessionUpdate: 'tool_call',
109
+ toolCallId,
110
+ title,
111
+ kind: 'other',
112
+ status: 'pending',
113
+ rawInput: { question: item.question, options: item.options, multiple: true },
114
+ });
115
+ const response = await input.acp.request(methods.client.elicitation.create, {
116
+ mode: 'form',
117
+ sessionId: input.session.id,
118
+ toolCallId,
119
+ message: title,
120
+ requestedSchema: {
121
+ type: 'object',
122
+ properties: {
123
+ answer: {
124
+ type: 'array',
125
+ title,
126
+ items: {
127
+ anyOf: item.options.map((option) => ({
128
+ const: option.label,
129
+ title: option.description ? `${option.label} — ${option.description}` : option.label,
130
+ })),
131
+ },
132
+ minItems: 1,
133
+ },
101
134
  },
102
- options: permissionOptions(item),
103
- }, {
104
- cancellationSignal: input.signal,
105
- stopWaitingOnCancel: true,
106
- });
107
- if (response.outcome.outcome !== 'selected')
108
- throw new QuestionDeclined();
109
- const selected = item.options[Number(response.outcome.optionId)];
110
- answers.push([selected?.label ?? response.outcome.optionId]);
135
+ required: ['answer'],
136
+ },
137
+ }, {
138
+ cancellationSignal: input.signal,
139
+ stopWaitingOnCancel: true,
140
+ });
141
+ if (response.action !== 'accept') {
142
+ await completeQuestionToolCall(input, toolCallId, 'failed', '用户取消了提问');
143
+ throw new QuestionDeclined();
111
144
  }
112
- return answers;
145
+ const raw = response.content?.answer;
146
+ const selected = Array.isArray(raw)
147
+ ? raw.filter((value) => typeof value === 'string')
148
+ : [];
149
+ await completeQuestionToolCall(input, toolCallId, 'completed', selected.join(', '));
150
+ return selected;
151
+ }
152
+ async function askSingleSelect(input, toolCallId, title, item) {
153
+ const response = await input.acp.request(methods.client.session.requestPermission, {
154
+ sessionId: input.session.id,
155
+ toolCall: {
156
+ toolCallId,
157
+ title,
158
+ kind: 'other',
159
+ status: 'pending',
160
+ rawInput: { question: item.question, options: item.options },
161
+ },
162
+ options: permissionOptions(item),
163
+ }, {
164
+ cancellationSignal: input.signal,
165
+ stopWaitingOnCancel: true,
166
+ });
167
+ if (response.outcome.outcome !== 'selected')
168
+ throw new QuestionDeclined();
169
+ const selected = item.options[Number(response.outcome.optionId)];
170
+ return [selected?.label ?? response.outcome.optionId];
171
+ }
172
+ async function completeQuestionToolCall(input, toolCallId, status, text) {
173
+ await update(input, {
174
+ sessionUpdate: 'tool_call_update',
175
+ toolCallId,
176
+ status,
177
+ rawOutput: text,
178
+ content: [{ type: 'content', content: { type: 'text', text } }],
179
+ });
113
180
  }
114
181
  function permissionOptions(item) {
115
182
  return item.options.map((option, index) => ({
@@ -119,6 +186,14 @@ function permissionOptions(item) {
119
186
  }));
120
187
  }
121
188
  async function reportTool(input, call) {
189
+ // ask_user draws its own question form (permission buttons or an elicitation
190
+ // form); a generic tool call card on top of that would only be noise.
191
+ if (call.name === ASK_USER_TOOL_NAME) {
192
+ return input.tools.run(input.session.cwd, call, {
193
+ signal: input.signal,
194
+ ask: (questions) => askUser(input, questions),
195
+ });
196
+ }
122
197
  const filePath = typeof call.arguments.file_path === 'string' ? call.arguments.file_path : '';
123
198
  await update(input, {
124
199
  sessionUpdate: 'tool_call',
@@ -130,15 +205,27 @@ async function reportTool(input, call) {
130
205
  rawInput: call.arguments,
131
206
  ...(filePath ? { locations: [{ path: path.resolve(input.session.cwd, filePath) }] } : {}),
132
207
  });
133
- const output = await runLocalTool(input.session.cwd, call);
208
+ const output = await input.tools.run(input.session.cwd, call, { signal: input.signal });
209
+ // A command now running in the background must wake this session when it
210
+ // exits, so remember which session started it.
211
+ const task = /^background task started: (\S+)/m.exec(output);
212
+ if (task?.[1])
213
+ input.onTaskStarted?.(task[1]);
214
+ // A status check means the caller is looking at task progress, so this is the
215
+ // safe point to deliver notices that queued up during this turn. They ride
216
+ // along with this tool result instead of interrupting the turn with another.
217
+ const notices = call.name === 'task_status' ? input.onTaskChecked?.() ?? [] : [];
218
+ const reported = notices.length > 0
219
+ ? `${output}\n\n${notices.join('\n\n')}`
220
+ : output;
134
221
  await update(input, {
135
222
  sessionUpdate: 'tool_call_update',
136
223
  toolCallId: call.callId,
137
224
  status: 'completed',
138
- rawOutput: output,
139
- content: [{ type: 'content', content: { type: 'text', text: output } }],
225
+ rawOutput: reported,
226
+ content: [{ type: 'content', content: { type: 'text', text: reported } }],
140
227
  });
141
- return output;
228
+ return reported;
142
229
  }
143
230
  function toolKind(name) {
144
231
  if (name === 'exec')
@@ -1,6 +1,7 @@
1
1
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
2
2
  import { homedir } from 'node:os';
3
3
  import path from 'node:path';
4
+ import { isDevMode } from '../dev.js';
4
5
  const TEMPLATE = {
5
6
  baseUrl: 'https://portal.adp.woa.com',
6
7
  apiKey: '',
@@ -12,7 +13,7 @@ export function authFile() {
12
13
  if (process.env.NODE_TEST_CONTEXT) {
13
14
  throw new Error('Refusing to use ~/.portal/auth.json during tests. Set PORTAL_AUTH_FILE.');
14
15
  }
15
- return path.join(homedir(), '.portal', 'auth.json');
16
+ return path.join(homedir(), '.portal', isDevMode() ? 'auth.dev.json' : 'auth.json');
16
17
  }
17
18
  export function readAuthFile() {
18
19
  const file = authFile();
package/dist/bin.js CHANGED
@@ -1,7 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
  import { serveAcp } from './acp/server.js';
3
3
  import { chat } from './cli/chat.js';
4
- const args = process.argv.slice(2);
4
+ import { setDevMode } from './dev.js';
5
+ const raw = process.argv.slice(2);
6
+ // --dev can appear anywhere: it selects auth.dev.json and turns on the SSE log.
7
+ if (raw.includes('--dev'))
8
+ setDevMode(true);
9
+ const args = raw.filter((arg) => arg !== '--dev');
5
10
  if (args[0] === 'acp') {
6
11
  await serveAcp();
7
12
  }
package/dist/cli/ask.d.ts CHANGED
@@ -1,3 +1,7 @@
1
- import type { UserQuestion } from '../portal/types.js';
2
- export declare function askQuestions(question: UserQuestion): Promise<string[][]>;
1
+ import type { AskUserReply, UserQuestionItem } from '../portal/types.js';
2
+ /**
3
+ * Answers an ask_user call in the terminal. Closing stdin (Ctrl-D) counts as a
4
+ * decline rather than an answer, so the model is never handed a made-up one.
5
+ */
6
+ export declare function askQuestions(questions: UserQuestionItem[]): Promise<AskUserReply>;
3
7
  //# sourceMappingURL=ask.d.ts.map
package/dist/cli/ask.js CHANGED
@@ -1,17 +1,30 @@
1
1
  import { stdin, stdout } from 'node:process';
2
2
  import { createInterface } from 'node:readline/promises';
3
- export async function askQuestions(question) {
3
+ /**
4
+ * Answers an ask_user call in the terminal. Closing stdin (Ctrl-D) counts as a
5
+ * decline rather than an answer, so the model is never handed a made-up one.
6
+ */
7
+ export async function askQuestions(questions) {
4
8
  const rl = createInterface({ input: stdin, output: stdout });
5
9
  const answers = [];
6
10
  try {
7
- for (const item of question.questions) {
11
+ for (const item of questions) {
8
12
  answers.push(await askOne(rl, item));
9
13
  }
14
+ return { answers };
15
+ }
16
+ catch (error) {
17
+ if (isCancelled(error))
18
+ return { declined: true };
19
+ throw error;
10
20
  }
11
21
  finally {
12
22
  rl.close();
13
23
  }
14
- return answers;
24
+ }
25
+ /** readline reports Ctrl-D (and Ctrl-C while waiting) as an abort. */
26
+ function isCancelled(error) {
27
+ return error instanceof Error && (error.name === 'AbortError' || error.name === 'ExitPromptError');
15
28
  }
16
29
  async function askOne(rl, item) {
17
30
  if (item.header)
package/dist/cli/chat.js CHANGED
@@ -24,14 +24,6 @@ export async function chat(input) {
24
24
  message: input.message,
25
25
  cwd,
26
26
  ask: askQuestions,
27
- replyQuestion: (question, reply) => client.replyQuestion({
28
- spaceId: auth.spaceId,
29
- agentId: target.agentId,
30
- interactionId: question.interactionId,
31
- expectedVersion: question.version,
32
- answers: reply.answers,
33
- rejected: reply.rejected,
34
- }),
35
27
  openStream: (turn) => client.streamChat({
36
28
  spaceId: auth.spaceId,
37
29
  agentId: target.agentId,
package/dist/dev.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export declare function setDevMode(value: boolean): void;
2
+ export declare function isDevMode(): boolean;
3
+ //# sourceMappingURL=dev.d.ts.map
package/dist/dev.js ADDED
@@ -0,0 +1,10 @@
1
+ // Set by the CLI entry point when --dev is passed. A source-run session keeps
2
+ // its own auth file and writes the SSE log; a packaged run stays quiet.
3
+ let enabled = false;
4
+ export function setDevMode(value) {
5
+ enabled = value;
6
+ }
7
+ export function isDevMode() {
8
+ return enabled;
9
+ }
10
+ //# sourceMappingURL=dev.js.map
@@ -1,68 +1,25 @@
1
- export declare const TOOL_GUIDANCE: string;
2
- export declare const CALLER_TOOLS: ({
1
+ /** 前端工具(caller tool)声明,形状与运行时的 Tools 字段一致。 */
2
+ export interface CallerToolDefinition {
3
3
  Name: string;
4
4
  Description: string;
5
- InputSchema: {
6
- type: string;
7
- properties: {
8
- command: {
9
- type: string;
10
- description: string;
11
- };
12
- file_path?: undefined;
13
- offset?: undefined;
14
- limit?: undefined;
15
- old_string?: undefined;
16
- new_string?: undefined;
17
- replace_all?: undefined;
18
- };
19
- required: string[];
20
- };
21
- } | {
22
- Name: string;
23
- Description: string;
24
- InputSchema: {
25
- type: string;
26
- properties: {
27
- file_path: {
28
- type: string;
29
- };
30
- offset: {
31
- type: string;
32
- };
33
- limit: {
34
- type: string;
35
- };
36
- command?: undefined;
37
- old_string?: undefined;
38
- new_string?: undefined;
39
- replace_all?: undefined;
40
- };
41
- required: string[];
42
- };
43
- } | {
44
- Name: string;
45
- Description: string;
46
- InputSchema: {
47
- type: string;
48
- properties: {
49
- file_path: {
50
- type: string;
51
- };
52
- old_string: {
53
- type: string;
54
- };
55
- new_string: {
56
- type: string;
57
- };
58
- replace_all: {
59
- type: string;
60
- };
61
- command?: undefined;
62
- offset?: undefined;
63
- limit?: undefined;
64
- };
65
- required: string[];
66
- };
67
- })[];
5
+ InputSchema: Record<string, unknown>;
6
+ }
7
+ /**
8
+ * 一组前端工具,外加这一组自己的 system prompt。
9
+ *
10
+ * 工具定义只写「这是什么、入参是什么」,行为规则一律放在 guidance 里:
11
+ * 启用一组工具,就同时启用它的工具和它的 prompt,两者不会各说各的。
12
+ */
13
+ export interface CallerToolGroup {
14
+ id: string;
15
+ tools: CallerToolDefinition[];
16
+ /** 这一组注入 system prompt 的说明;空字符串表示只提供工具、不注入。 */
17
+ guidance: string;
18
+ }
19
+ export declare const CALLER_TOOL_GROUPS: CallerToolGroup[];
20
+ /** 启用所有组时要下发的工具。 */
21
+ export declare const CALLER_TOOLS: CallerToolDefinition[];
22
+ /** 把各组的 prompt 拼成一段,交给对话协议的 ToolGuidance。 */
23
+ export declare function composeCallerToolGuidance(groups?: readonly CallerToolGroup[]): string;
24
+ export declare const CALLER_TOOL_GUIDANCE: string;
68
25
  //# sourceMappingURL=callerTools.d.ts.map