@stigmer/client 0.3.1 → 0.4.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.
Files changed (58) hide show
  1. package/custom-tools.d.ts +40 -0
  2. package/custom-tools.d.ts.map +1 -0
  3. package/custom-tools.js +29 -0
  4. package/custom-tools.js.map +1 -0
  5. package/gen/client.d.ts +1 -1
  6. package/gen/client.d.ts.map +1 -1
  7. package/gen/plugin.d.ts +3 -1
  8. package/gen/plugin.d.ts.map +1 -1
  9. package/gen/plugin.js +16 -0
  10. package/gen/plugin.js.map +1 -1
  11. package/gen/run.d.ts +7 -0
  12. package/gen/run.d.ts.map +1 -1
  13. package/gen/run.js +18 -1
  14. package/gen/run.js.map +1 -1
  15. package/gen/session.d.ts +10 -2
  16. package/gen/session.d.ts.map +1 -1
  17. package/gen/session.js +26 -1
  18. package/gen/session.js.map +1 -1
  19. package/gen/skill.d.ts +3 -1
  20. package/gen/skill.d.ts.map +1 -1
  21. package/gen/skill.js +16 -0
  22. package/gen/skill.js.map +1 -1
  23. package/index.d.ts +3 -2
  24. package/index.d.ts.map +1 -1
  25. package/index.js +2 -1
  26. package/index.js.map +1 -1
  27. package/package.json +3 -3
  28. package/run/step-words.d.ts +13 -0
  29. package/run/step-words.d.ts.map +1 -1
  30. package/run/step-words.js +15 -0
  31. package/run/step-words.js.map +1 -1
  32. package/run/tool-view.d.ts +13 -4
  33. package/run/tool-view.d.ts.map +1 -1
  34. package/run/tool-view.js +11 -2
  35. package/run/tool-view.js.map +1 -1
  36. package/run/transcript.d.ts.map +1 -1
  37. package/run/transcript.js +1 -0
  38. package/run/transcript.js.map +1 -1
  39. package/run/turn-activity.d.ts +6 -1
  40. package/run/turn-activity.d.ts.map +1 -1
  41. package/run/turn-activity.js +7 -2
  42. package/run/turn-activity.js.map +1 -1
  43. package/session-events.d.ts +20 -9
  44. package/session-events.d.ts.map +1 -1
  45. package/session-events.js +12 -7
  46. package/session-events.js.map +1 -1
  47. package/src/custom-tools.ts +43 -0
  48. package/src/gen/client.ts +1 -1
  49. package/src/gen/plugin.ts +13 -1
  50. package/src/gen/run.ts +27 -1
  51. package/src/gen/session.ts +36 -3
  52. package/src/gen/skill.ts +13 -1
  53. package/src/index.ts +3 -0
  54. package/src/run/step-words.ts +16 -0
  55. package/src/run/tool-view.ts +11 -4
  56. package/src/run/transcript.ts +1 -0
  57. package/src/run/turn-activity.ts +8 -2
  58. package/src/session-events.ts +22 -10
package/src/gen/run.ts CHANGED
@@ -16,7 +16,7 @@ import { RunQueryController } from "@stigmer/apis/ai/stigmer/agentic/run/v1/quer
16
16
  import { RunSpecSchema, ConversationCatchupSchema, type ConversationCatchup } from "@stigmer/apis/ai/stigmer/agentic/run/v1/spec_pb";
17
17
  import { Harness, ExecutionTarget, GitWriteBackMode } from "@stigmer/apis/ai/stigmer/agentic/session/v1/enum_pb";
18
18
  import { FileResourceSchema, GitRepositoryResourceSchema, LocalPathResourceSchema, SessionResourceSchema, type FileResource, type GitRepositoryResource, type LocalPathResource, type SessionResource } from "@stigmer/apis/ai/stigmer/agentic/session/v1/resource_pb";
19
- import { SessionSpecSchema, type SessionSpec } from "@stigmer/apis/ai/stigmer/agentic/session/v1/spec_pb";
19
+ import { CustomToolSchema, SessionSpecSchema, type CustomTool, type SessionSpec } from "@stigmer/apis/ai/stigmer/agentic/session/v1/spec_pb";
20
20
  import { ApiResourceVisibility } from "@stigmer/apis/ai/stigmer/commons/apiresource/enum_pb";
21
21
  import { ApiResourceIdSchema, ApiResourceReferenceSchema } from "@stigmer/apis/ai/stigmer/commons/apiresource/io_pb";
22
22
  import { ApiResourceMetadataSchema } from "@stigmer/apis/ai/stigmer/commons/apiresource/metadata_pb";
@@ -243,6 +243,7 @@ export interface SessionSpecInput {
243
243
  fileReview?: boolean;
244
244
  environmentRef?: ResourceRef;
245
245
  resources?: SessionResourceInput[];
246
+ customTools?: CustomToolInput[];
246
247
  }
247
248
 
248
249
  /** SDK input type for SessionResource. */
@@ -273,6 +274,13 @@ export interface LocalPathResourceInput {
273
274
  path?: string;
274
275
  }
275
276
 
277
+ /** SDK input type for CustomTool. */
278
+ export interface CustomToolInput {
279
+ name?: string;
280
+ description?: string;
281
+ inputSchema: JsonObject;
282
+ }
283
+
276
284
  /** SDK input type for RunConfig. */
277
285
  export interface RunConfigInput {
278
286
  modelName?: string;
@@ -377,6 +385,14 @@ function buildSessionResourceProto(input: SessionResourceInput) {
377
385
  return msg;
378
386
  }
379
387
 
388
+ function buildCustomToolProto(input: CustomToolInput) {
389
+ return Object.assign(create(CustomToolSchema), stripUndefined({
390
+ name: input.name,
391
+ description: input.description,
392
+ inputSchema: input.inputSchema,
393
+ }));
394
+ }
395
+
380
396
  function buildSessionSpecProto(input: SessionSpecInput) {
381
397
  const msg = create(SessionSpecSchema);
382
398
  if (input.agentRef?.slug || input.agentRef?.org || input.agentRef?.id) msg.agentRef = create(ApiResourceReferenceSchema, { ...input.agentRef, kind: 40 });
@@ -391,6 +407,7 @@ function buildSessionSpecProto(input: SessionSpecInput) {
391
407
  if (input.fileReview !== undefined) msg.fileReview = input.fileReview;
392
408
  if (input.environmentRef?.slug || input.environmentRef?.org || input.environmentRef?.id) msg.environmentRef = create(ApiResourceReferenceSchema, { ...input.environmentRef, kind: 67 });
393
409
  if (input.resources) msg.resources = input.resources.map(buildSessionResourceProto);
410
+ if (input.customTools) msg.customTools = input.customTools.map(buildCustomToolProto);
394
411
  return msg;
395
412
  }
396
413
 
@@ -547,6 +564,14 @@ function toSessionResourceInput(msg: SessionResource): SessionResourceInput {
547
564
  };
548
565
  }
549
566
 
567
+ function toCustomToolInput(msg: CustomTool): CustomToolInput {
568
+ return {
569
+ name: msg.name || undefined,
570
+ description: msg.description || undefined,
571
+ inputSchema: msg.inputSchema ?? {},
572
+ };
573
+ }
574
+
550
575
  function toSessionSpecInput(msg: SessionSpec): SessionSpecInput {
551
576
  return {
552
577
  agentRef: toResourceRefInput(msg.agentRef),
@@ -561,6 +586,7 @@ function toSessionSpecInput(msg: SessionSpec): SessionSpecInput {
561
586
  fileReview: msg.fileReview || undefined,
562
587
  environmentRef: toResourceRefInput(msg.environmentRef),
563
588
  resources: msg.resources?.length ? msg.resources.map(toSessionResourceInput) : undefined,
589
+ customTools: msg.customTools?.length ? msg.customTools.map(toCustomToolInput) : undefined,
564
590
  };
565
591
  }
566
592
 
@@ -3,16 +3,16 @@
3
3
  import { wrapError } from "./errors.js";
4
4
  import { stripUndefined, toResourceRefInput, toResourceRefInputs } from "./proto-utils.js";
5
5
  import { type ResourceRef } from "./types.js";
6
- import { create, type MessageInitShape } from "@bufbuild/protobuf";
6
+ import { create, type MessageInitShape, type JsonObject } from "@bufbuild/protobuf";
7
7
  import { createClient, type Client, type Transport } from "@connectrpc/connect";
8
8
  import { SessionSchema, type Session } from "@stigmer/apis/ai/stigmer/agentic/session/v1/api_pb";
9
9
  import { SessionCommandController } from "@stigmer/apis/ai/stigmer/agentic/session/v1/command_pb";
10
10
  import { Harness, ExecutionTarget, GitWriteBackMode } from "@stigmer/apis/ai/stigmer/agentic/session/v1/enum_pb";
11
11
  import { SessionEventSchema, type SessionEvent } from "@stigmer/apis/ai/stigmer/agentic/session/v1/event_pb";
12
- import { SessionIdSchema, UpdateSessionInputSchema, UpdateSessionSubjectRequestSchema, ReviewFileChangesInputSchema, ReviewFileChangesResponseSchema, ConfirmToolUseInputSchema, GrantPermissionInputSchema, GrantPermissionResponseSchema, StopBackgroundCommandInputSchema, InterruptSessionInputSchema, InterruptSessionResponseSchema, ListSessionsRequestSchema, SessionListSchema, ListSessionsByAgentRequestSchema, ListSessionsByChannelRequestSchema, ListSessionEventsRequestSchema, SessionEventListSchema, StreamSessionEventsRequestSchema, StreamSessionEventsResponseSchema, StreamAttentionRequestSchema, AttentionSchema, type UpdateSessionSubjectRequest, type ReviewFileChangesInput, type ReviewFileChangesResponse, type ConfirmToolUseInput, type GrantPermissionInput, type GrantPermissionResponse, type StopBackgroundCommandInput, type InterruptSessionInput, type InterruptSessionResponse, type ListSessionsRequest, type SessionList, type ListSessionsByAgentRequest, type ListSessionsByChannelRequest, type ListSessionEventsRequest, type SessionEventList, type StreamSessionEventsRequest, type StreamSessionEventsResponse, type StreamAttentionRequest, type Attention } from "@stigmer/apis/ai/stigmer/agentic/session/v1/io_pb";
12
+ import { SessionIdSchema, UpdateSessionInputSchema, UpdateSessionSubjectRequestSchema, ReviewFileChangesInputSchema, ReviewFileChangesResponseSchema, ConfirmToolUseInputSchema, AnswerCustomToolUseInputSchema, GrantPermissionInputSchema, GrantPermissionResponseSchema, StopBackgroundCommandInputSchema, InterruptSessionInputSchema, InterruptSessionResponseSchema, ListSessionsRequestSchema, SessionListSchema, ListSessionsByAgentRequestSchema, ListSessionsByChannelRequestSchema, ListSessionEventsRequestSchema, SessionEventListSchema, StreamSessionEventsRequestSchema, StreamSessionEventsResponseSchema, StreamAttentionRequestSchema, AttentionSchema, type UpdateSessionSubjectRequest, type ReviewFileChangesInput, type ReviewFileChangesResponse, type ConfirmToolUseInput, type AnswerCustomToolUseInput, type GrantPermissionInput, type GrantPermissionResponse, type StopBackgroundCommandInput, type InterruptSessionInput, type InterruptSessionResponse, type ListSessionsRequest, type SessionList, type ListSessionsByAgentRequest, type ListSessionsByChannelRequest, type ListSessionEventsRequest, type SessionEventList, type StreamSessionEventsRequest, type StreamSessionEventsResponse, type StreamAttentionRequest, type Attention } from "@stigmer/apis/ai/stigmer/agentic/session/v1/io_pb";
13
13
  import { SessionQueryController } from "@stigmer/apis/ai/stigmer/agentic/session/v1/query_pb";
14
14
  import { FileResourceSchema, GitRepositoryResourceSchema, LocalPathResourceSchema, SessionResourceSchema, type FileResource, type GitRepositoryResource, type LocalPathResource, type SessionResource } from "@stigmer/apis/ai/stigmer/agentic/session/v1/resource_pb";
15
- import { SessionSpecSchema } from "@stigmer/apis/ai/stigmer/agentic/session/v1/spec_pb";
15
+ import { SessionSpecSchema, CustomToolSchema, type CustomTool } from "@stigmer/apis/ai/stigmer/agentic/session/v1/spec_pb";
16
16
  import { ApiResourceVisibility } from "@stigmer/apis/ai/stigmer/commons/apiresource/enum_pb";
17
17
  import { ApiResourceReferenceSchema } from "@stigmer/apis/ai/stigmer/commons/apiresource/io_pb";
18
18
  import { ApiResourceMetadataSchema } from "@stigmer/apis/ai/stigmer/commons/apiresource/metadata_pb";
@@ -63,6 +63,12 @@ export class SessionClient {
63
63
  } catch (e) { throw wrapError(e); }
64
64
  }
65
65
 
66
+ async answerCustomToolUse(input: MessageInitShape<typeof AnswerCustomToolUseInputSchema>): Promise<SessionEvent> {
67
+ try {
68
+ return await this.command.answerCustomToolUse(input);
69
+ } catch (e) { throw wrapError(e); }
70
+ }
71
+
66
72
  async grantPermission(input: MessageInitShape<typeof GrantPermissionInputSchema>): Promise<GrantPermissionResponse> {
67
73
  try {
68
74
  return await this.command.grantPermission(input);
@@ -202,6 +208,7 @@ export interface SessionInput {
202
208
  fileReview?: boolean;
203
209
  environmentRef?: ResourceRef;
204
210
  resources?: SessionResourceInput[];
211
+ customTools?: CustomToolInput[];
205
212
  }
206
213
 
207
214
  /** SDK input type for SessionResource. */
@@ -232,6 +239,13 @@ export interface LocalPathResourceInput {
232
239
  path?: string;
233
240
  }
234
241
 
242
+ /** SDK input type for CustomTool. */
243
+ export interface CustomToolInput {
244
+ name?: string;
245
+ description?: string;
246
+ inputSchema: JsonObject;
247
+ }
248
+
235
249
  function buildFileResourceProto(input: FileResourceInput) {
236
250
  return Object.assign(create(FileResourceSchema), stripUndefined({
237
251
  fileId: input.fileId,
@@ -268,6 +282,14 @@ function buildSessionResourceProto(input: SessionResourceInput) {
268
282
  return msg;
269
283
  }
270
284
 
285
+ function buildCustomToolProto(input: CustomToolInput) {
286
+ return Object.assign(create(CustomToolSchema), stripUndefined({
287
+ name: input.name,
288
+ description: input.description,
289
+ inputSchema: input.inputSchema,
290
+ }));
291
+ }
292
+
271
293
  export function buildSessionProto(input: SessionInput): Session {
272
294
  const agentRef = (input.agentRef?.slug || input.agentRef?.org || input.agentRef?.id) ? create(ApiResourceReferenceSchema, { ...input.agentRef, kind: 40 }) : undefined;
273
295
  const skillRefs = input.skillRefs?.map(r => create(ApiResourceReferenceSchema, { ...r, kind: 43 }));
@@ -275,6 +297,7 @@ export function buildSessionProto(input: SessionInput): Session {
275
297
  const plugins = input.plugins?.map(r => create(ApiResourceReferenceSchema, { ...r, kind: 58 }));
276
298
  const environmentRef = (input.environmentRef?.slug || input.environmentRef?.org || input.environmentRef?.id) ? create(ApiResourceReferenceSchema, { ...input.environmentRef, kind: 67 }) : undefined;
277
299
  const resources = input.resources?.map(buildSessionResourceProto);
300
+ const customTools = input.customTools?.map(buildCustomToolProto);
278
301
  return Object.assign(create(SessionSchema), {
279
302
  apiVersion: "agentic.stigmer.ai/v1",
280
303
  kind: "Session",
@@ -299,6 +322,7 @@ export function buildSessionProto(input: SessionInput): Session {
299
322
  fileReview: input.fileReview,
300
323
  environmentRef,
301
324
  resources,
325
+ customTools,
302
326
  })),
303
327
  }) as Session;
304
328
  }
@@ -335,6 +359,14 @@ function toSessionResourceInput(msg: SessionResource): SessionResourceInput {
335
359
  };
336
360
  }
337
361
 
362
+ function toCustomToolInput(msg: CustomTool): CustomToolInput {
363
+ return {
364
+ name: msg.name || undefined,
365
+ description: msg.description || undefined,
366
+ inputSchema: msg.inputSchema ?? {},
367
+ };
368
+ }
369
+
338
370
  /**
339
371
  * Maps a fetched {@link Session} to the complete {@link SessionInput} that
340
372
  * restates it, for copying it into a new resource:
@@ -370,5 +402,6 @@ export function toSessionInput(resource: Session): SessionInput {
370
402
  fileReview: spec.fileReview || undefined,
371
403
  environmentRef: toResourceRefInput(spec.environmentRef),
372
404
  resources: spec.resources?.length ? spec.resources.map(toSessionResourceInput) : undefined,
405
+ customTools: spec.customTools?.length ? spec.customTools.map(toCustomToolInput) : undefined,
373
406
  };
374
407
  }
package/src/gen/skill.ts CHANGED
@@ -7,7 +7,7 @@ import { create, type MessageInitShape } from "@bufbuild/protobuf";
7
7
  import { createClient, type Client, type Transport } from "@connectrpc/connect";
8
8
  import { SkillSchema, type Skill } from "@stigmer/apis/ai/stigmer/agentic/skill/v1/api_pb";
9
9
  import { SkillCommandController } from "@stigmer/apis/ai/stigmer/agentic/skill/v1/command_pb";
10
- import { SkillIdSchema, PushSkillRequestSchema, CreateSkillArtifactUploadUrlRequestSchema, SkillArtifactUploadUrlSchema, PushSkillFromFileRequestSchema, ListSkillsRequestSchema, SkillListSchema, GetArtifactRequestSchema, GetArtifactResponseSchema, SkillArtifactDownloadUrlSchema, ListSkillVersionsInputSchema, ListSkillVersionsResponseSchema, type PushSkillRequest, type CreateSkillArtifactUploadUrlRequest, type SkillArtifactUploadUrl, type PushSkillFromFileRequest, type ListSkillsRequest, type SkillList, type GetArtifactRequest, type GetArtifactResponse, type SkillArtifactDownloadUrl, type ListSkillVersionsInput, type ListSkillVersionsResponse } from "@stigmer/apis/ai/stigmer/agentic/skill/v1/io_pb";
10
+ import { SkillIdSchema, PushSkillRequestSchema, CreateSkillArtifactUploadUrlRequestSchema, SkillArtifactUploadUrlSchema, PushSkillFromFileRequestSchema, ListSkillsRequestSchema, SkillListSchema, GetArtifactRequestSchema, GetArtifactResponseSchema, SkillArtifactDownloadUrlSchema, ListSkillFilesInputSchema, SkillFileListSchema, ReadSkillFileInputSchema, SkillFileContentSchema, ListSkillVersionsInputSchema, ListSkillVersionsResponseSchema, type PushSkillRequest, type CreateSkillArtifactUploadUrlRequest, type SkillArtifactUploadUrl, type PushSkillFromFileRequest, type ListSkillsRequest, type SkillList, type GetArtifactRequest, type GetArtifactResponse, type SkillArtifactDownloadUrl, type ListSkillFilesInput, type SkillFileList, type ReadSkillFileInput, type SkillFileContent, type ListSkillVersionsInput, type ListSkillVersionsResponse } from "@stigmer/apis/ai/stigmer/agentic/skill/v1/io_pb";
11
11
  import { SkillQueryController } from "@stigmer/apis/ai/stigmer/agentic/skill/v1/query_pb";
12
12
  import { SkillSpecSchema } from "@stigmer/apis/ai/stigmer/agentic/skill/v1/spec_pb";
13
13
  import { ApiResourceKind } from "@stigmer/apis/ai/stigmer/commons/apiresource/apiresourcekind/api_resource_kind_pb";
@@ -99,6 +99,18 @@ export class SkillClient {
99
99
  } catch (e) { throw wrapError(e); }
100
100
  }
101
101
 
102
+ async listFiles(input: MessageInitShape<typeof ListSkillFilesInputSchema>): Promise<SkillFileList> {
103
+ try {
104
+ return await this.query.listFiles(input);
105
+ } catch (e) { throw wrapError(e); }
106
+ }
107
+
108
+ async readFile(input: MessageInitShape<typeof ReadSkillFileInputSchema>): Promise<SkillFileContent> {
109
+ try {
110
+ return await this.query.readFile(input);
111
+ } catch (e) { throw wrapError(e); }
112
+ }
113
+
102
114
  async listVersions(input: MessageInitShape<typeof ListSkillVersionsInputSchema>): Promise<ListSkillVersionsResponse> {
103
115
  try {
104
116
  return await this.query.listVersions(input);
package/src/index.ts CHANGED
@@ -406,7 +406,9 @@ export {
406
406
  type FileResourceInput,
407
407
  type GitRepositoryResourceInput,
408
408
  type LocalPathResourceInput,
409
+ type CustomToolInput,
409
410
  } from "./gen/session.js";
411
+ export { defineCustomTool, type CustomToolDefinition } from "./custom-tools.js";
410
412
 
411
413
  // Session utilities (hand-written)
412
414
  export {
@@ -468,6 +470,7 @@ export {
468
470
  searchCountWords,
469
471
  stepPhrase,
470
472
  stepTense,
473
+ awaitsAnswer,
471
474
  type StepPhrase,
472
475
  type StepPhraseOptions,
473
476
  type StepTense,
@@ -162,6 +162,22 @@ export function targetOf(tool: Pick<ToolUse, "name" | "mcpServerName" | "input">
162
162
  }
163
163
  }
164
164
 
165
+ /**
166
+ * Whether `tool` waits on someone's answer: a person's approval
167
+ * (`waiting`) or the app's answer to a call of its own tool
168
+ * (`waiting_on_host`). A waiting call is open, never settled, whoever it
169
+ * waits on; only an approval offers a decision.
170
+ *
171
+ * @example
172
+ * ```ts
173
+ * awaitsAnswer({ state: "waiting_on_host" }); // true
174
+ * awaitsAnswer({ state: "completed" }); // false
175
+ * ```
176
+ */
177
+ export function awaitsAnswer(tool: Pick<ToolUse, "state">): boolean {
178
+ return tool.state === "waiting" || tool.state === "waiting_on_host";
179
+ }
180
+
165
181
  /**
166
182
  * How `tool` stands: open, returned, failed (an error result, a denial, or a
167
183
  * command that exited non-zero), or stopped before it returned. A background
@@ -235,9 +235,12 @@ const NAME_TO_KIND: ReadonlyMap<string, ToolKind> = new Map<string, ToolKind>([
235
235
  /**
236
236
  * Resolves the harness-agnostic kind of a tool use, from its name and MCP
237
237
  * server ({@link resolveToolKindByName}). An unknown name with an MCP
238
- * server is an MCP tool.
238
+ * server is an MCP tool. A call of the app's own tools (`custom`) is always
239
+ * `unknown`: its name is the app's, and one that reads like a built-in's
240
+ * (`search`, `shell`) never takes the built-in's words or look.
239
241
  */
240
- export function resolveToolKind(tool: Pick<ToolUse, "name" | "mcpServerName">): ToolKind {
242
+ export function resolveToolKind(tool: Pick<ToolUse, "name" | "mcpServerName"> & { readonly custom?: boolean }): ToolKind {
243
+ if (tool.custom === true) return "unknown";
241
244
  return resolveToolKindByName(tool.name, tool.mcpServerName);
242
245
  }
243
246
 
@@ -276,7 +279,9 @@ export function resolveToolKindByName(name: string, mcpServerSlug?: string): Too
276
279
  * `undefined` for a call that has none. A connected server's tool is
277
280
  * `mcp__<server>__<tool>`: the name the agent's tool list, hooks and the
278
281
  * console show, and the key a host registers its own card under
279
- * (`toolCards` in `@stigmer/react-sdk`). Built-in tools, the memory
282
+ * (`toolCards` in `@stigmer/react-sdk`). A call of one of the host app's
283
+ * own tools (`custom`, the session's `custom_tools`) is the name the host
284
+ * declared it under, whatever it reads like. Built-in tools, the memory
280
285
  * attachment's tools and a server tool named like a built-in resolve to
281
286
  * their own kinds ({@link resolveToolKind}), are drawn by the kit, and have
282
287
  * none.
@@ -291,9 +296,11 @@ export function resolveToolKindByName(name: string, mcpServerSlug?: string): Too
291
296
  * toolPublicName({ name: "create_invoice", mcpServerName: "billing" });
292
297
  * // "mcp__billing__create_invoice"
293
298
  * toolPublicName({ name: "Edit", mcpServerName: "" }); // undefined
299
+ * toolPublicName({ name: "show_form", mcpServerName: "", custom: true }); // "show_form"
294
300
  * ```
295
301
  */
296
- export function toolPublicName(tool: Pick<ToolUse, "name" | "mcpServerName">): string | undefined {
302
+ export function toolPublicName(tool: Pick<ToolUse, "name" | "mcpServerName"> & { readonly custom?: boolean }): string | undefined {
303
+ if (tool.custom === true) return tool.name;
297
304
  if (resolveToolKind(tool) !== "mcp") return undefined;
298
305
  return `mcp__${tool.mcpServerName}__${tool.name}`;
299
306
  }
@@ -643,6 +643,7 @@ function toolOutputText(
643
643
  const TOOL_STATE_LABELS: Readonly<Record<ToolUse["state"], string>> = {
644
644
  running: "running",
645
645
  waiting: "waiting for approval",
646
+ waiting_on_host: "waiting for the app",
646
647
  completed: "completed",
647
648
  failed: "failed",
648
649
  denied: "denied",
@@ -6,7 +6,8 @@
6
6
  // It reads only what a session's events fold into a turn
7
7
  // (@stigmer/session-log): the open tool calls and their kinds
8
8
  // (`resolveToolKind`, so the Stigmer harness's `execute` and the Claude
9
- // harness's `Bash` read alike), the asks waiting on a person, a message or
9
+ // harness's `Bash` read alike), the asks waiting on a person, the calls of
10
+ // the app's own tools waiting on the app, a message or
10
11
  // thinking still streaming, and the to-do list.
11
12
  // It returns structure, never prose; `activityPhrase` beside it gives the
12
13
  // present-tense words, so a surface may lay the parts out as it likes. The
@@ -41,6 +42,8 @@ export type TurnActivity =
41
42
  | { readonly kind: "tool"; readonly toolKind: ToolKind; readonly target: string; readonly toolUseId: string }
42
43
  /** A question or approval waits for the person; `count` of them. */
43
44
  | { readonly kind: "waiting_for_you"; readonly count: number }
45
+ /** A call of the app's own tools waits for the app's answer; `count` of them. */
46
+ | { readonly kind: "waiting_for_app"; readonly count: number }
44
47
  /** The agent's reply is streaming. */
45
48
  | { readonly kind: "writing" }
46
49
  /** The agent is thinking (its thinking is streaming). */
@@ -103,6 +106,7 @@ function activityOf(turn: Turn, open: readonly ToolUse[]): TurnActivity {
103
106
  const sandboxWait = turn.liveness?.awaitingSandboxMs;
104
107
  if (sandboxWait !== undefined && !turn.ended) return { kind: "waiting_for_sandbox", waitedMs: sandboxWait };
105
108
  if (turn.asks.length > 0) return { kind: "waiting_for_you", count: turn.asks.length };
109
+ if (turn.customToolUses.length > 0) return { kind: "waiting_for_app", count: turn.customToolUses.length };
106
110
  const last = turn.items.at(-1);
107
111
  if (last?.kind === "message" && last.live) return { kind: "writing" };
108
112
  if (last?.kind === "thinking" && last.live) return { kind: "thinking" };
@@ -128,13 +132,15 @@ function todoProgress(turn: Turn): TodoProgress | undefined {
128
132
 
129
133
  /**
130
134
  * The activity in present-tense words: "Editing invoice.ts", "Running a
131
- * command", "Waiting for you", "Waiting for a sandbox". A kind's words name the work, whichever
135
+ * command", "Waiting for you", "Waiting for the app", "Waiting for a sandbox". A kind's words name the work, whichever
132
136
  * harness ran it; a target the input did not name leaves the generic words.
133
137
  */
134
138
  export function activityPhrase(activity: TurnActivity): string {
135
139
  switch (activity.kind) {
136
140
  case "waiting_for_you":
137
141
  return "Waiting for you";
142
+ case "waiting_for_app":
143
+ return "Waiting for the app";
138
144
  case "writing":
139
145
  return "Writing the answer";
140
146
  case "thinking":
@@ -18,8 +18,10 @@
18
18
  * off for the rest of the follow.
19
19
  * - {@link sendAndWait} starts a turn (`run.create`, as every turn
20
20
  * starts) and follows the session until that turn's
21
- * `stigmer.run.status` says it ended, or it waits for a person's answer
22
- * (the session idles with `requires_action` naming its tool uses). It
21
+ * `stigmer.run.status` says it ended, or it waits for an answer (the
22
+ * session idles with `requires_action` naming its tool uses): a
23
+ * person's approval of an ask, or the host app's answer to a call of
24
+ * one of its own tools (the session's `custom_tools`). It
23
25
  * returns the turn's answer, structured output and how it ended;
24
26
  * {@link waitForTurn} resumes the wait after the caller answered. Its two
25
27
  * halves are exported for a caller that follows the turn its own way (a
@@ -267,8 +269,9 @@ export interface TurnOutcome {
267
269
  readonly sessionId: string;
268
270
  /**
269
271
  * The turn's phase: one that ends it (completed, failed, cancelled,
270
- * terminated), or `waiting` when it waits for a person's answer (see
271
- * {@link asks}). The wait returns on nothing else.
272
+ * terminated), or `waiting` when it waits for an answer (see
273
+ * {@link asks} and {@link customToolUses}). The wait returns on nothing
274
+ * else.
272
275
  */
273
276
  readonly phase: TurnPhase;
274
277
  /** The text of the turn's last message on its primary thread; "" when it wrote none. */
@@ -280,8 +283,14 @@ export interface TurnOutcome {
280
283
  readonly stopDetail?: TurnStopDetail;
281
284
  /** What went wrong, when it failed or was stopped with a reason. */
282
285
  readonly error: string;
283
- /** The tool uses that wait for an answer, when `phase` is waiting. */
286
+ /** The tool uses that wait for a person's approval, when `phase` is waiting: answer each with `confirmToolUse`. */
284
287
  readonly asks: ReadonlyArray<ToolUse>;
288
+ /**
289
+ * The calls of the host app's own tools that wait for its answer, when
290
+ * `phase` is waiting: answer each with `answerCustomToolUse`, never with
291
+ * an approval.
292
+ */
293
+ readonly customToolUses: ReadonlyArray<ToolUse>;
285
294
  /** The whole turn, folded. */
286
295
  readonly turn: Turn;
287
296
  /** The log's place when the wait returned: pass it to {@link waitForTurn} to resume. */
@@ -299,8 +308,9 @@ export interface WaitOptions {
299
308
  /**
300
309
  * Waits for one turn of a session: until its status says it ended, or it
301
310
  * waits for an answer. Answer each of {@link TurnOutcome.asks} (the
302
- * session's `confirmToolUse` or `grantPermission`), then call it again
303
- * with the outcome's `lastSeq`.
311
+ * session's `confirmToolUse` or `grantPermission`) and each of
312
+ * {@link TurnOutcome.customToolUses} (`answerCustomToolUse`), then call it
313
+ * again with the outcome's `lastSeq`.
304
314
  */
305
315
  export async function waitForTurn(
306
316
  client: SessionEventsClient,
@@ -360,8 +370,9 @@ export interface TurnPlace {
360
370
  /**
361
371
  * The outcome of a folded turn: its answer, output and how it stands. Its
362
372
  * phase is the status's once the turn ended, `waiting` when `waiting` says
363
- * the session waits on its asks, and otherwise the phase it reports now
364
- * (`pending` before its first status); its asks are empty once it ended.
373
+ * the session waits on its asks or custom tool uses, and otherwise the
374
+ * phase it reports now (`pending` before its first status); its asks and
375
+ * custom tool uses are empty once it ended.
365
376
  */
366
377
  export function turnOutcomeOf(turn: Turn, place: TurnPlace, lastSeq: bigint, waiting = false): TurnOutcome {
367
378
  const ended = turn.status !== undefined && turn.ended;
@@ -374,6 +385,7 @@ export function turnOutcomeOf(turn: Turn, place: TurnPlace, lastSeq: bigint, wai
374
385
  ...(ended && turn.status?.stopDetail !== undefined ? { stopDetail: turn.status.stopDetail } : {}),
375
386
  error: turn.status?.error ?? "",
376
387
  asks: ended ? [] : turn.asks,
388
+ customToolUses: ended ? [] : turn.customToolUses,
377
389
  turn,
378
390
  lastSeq,
379
391
  };
@@ -421,7 +433,7 @@ async function waitIn(
421
433
  const waiting =
422
434
  fold.status.state === "idle" &&
423
435
  fold.status.stopReason === "requires_action" &&
424
- turn.asks.some((ask) => fold.status.waitingOn.includes(ask.id));
436
+ [...turn.asks, ...turn.customToolUses].some((call) => fold.status.waitingOn.includes(call.id));
425
437
  if (ended || waiting) {
426
438
  return turnOutcomeOf(turn, { run, runId, sessionId }, fold.lastSeq, waiting);
427
439
  }