@asterism-app/builtin-api 0.25.2 → 0.26.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.
- package/docs/agents.md +8 -0
- package/package.json +1 -1
- package/src/agent-services.ts +3 -5
- package/src/peek-renderer.ts +51 -0
- package/src/peek.ts +35 -5
- package/src/renderer.ts +2 -0
- package/src/tools.ts +4 -3
package/docs/agents.md
CHANGED
|
@@ -67,6 +67,14 @@ For cross-session messaging, obtain the target session executor and submit throu
|
|
|
67
67
|
|
|
68
68
|
Mesh messages retain their internal sender attribution in history. Model projection uses the channel name, Agent name, and numeric disambiguator; a sender not exposed to the channel is marked as not visible. Communication resources own their member directory and task descriptions. Resolve targets against the request's captured access scope. Read current task descriptions when handling an operation; identity resolution and mutable profile text have separate lifetimes.
|
|
69
69
|
|
|
70
|
+
## Investigate a conversation
|
|
71
|
+
|
|
72
|
+
Peek uses the configured utility model to explain an Agent's saved records. Backend plugins obtain a client with `agentServices(plugin).peek(target)` after resolving an authorized Agent reference. Renderer contributions bind `createPeekClient(object)` to their displayed Agent. Both clients offer `run(input, { signal, onProgress })` for a final outcome and `stream(input, { signal })` for progress followed by a terminal result.
|
|
73
|
+
|
|
74
|
+
Supply a `question` and optionally `includeThinking` to admit saved readable thinking. Each call captures fresh evidence from the target's current timeline and keeps that snapshot fixed throughout its retrieval rounds. Progress contains a complete report snapshot, which replaces the previous report rather than appending to it. The final outcome distinguishes success, partial output, cancellation, and failure. Breaking out of a stream cancels its investigation.
|
|
75
|
+
|
|
76
|
+
For follow-ups, pass `history` containing earlier questions, reports, and their outcomes. This context belongs to the caller and is separate from the target's saved records. Keep incomplete reports marked with their actual outcome. The service does not retain conversations or write investigation exchanges to the target. Single-call tools, including Mesh Peek, supply no history; a conversational interface owns its temporary history and passes it explicitly on each call.
|
|
77
|
+
|
|
70
78
|
## Prepare incoming input
|
|
71
79
|
|
|
72
80
|
An external preparer can inspect, replace, or reject any of the three message sources using the original built-in action contract. Its replacement supplies raw action input that will be parsed again. Preparation applies to idle input, queued steering and follow-ups, and Home's initial input. It runs before acceptance, including on retries, so it is not an acceptance notification. Preparation has read capabilities and does not commit session mutations.
|
package/package.json
CHANGED
package/src/agent-services.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import type { z } from "zod";
|
|
2
1
|
import type { ResourceRef, SessionDirectory } from "@asterism-app/sdk/contracts";
|
|
3
|
-
import { PluginApiError, type
|
|
4
|
-
import type {
|
|
2
|
+
import { PluginApiError, type PluginContext } from "@asterism-app/sdk/runtime";
|
|
3
|
+
import type { PeekClient } from "./peek.ts";
|
|
5
4
|
|
|
6
5
|
/** Agent-owned operations for trusted plugins that have resolved an authorized resource reference. */
|
|
7
6
|
export interface AgentServices {
|
|
8
7
|
describe(target: ResourceRef): { type: string };
|
|
9
|
-
peek(target: ResourceRef
|
|
10
|
-
publish: (data: PeekResult) => void): Promise<CallResult<PeekResult>>;
|
|
8
|
+
peek(target: ResourceRef): PeekClient;
|
|
11
9
|
}
|
|
12
10
|
const services = new WeakMap<SessionDirectory, AgentServices>();
|
|
13
11
|
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { RendererObjectContext } from "@asterism-app/sdk/renderer";
|
|
2
|
+
import { PeekChannel, type PeekClient, type PeekEvent, type PeekResult } from "./peek.ts";
|
|
3
|
+
|
|
4
|
+
/** Binds Peek to the displayed Agent. Stream completion carries the outcome; early iterator exit closes the channel. */
|
|
5
|
+
export function createPeekClient(object: Pick<RendererObjectContext, "openChannel">): PeekClient {
|
|
6
|
+
const stream: PeekClient["stream"] = async function* (input, { signal }) {
|
|
7
|
+
signal.throwIfAborted();
|
|
8
|
+
const channel = object.openChannel(PeekChannel);
|
|
9
|
+
const abort = () => channel.close();
|
|
10
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
11
|
+
let completed = false;
|
|
12
|
+
let progress: PeekResult | undefined;
|
|
13
|
+
const reader = new ReadableStream<PeekEvent>({
|
|
14
|
+
start(output) {
|
|
15
|
+
channel.onMessage(event => {
|
|
16
|
+
output.enqueue(event);
|
|
17
|
+
if (event.type === "result") completed = true;
|
|
18
|
+
else progress = event.data;
|
|
19
|
+
});
|
|
20
|
+
void channel.closed.then(end => {
|
|
21
|
+
if (!completed) output.enqueue({ type: "result", result: signal.aborted
|
|
22
|
+
? { kind: "cancelled", data: progress, message: "The investigation was cancelled." }
|
|
23
|
+
: { kind: "failed", data: progress, error: { code: "peek_channel_closed", message: end.message ?? `Peek channel ended: ${end.reason}.` } } });
|
|
24
|
+
output.close();
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
}).getReader();
|
|
28
|
+
try {
|
|
29
|
+
channel.send(input);
|
|
30
|
+
while (true) {
|
|
31
|
+
const next = await reader.read();
|
|
32
|
+
if (next.done) return;
|
|
33
|
+
yield next.value;
|
|
34
|
+
}
|
|
35
|
+
} finally {
|
|
36
|
+
signal.removeEventListener("abort", abort);
|
|
37
|
+
channel.close();
|
|
38
|
+
reader.releaseLock();
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
return {
|
|
42
|
+
stream,
|
|
43
|
+
async run(input, { signal, onProgress }) {
|
|
44
|
+
for await (const event of stream(input, { signal })) {
|
|
45
|
+
if (event.type === "result") return event.result;
|
|
46
|
+
onProgress?.(event.data);
|
|
47
|
+
}
|
|
48
|
+
throw new Error("Peek ended without a result.");
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
package/src/peek.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { defineTool, jsonSchema, modelCompletionSchema, modelSourceSchema } from "@asterism-app/sdk/contracts";
|
|
2
|
+
import { defineChannel, defineTool, jsonSchema, modelCompletionSchema, modelSourceSchema } from "@asterism-app/sdk/contracts";
|
|
3
3
|
import { builtin } from "./identity.ts";
|
|
4
4
|
|
|
5
|
+
const peekQuestionSchema = z.strictObject({
|
|
6
|
+
question: z.string().trim().min(1).describe("The question to investigate in this Agent's saved records."),
|
|
7
|
+
includeThinking: z.boolean().optional().describe("Include saved readable thinking. Defaults to false."),
|
|
8
|
+
}).describe("Question and optional access to saved readable thinking.");
|
|
9
|
+
|
|
5
10
|
export const Peek = defineTool({
|
|
6
11
|
id: builtin.name("tool.peek"), name: "peek",
|
|
7
12
|
description: "Investigate an Agent's saved timeline records and return a concise summary or explanation using the utility model.",
|
|
@@ -11,10 +16,7 @@ export const Peek = defineTool({
|
|
|
11
16
|
"Each call reads a fresh, fixed snapshot of the selected Agent's current timeline, including records preceding context compression.",
|
|
12
17
|
"includeThinking admits saved readable thinking into the investigation; its default is false.",
|
|
13
18
|
],
|
|
14
|
-
argsSchema:
|
|
15
|
-
question: z.string().trim().min(1).describe("The question to investigate in this Agent's saved records."),
|
|
16
|
-
includeThinking: z.boolean().optional().describe("Include saved readable thinking. Defaults to false."),
|
|
17
|
-
}).describe("Question and optional access to saved readable thinking."),
|
|
19
|
+
argsSchema: peekQuestionSchema,
|
|
18
20
|
});
|
|
19
21
|
export const peekResultSchema = z.strictObject({
|
|
20
22
|
snapshot: z.strictObject({ nodeId: z.string().nullable(), capturedAt: z.string(), records: z.number().int().nonnegative() }),
|
|
@@ -26,6 +28,34 @@ export const peekResultSchema = z.strictObject({
|
|
|
26
28
|
}).describe("Investigation progress or report, fixed snapshot position, request measurements and retrieved record references.");
|
|
27
29
|
export type PeekResult = z.infer<typeof peekResultSchema>;
|
|
28
30
|
|
|
31
|
+
/** Prior exchanges belong to the caller's temporary conversation, independently of the investigated timeline. */
|
|
32
|
+
export const peekExchangeSchema = z.strictObject({
|
|
33
|
+
question: z.string(),
|
|
34
|
+
report: z.string(),
|
|
35
|
+
outcome: z.enum(["succeeded", "partial", "cancelled", "failed"]),
|
|
36
|
+
});
|
|
37
|
+
export type PeekExchange = z.infer<typeof peekExchangeSchema>;
|
|
38
|
+
export const peekInputSchema = peekQuestionSchema.extend({
|
|
39
|
+
history: z.array(peekExchangeSchema).optional(),
|
|
40
|
+
});
|
|
41
|
+
export type PeekInput = z.infer<typeof peekInputSchema>;
|
|
42
|
+
export type PeekOutcome =
|
|
43
|
+
| { kind: "succeeded"; data: PeekResult }
|
|
44
|
+
| { kind: "partial"; data: PeekResult; message: string }
|
|
45
|
+
| { kind: "cancelled"; data?: PeekResult; message: string }
|
|
46
|
+
| { kind: "failed"; data?: PeekResult; error: { code: string; message: string } };
|
|
47
|
+
export type PeekEvent = { type: "progress"; data: PeekResult } | { type: "result"; result: PeekOutcome };
|
|
48
|
+
export interface PeekOptions {
|
|
49
|
+
signal: AbortSignal;
|
|
50
|
+
}
|
|
51
|
+
/** Each invocation captures fresh evidence. Callers explicitly supply any earlier Peek exchanges. */
|
|
52
|
+
export interface PeekClient {
|
|
53
|
+
stream(input: PeekInput, options: PeekOptions): AsyncIterable<PeekEvent>;
|
|
54
|
+
run(input: PeekInput, options: PeekOptions & { onProgress?: (data: PeekResult) => void }): Promise<PeekOutcome>;
|
|
55
|
+
}
|
|
56
|
+
/** One investigation per channel; closing it cancels that investigation. */
|
|
57
|
+
export const PeekChannel = defineChannel<PeekInput, PeekEvent>(builtin.name("agent.peek.channel"));
|
|
58
|
+
|
|
29
59
|
export function peekToModel(data: PeekResult): string {
|
|
30
60
|
return data.report;
|
|
31
61
|
}
|
package/src/renderer.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { pluginOf, pluginNamespace, type ThinkingLevel, type UiText } from "@ast
|
|
|
3
3
|
import type { AgentSelection } from "./configuration.ts";
|
|
4
4
|
import type { CatalogModel } from "./catalogs.ts";
|
|
5
5
|
|
|
6
|
+
export { createPeekClient } from "./peek-renderer.ts";
|
|
7
|
+
|
|
6
8
|
/** One instance mounts per expanded Agent card; obtains the associated object through SDK useRendererObject. */
|
|
7
9
|
export interface AgentUIContribution {
|
|
8
10
|
readonly id: string;
|
package/src/tools.ts
CHANGED
|
@@ -113,12 +113,13 @@ export const See = defineTool({
|
|
|
113
113
|
export const Wait = defineTool({
|
|
114
114
|
id: builtin.name("tool.wait"),
|
|
115
115
|
name: "wait",
|
|
116
|
-
description: "Wait until a resource reaches its resting state,
|
|
116
|
+
description: "Wait until a resource reaches its resting state, with an optional timeout.",
|
|
117
117
|
guidelines: [
|
|
118
118
|
"The resource implementation defines its resting state. A resource already at rest returns immediately.",
|
|
119
|
+
"Normally omit timeout and wait for completion or cancellation. Specify it only when the task has an explicit time limit.",
|
|
119
120
|
"Timeout or cancellation ends only the wait; the resource continues its own work. The result reports the observed state.",
|
|
120
121
|
],
|
|
121
122
|
argsSchema: z.strictObject({
|
|
122
|
-
timeout: z.number().positive().max(2147483).describe("
|
|
123
|
-
}).describe("
|
|
123
|
+
timeout: z.number().positive().max(2147483).optional().describe("Optional maximum wait in seconds; omitted means no timeout."),
|
|
124
|
+
}).describe("Wait with an optional time limit."),
|
|
124
125
|
});
|