@borgee/agents-host 0.2.94 → 0.2.97
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/agents-host.js +8 -0
- package/dist/background-runs.d.ts +4 -0
- package/dist/background-runs.js +8 -4
- package/dist/chat/chat-control-plane.d.ts +2 -1
- package/dist/chat/sdk-chat-control-plane.d.ts +3 -2
- package/dist/chat/sdk-chat-control-plane.js +3 -0
- package/dist/plugin-sdk.js +13 -1
- package/dist/plugin-sdk.js.map +2 -2
- package/dist/progress-to-activity.d.ts +3 -3
- package/dist/providers/claude/adapter.d.ts +2 -1
- package/dist/providers/claude/adapter.js +10 -0
- package/dist/providers/claude/cli-client.d.ts +3 -1
- package/dist/providers/claude/cli-client.js +263 -13
- package/package.json +9 -9
package/dist/agents-host.js
CHANGED
|
@@ -368,6 +368,14 @@ export class AgentsHost {
|
|
|
368
368
|
cancel: this.provider.cancelBackgroundRun
|
|
369
369
|
? (channelId, providerRunId) => (this.provider.cancelBackgroundRun(channelId, providerRunId))
|
|
370
370
|
: undefined,
|
|
371
|
+
onFinished: (channelId, run) => {
|
|
372
|
+
this.borgee.reportTaskFinished?.({
|
|
373
|
+
channelId,
|
|
374
|
+
taskId: run.runId,
|
|
375
|
+
outcome: run.state,
|
|
376
|
+
...(run.state === 'failed' ? { reason: 'unknown' } : {}),
|
|
377
|
+
});
|
|
378
|
+
},
|
|
371
379
|
});
|
|
372
380
|
}
|
|
373
381
|
async start() {
|
|
@@ -4,6 +4,10 @@ interface BackgroundRunTrackerOptions {
|
|
|
4
4
|
lifecycleSupported: boolean;
|
|
5
5
|
targetedCancellationSupported: boolean;
|
|
6
6
|
cancel?: (channelId: string, providerRunId: string) => Promise<boolean>;
|
|
7
|
+
onFinished?: (channelId: string, run: {
|
|
8
|
+
runId: string;
|
|
9
|
+
state: 'completed' | 'failed' | 'cancelled';
|
|
10
|
+
}) => void;
|
|
7
11
|
}
|
|
8
12
|
export declare class BackgroundRunTracker {
|
|
9
13
|
private readonly report;
|
package/dist/background-runs.js
CHANGED
|
@@ -99,6 +99,10 @@ export class BackgroundRunTracker {
|
|
|
99
99
|
historySize -= 1;
|
|
100
100
|
}
|
|
101
101
|
this.publish(run);
|
|
102
|
+
if (isConcreteTerminal(state) &&
|
|
103
|
+
(startsNewExecution || !held || !isConcreteTerminal(held.state))) {
|
|
104
|
+
this.options.onFinished?.(channelId, { runId: run.runId, state });
|
|
105
|
+
}
|
|
102
106
|
}
|
|
103
107
|
replay() {
|
|
104
108
|
for (const run of this.runs.values()) {
|
|
@@ -166,10 +170,10 @@ function runState(status) {
|
|
|
166
170
|
}
|
|
167
171
|
}
|
|
168
172
|
function isTerminal(state) {
|
|
169
|
-
return (state === '
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
+
return (isConcreteTerminal(state) || state === 'unknown');
|
|
174
|
+
}
|
|
175
|
+
function isConcreteTerminal(state) {
|
|
176
|
+
return state === 'completed' || state === 'failed' || state === 'cancelled';
|
|
173
177
|
}
|
|
174
178
|
function stableRunId(channelId, providerRunId, startedAt, executionId) {
|
|
175
179
|
const digest = createHash('sha256')
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AgentActivity, ReportTurnActivityInput, StopBackgroundRunHandler, StopTurnHandler, TurnActivityReporter } from '../plugin-sdk.js';
|
|
1
|
+
import type { AgentActivity, ReportTaskFinishedInput, ReportTurnActivityInput, StopBackgroundRunHandler, StopTurnHandler, TurnActivityReporter } from '../plugin-sdk.js';
|
|
2
2
|
import type { ChannelSummary, ChannelHistoryEntry, ChannelMessageEvent, CreateTaskInput, DirectoryUser, MeResponseUser, PostMessageInput, PostedMessage, ReadChannelHistoryInput, Task, UpdateTaskInput } from '../types.js';
|
|
3
3
|
export interface ChatControlPlane {
|
|
4
4
|
onStopTurn?(handler: StopTurnHandler | undefined): void;
|
|
@@ -12,6 +12,7 @@ export interface ChatControlPlane {
|
|
|
12
12
|
startTyping(channelId: string): () => void;
|
|
13
13
|
/** Opens one turn's report on the activity rail. Fire-and-forget: nothing recovers what it sends. */
|
|
14
14
|
reportTurnActivity(input: ReportTurnActivityInput): TurnActivityReporter;
|
|
15
|
+
reportTaskFinished?(input: ReportTaskFinishedInput): void;
|
|
15
16
|
reportActivity?(input: {
|
|
16
17
|
channelId: string;
|
|
17
18
|
activity: AgentActivity;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { type BorgeePluginClient, type BorgeePluginOptions, type InboundMessageEvent, type ReportTurnActivityInput, type StopTurnHandler, type StopBackgroundRunHandler, type TurnActivityReporter } from '../plugin-sdk.js';
|
|
1
|
+
import { type BorgeePluginClient, type BorgeePluginOptions, type InboundMessageEvent, type ReportTaskFinishedInput, type ReportTurnActivityInput, type StopTurnHandler, type StopBackgroundRunHandler, type TurnActivityReporter } from '../plugin-sdk.js';
|
|
2
2
|
import type { ChannelSummary, ChannelHistoryEntry, ChannelMessageEvent, CreateTaskInput, DirectoryUser, MeResponseUser, PostMessageInput, PostedMessage, ReadChannelHistoryInput, Task, UpdateTaskInput } from '../types.js';
|
|
3
3
|
import type { ChatControlPlane } from './chat-control-plane.js';
|
|
4
|
-
type PluginClientLike = Pick<BorgeePluginClient, 'agentId' | 'close' | 'connect' | 'createTask' | 'deleteMessage' | 'editMessage' | 'getMe' | 'getTask' | 'listChannels' | 'listTasks' | 'listUsers' | 'on' | 'onStopTurn' | 'onStopBackgroundRun' | 'reportActivity' | 'readHistory' | 'reportTurnActivity' | 'sendMessage' | 'startTyping' | 'updateTask' | 'setTaskProperty' | 'deleteTaskProperty'
|
|
4
|
+
type PluginClientLike = Pick<BorgeePluginClient, 'agentId' | 'close' | 'connect' | 'createTask' | 'deleteMessage' | 'editMessage' | 'getMe' | 'getTask' | 'listChannels' | 'listTasks' | 'listUsers' | 'on' | 'onStopTurn' | 'onStopBackgroundRun' | 'reportActivity' | 'readHistory' | 'reportTurnActivity' | 'sendMessage' | 'startTyping' | 'updateTask' | 'setTaskProperty' | 'deleteTaskProperty'> & Partial<Pick<BorgeePluginClient, 'reportTaskFinished'>>;
|
|
5
5
|
type PluginClientFactory = (options: BorgeePluginOptions) => PluginClientLike;
|
|
6
6
|
type SdkChatControlPlaneOptions = Pick<BorgeePluginOptions, 'pluginId'>;
|
|
7
7
|
/**
|
|
@@ -25,6 +25,7 @@ export declare class SdkChatControlPlane implements ChatControlPlane {
|
|
|
25
25
|
close(): Promise<void>;
|
|
26
26
|
postMessage(input: PostMessageInput): Promise<PostedMessage>;
|
|
27
27
|
reportActivity(input: Parameters<BorgeePluginClient['reportActivity']>[0]): void;
|
|
28
|
+
reportTaskFinished(input: ReportTaskFinishedInput): void;
|
|
28
29
|
editMessage(messageId: string, content: string): Promise<void>;
|
|
29
30
|
deleteMessage(messageId: string): Promise<void>;
|
|
30
31
|
startTyping(channelId: string): () => void;
|
|
@@ -82,6 +82,9 @@ export class SdkChatControlPlane {
|
|
|
82
82
|
reportActivity(input) {
|
|
83
83
|
this.client.reportActivity(input);
|
|
84
84
|
}
|
|
85
|
+
reportTaskFinished(input) {
|
|
86
|
+
this.client.reportTaskFinished?.(input);
|
|
87
|
+
}
|
|
85
88
|
async editMessage(messageId, content) {
|
|
86
89
|
await this.client.editMessage({ messageId, body: content });
|
|
87
90
|
}
|
package/dist/plugin-sdk.js
CHANGED
|
@@ -4502,7 +4502,7 @@ var BppTransport = class {
|
|
|
4502
4502
|
};
|
|
4503
4503
|
this.send(frame);
|
|
4504
4504
|
}
|
|
4505
|
-
// sendActivity flattens the
|
|
4505
|
+
// sendActivity flattens the activity union onto one frame. The union is
|
|
4506
4506
|
// how a producer says which shape it is reporting; the wire puts the
|
|
4507
4507
|
// discriminator beside its payload with no wrapper object, matching both the
|
|
4508
4508
|
// protocol this relays and inbound_message's own `kind`.
|
|
@@ -4575,6 +4575,18 @@ var BppTransport = class {
|
|
|
4575
4575
|
frame.stop_supported = action.activity.stopSupported;
|
|
4576
4576
|
frame.stop_unsupported_reason = action.activity.stopUnsupportedReason ?? "";
|
|
4577
4577
|
break;
|
|
4578
|
+
case "normalized":
|
|
4579
|
+
frame.protocol_version = action.activity.protocolVersion;
|
|
4580
|
+
frame.task_id = action.activity.taskId;
|
|
4581
|
+
frame.event = action.activity.event;
|
|
4582
|
+
break;
|
|
4583
|
+
}
|
|
4584
|
+
if (action.activity.shape === "normalized") {
|
|
4585
|
+
const ids = [frame.channel_id, frame.task_id];
|
|
4586
|
+
if (ids.some((value) => new TextEncoder().encode(value).byteLength > 256))
|
|
4587
|
+
return;
|
|
4588
|
+
if (new TextEncoder().encode(JSON.stringify(frame)).byteLength > 32768)
|
|
4589
|
+
return;
|
|
4578
4590
|
}
|
|
4579
4591
|
this.send(frame);
|
|
4580
4592
|
}
|