@agentplat/sessions 0.2.0-beta.2
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/LICENSE +202 -0
- package/README.md +25 -0
- package/dist/index.d.ts +187 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +457 -0
- package/dist/index.js.map +1 -0
- package/package.json +37 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
202
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# @agentplat/sessions
|
|
2
|
+
|
|
3
|
+
Typed, ephemeral multi-agent turn orchestration over an `AgentRuntime`. Sessions
|
|
4
|
+
coordinate speakers, bounded history, stopping rules, usage and one unified
|
|
5
|
+
event stream. They do not persist Rooms or grant tool permissions.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { createMultiAgentSession } from '@agentplat/sessions';
|
|
9
|
+
|
|
10
|
+
const session = createMultiAgentSession({
|
|
11
|
+
runtime,
|
|
12
|
+
tenant: { tenantId: 'local' },
|
|
13
|
+
speakers: [buyer, seller],
|
|
14
|
+
maxRounds: 4,
|
|
15
|
+
stopMarkers: ['DEAL AGREED'],
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
for await (const event of session.stream({ input: scenario, signal })) {
|
|
19
|
+
// session_started, turn_started, token, turn_completed, stop_reason...
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Use Agent Rooms when work must be durable, approval-gated or governed. A future
|
|
24
|
+
session sink can bridge this ephemeral event stream into Room audit without
|
|
25
|
+
changing the scheduler contract.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import type { AgentPlatID, JsonObject, Metadata, TenantContext } from '@agentplat/core';
|
|
2
|
+
import type { AgentRunInput, AgentRuntime, AgentUsage, StreamEvent } from '@agentplat/runtime';
|
|
3
|
+
/** One agent that can take turns in an ephemeral session. */
|
|
4
|
+
export interface SessionSpeaker {
|
|
5
|
+
id: AgentPlatID;
|
|
6
|
+
name: string;
|
|
7
|
+
instructions: string;
|
|
8
|
+
platform: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
modelName?: string;
|
|
11
|
+
config?: JsonObject;
|
|
12
|
+
metadata?: Metadata;
|
|
13
|
+
}
|
|
14
|
+
/** One bounded transcript entry produced by a session speaker. */
|
|
15
|
+
export interface SessionMessage {
|
|
16
|
+
speakerId: AgentPlatID;
|
|
17
|
+
speakerName: string;
|
|
18
|
+
content: string;
|
|
19
|
+
round: number;
|
|
20
|
+
turn: number;
|
|
21
|
+
createdAt: string;
|
|
22
|
+
}
|
|
23
|
+
/** Aggregated provider-reported usage across completed turns. */
|
|
24
|
+
export interface SessionUsage extends JsonObject {
|
|
25
|
+
inputTokens: number;
|
|
26
|
+
outputTokens: number;
|
|
27
|
+
totalTokens: number;
|
|
28
|
+
reportedTurns: number;
|
|
29
|
+
}
|
|
30
|
+
/** Stable reasons why an ephemeral session stopped. */
|
|
31
|
+
export type SessionStopReason = 'max_rounds' | 'predicate' | 'marker' | 'aborted' | 'failed';
|
|
32
|
+
/** State passed to a custom stopping predicate after every completed turn. */
|
|
33
|
+
export interface SessionStopContext {
|
|
34
|
+
sessionId: AgentPlatID;
|
|
35
|
+
speaker: SessionSpeaker;
|
|
36
|
+
round: number;
|
|
37
|
+
turn: number;
|
|
38
|
+
history: readonly SessionMessage[];
|
|
39
|
+
latest: SessionMessage;
|
|
40
|
+
usage: Readonly<SessionUsage>;
|
|
41
|
+
}
|
|
42
|
+
/** Optional structured result returned by a stopping predicate. */
|
|
43
|
+
export interface SessionStopDecision {
|
|
44
|
+
stop: boolean;
|
|
45
|
+
detail?: string;
|
|
46
|
+
}
|
|
47
|
+
/** Context used to customize the runtime input for one speaker turn. */
|
|
48
|
+
export interface SessionInputContext {
|
|
49
|
+
sessionId: AgentPlatID;
|
|
50
|
+
scenario: AgentRunInput['input'];
|
|
51
|
+
speaker: SessionSpeaker;
|
|
52
|
+
round: number;
|
|
53
|
+
turn: number;
|
|
54
|
+
history: readonly SessionMessage[];
|
|
55
|
+
metadata?: Metadata;
|
|
56
|
+
}
|
|
57
|
+
/** Configuration shared by every invocation of a multi-agent session. */
|
|
58
|
+
export interface MultiAgentSessionOptions {
|
|
59
|
+
runtime: AgentRuntime;
|
|
60
|
+
speakers: SessionSpeaker[];
|
|
61
|
+
tenant?: TenantContext;
|
|
62
|
+
credentials?: Record<string, string>;
|
|
63
|
+
maxRounds?: number;
|
|
64
|
+
historyLimit?: number;
|
|
65
|
+
stopMarkers?: string[];
|
|
66
|
+
stopWhen?: (context: SessionStopContext) => boolean | SessionStopDecision | Promise<boolean | SessionStopDecision>;
|
|
67
|
+
buildInput?: (context: SessionInputContext) => AgentRunInput;
|
|
68
|
+
idGenerator?: () => AgentPlatID;
|
|
69
|
+
clock?: () => Date;
|
|
70
|
+
}
|
|
71
|
+
/** Input for one independent session execution. */
|
|
72
|
+
export interface MultiAgentSessionInput {
|
|
73
|
+
input: AgentRunInput['input'];
|
|
74
|
+
history?: SessionMessage[];
|
|
75
|
+
metadata?: Metadata;
|
|
76
|
+
sessionId?: AgentPlatID;
|
|
77
|
+
signal?: AbortSignal;
|
|
78
|
+
}
|
|
79
|
+
/** Public result returned after draining a multi-agent session. */
|
|
80
|
+
export interface MultiAgentSessionResult {
|
|
81
|
+
sessionId: AgentPlatID;
|
|
82
|
+
status: 'completed' | 'aborted' | 'failed';
|
|
83
|
+
stopReason: SessionStopReason;
|
|
84
|
+
stopDetail?: string;
|
|
85
|
+
roundsCompleted: number;
|
|
86
|
+
turnsCompleted: number;
|
|
87
|
+
history: SessionMessage[];
|
|
88
|
+
usage: SessionUsage;
|
|
89
|
+
durationMs: number;
|
|
90
|
+
}
|
|
91
|
+
/** Compact speaker identity transported in session event payloads. */
|
|
92
|
+
export interface SessionSpeakerRef extends JsonObject {
|
|
93
|
+
id: AgentPlatID;
|
|
94
|
+
name: string;
|
|
95
|
+
}
|
|
96
|
+
/** Payload common to events scoped to one session. */
|
|
97
|
+
export interface SessionEventPayload extends JsonObject {
|
|
98
|
+
sessionId: AgentPlatID;
|
|
99
|
+
}
|
|
100
|
+
/** Payload common to events scoped to one speaker turn. */
|
|
101
|
+
export interface SessionTurnPayload extends SessionEventPayload {
|
|
102
|
+
turnId: AgentPlatID;
|
|
103
|
+
speaker: SessionSpeakerRef;
|
|
104
|
+
round: number;
|
|
105
|
+
turn: number;
|
|
106
|
+
}
|
|
107
|
+
/** Payload emitted when a session starts. */
|
|
108
|
+
export interface SessionStartedPayload extends SessionEventPayload {
|
|
109
|
+
speakers: SessionSpeakerRef[];
|
|
110
|
+
maxRounds: number;
|
|
111
|
+
historyLimit: number;
|
|
112
|
+
}
|
|
113
|
+
/** Payload emitted after one speaker turn completes. */
|
|
114
|
+
export type SessionTurnCompletedPayload = SessionTurnPayload & {
|
|
115
|
+
usage: AgentUsage;
|
|
116
|
+
aggregateUsage: SessionUsage;
|
|
117
|
+
latencyMs: number;
|
|
118
|
+
model?: string;
|
|
119
|
+
finishReason?: string;
|
|
120
|
+
};
|
|
121
|
+
/** Payload that keeps provider tool details scoped to their session turn. */
|
|
122
|
+
export type SessionToolPayload = SessionTurnPayload & {
|
|
123
|
+
runtimePayload?: JsonObject;
|
|
124
|
+
};
|
|
125
|
+
/** Payload explaining why a session stopped. */
|
|
126
|
+
export type SessionStopPayload = SessionEventPayload & {
|
|
127
|
+
reason: SessionStopReason;
|
|
128
|
+
detail?: string;
|
|
129
|
+
marker?: string;
|
|
130
|
+
round: number;
|
|
131
|
+
turn: number;
|
|
132
|
+
};
|
|
133
|
+
/** Payload emitted when one active speaker turn fails. */
|
|
134
|
+
export type SessionFailurePayload = SessionTurnPayload & {
|
|
135
|
+
reason: 'failed';
|
|
136
|
+
detail?: string;
|
|
137
|
+
};
|
|
138
|
+
/** Payload emitted as the final event in a session stream. */
|
|
139
|
+
export type SessionCompletedPayload = SessionEventPayload & {
|
|
140
|
+
status: 'completed' | 'aborted' | 'failed';
|
|
141
|
+
stopReason: SessionStopReason;
|
|
142
|
+
stopDetail?: string;
|
|
143
|
+
roundsCompleted: number;
|
|
144
|
+
turnsCompleted: number;
|
|
145
|
+
usage: SessionUsage;
|
|
146
|
+
durationMs: number;
|
|
147
|
+
};
|
|
148
|
+
/** Typed events emitted by `MultiAgentSession.stream()`. */
|
|
149
|
+
export type MultiAgentSessionEvent = SessionPayloadEvent<'session_started', SessionStartedPayload> | SessionPayloadEvent<'speaker_changed', SessionTurnPayload> | SessionPayloadEvent<'turn_started', SessionTurnPayload> | (SessionPayloadEvent<'token', SessionTurnPayload> & {
|
|
150
|
+
content: string;
|
|
151
|
+
}) | SessionPayloadEvent<'tool_call', SessionToolPayload> | SessionPayloadEvent<'tool_result', SessionToolPayload> | (SessionPayloadEvent<'turn_completed', SessionTurnCompletedPayload> & {
|
|
152
|
+
content: string;
|
|
153
|
+
}) | SessionPayloadEvent<'stop_reason', SessionStopPayload> | (SessionPayloadEvent<'session_failed', SessionFailurePayload> & {
|
|
154
|
+
content: string;
|
|
155
|
+
}) | SessionPayloadEvent<'session_completed', SessionCompletedPayload>;
|
|
156
|
+
type SessionPayloadEvent<TType extends string, TPayload extends JsonObject> = StreamEvent<TType, TPayload> & {
|
|
157
|
+
payload: TPayload;
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* Deterministic, ephemeral round-robin orchestration over an `AgentRuntime`.
|
|
161
|
+
*
|
|
162
|
+
* The session owns turn order and bounded transcript assembly only. It does not
|
|
163
|
+
* persist data, execute tools itself or imply Agent Room governance.
|
|
164
|
+
*/
|
|
165
|
+
export declare class MultiAgentSession {
|
|
166
|
+
private readonly options;
|
|
167
|
+
private readonly speakers;
|
|
168
|
+
private readonly tenant;
|
|
169
|
+
private readonly credentials?;
|
|
170
|
+
private readonly maxRounds;
|
|
171
|
+
private readonly historyLimit;
|
|
172
|
+
private readonly stopMarkers;
|
|
173
|
+
private readonly idGenerator;
|
|
174
|
+
private readonly clock;
|
|
175
|
+
constructor(options: MultiAgentSessionOptions);
|
|
176
|
+
/** Stream one independent multi-agent execution. */
|
|
177
|
+
stream(input: MultiAgentSessionInput): AsyncIterable<MultiAgentSessionEvent>;
|
|
178
|
+
/** Run a session to completion and return its bounded final state. */
|
|
179
|
+
run(input: MultiAgentSessionInput): Promise<MultiAgentSessionResult>;
|
|
180
|
+
private execute;
|
|
181
|
+
private agentDefinition;
|
|
182
|
+
private buildInput;
|
|
183
|
+
}
|
|
184
|
+
/** Create a reusable ephemeral multi-agent session. */
|
|
185
|
+
export declare function createMultiAgentSession(options: MultiAgentSessionOptions): MultiAgentSession;
|
|
186
|
+
export {};
|
|
187
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,QAAQ,EACR,aAAa,EACd,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAGV,aAAa,EACb,YAAY,EACZ,UAAU,EACV,WAAW,EACZ,MAAM,oBAAoB,CAAC;AAQ5B,6DAA6D;AAC7D,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,WAAW,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC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IAAE,OAAO,EAAE,QAAQ,CAAA;CAAE,CAAC;AAEzD;;;;;GAKG;AACH,qBAAa,iBAAiB;IAUhB,OAAO,CAAC,QAAQ,CAAC,OAAO;IATpC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAmB;IAC5C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IACvC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAyB;IACtD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAW;IACvC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoB;IAChD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAa;gBAEN,OAAO,EAAE,wBAAwB;IAwB9D,oDAAoD;IACpD,MAAM,CAAC,KAAK,EAAE,sBAAsB,GAAG,aAAa,CAAC,sBAAsB,CAAC;IAI5E,sEAAsE;IAChE,GAAG,CAAC,KAAK,EAAE,sBAAsB,GAAG,OAAO,CAAC,uBAAuB,CAAC;YAgB3D,OAAO;IAmRtB,OAAO,CAAC,eAAe;IAiBvB,OAAO,CAAC,UAAU;CAQnB;AAED,uDAAuD;AACvD,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,wBAAwB,GAChC,iBAAiB,CAEnB"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
import { AgentPlatError } from '@agentplat/core';
|
|
2
|
+
const sessionPolicies = {
|
|
3
|
+
mode: 'multi_agent_session',
|
|
4
|
+
tools: 'denied',
|
|
5
|
+
externalWrites: 'denied',
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Deterministic, ephemeral round-robin orchestration over an `AgentRuntime`.
|
|
9
|
+
*
|
|
10
|
+
* The session owns turn order and bounded transcript assembly only. It does not
|
|
11
|
+
* persist data, execute tools itself or imply Agent Room governance.
|
|
12
|
+
*/
|
|
13
|
+
export class MultiAgentSession {
|
|
14
|
+
options;
|
|
15
|
+
speakers;
|
|
16
|
+
tenant;
|
|
17
|
+
credentials;
|
|
18
|
+
maxRounds;
|
|
19
|
+
historyLimit;
|
|
20
|
+
stopMarkers;
|
|
21
|
+
idGenerator;
|
|
22
|
+
clock;
|
|
23
|
+
constructor(options) {
|
|
24
|
+
this.options = options;
|
|
25
|
+
this.speakers = validateSpeakers(options.speakers);
|
|
26
|
+
this.tenant = options.tenant
|
|
27
|
+
? structuredClone(options.tenant)
|
|
28
|
+
: { tenantId: 'local' };
|
|
29
|
+
required(this.tenant.tenantId, 'tenant.tenantId');
|
|
30
|
+
this.credentials = options.credentials
|
|
31
|
+
? { ...options.credentials }
|
|
32
|
+
: undefined;
|
|
33
|
+
this.maxRounds = positiveInteger(options.maxRounds ?? 4, 'maxRounds', 100);
|
|
34
|
+
this.historyLimit = positiveInteger(options.historyLimit ?? 50, 'historyLimit', 1_000);
|
|
35
|
+
this.stopMarkers = (options.stopMarkers ?? []).map((marker, index) => {
|
|
36
|
+
required(marker, `stopMarkers[${index}]`);
|
|
37
|
+
return marker;
|
|
38
|
+
});
|
|
39
|
+
this.idGenerator =
|
|
40
|
+
options.idGenerator ?? (() => globalThis.crypto.randomUUID());
|
|
41
|
+
this.clock = options.clock ?? (() => new Date());
|
|
42
|
+
}
|
|
43
|
+
/** Stream one independent multi-agent execution. */
|
|
44
|
+
stream(input) {
|
|
45
|
+
return this.execute(input);
|
|
46
|
+
}
|
|
47
|
+
/** Run a session to completion and return its bounded final state. */
|
|
48
|
+
async run(input) {
|
|
49
|
+
let result;
|
|
50
|
+
for await (const _event of this.execute(input, (completed) => {
|
|
51
|
+
result = completed;
|
|
52
|
+
})) {
|
|
53
|
+
// Draining the stream preserves the same execution path as web clients.
|
|
54
|
+
}
|
|
55
|
+
if (!result) {
|
|
56
|
+
throw new AgentPlatError('INTERNAL_ERROR', 'The multi-agent session ended without a result');
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
async *execute(input, onResult) {
|
|
61
|
+
validateInput(input.input);
|
|
62
|
+
const sessionId = input.sessionId ?? this.idGenerator();
|
|
63
|
+
required(sessionId, 'sessionId');
|
|
64
|
+
const startedAt = performance.now();
|
|
65
|
+
const history = cloneHistory(input.history ?? []).slice(-this.historyLimit);
|
|
66
|
+
const usage = emptyUsage();
|
|
67
|
+
let turnsCompleted = 0;
|
|
68
|
+
let roundsCompleted = 0;
|
|
69
|
+
let stopReason;
|
|
70
|
+
let stopDetail;
|
|
71
|
+
let stopMarker;
|
|
72
|
+
yield {
|
|
73
|
+
type: 'session_started',
|
|
74
|
+
runId: sessionId,
|
|
75
|
+
payload: {
|
|
76
|
+
sessionId,
|
|
77
|
+
speakers: this.speakers.map(speakerRef),
|
|
78
|
+
maxRounds: this.maxRounds,
|
|
79
|
+
historyLimit: this.historyLimit,
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
outer: for (let round = 1; round <= this.maxRounds; round += 1) {
|
|
83
|
+
for (const speaker of this.speakers) {
|
|
84
|
+
if (input.signal?.aborted) {
|
|
85
|
+
stopReason = 'aborted';
|
|
86
|
+
stopDetail = abortMessage(input.signal);
|
|
87
|
+
break outer;
|
|
88
|
+
}
|
|
89
|
+
const turn = turnsCompleted + 1;
|
|
90
|
+
const turnId = this.idGenerator();
|
|
91
|
+
const turnPayload = {
|
|
92
|
+
sessionId,
|
|
93
|
+
turnId,
|
|
94
|
+
speaker: speakerRef(speaker),
|
|
95
|
+
round,
|
|
96
|
+
turn,
|
|
97
|
+
};
|
|
98
|
+
yield {
|
|
99
|
+
type: 'speaker_changed',
|
|
100
|
+
runId: turnId,
|
|
101
|
+
payload: turnPayload,
|
|
102
|
+
};
|
|
103
|
+
yield { type: 'turn_started', runId: turnId, payload: turnPayload };
|
|
104
|
+
const turnStartedAt = performance.now();
|
|
105
|
+
let output = '';
|
|
106
|
+
let completion;
|
|
107
|
+
let turnFailure;
|
|
108
|
+
const agent = this.agentDefinition(speaker);
|
|
109
|
+
try {
|
|
110
|
+
const runInput = this.buildInput({
|
|
111
|
+
sessionId,
|
|
112
|
+
scenario: input.input,
|
|
113
|
+
speaker,
|
|
114
|
+
round,
|
|
115
|
+
turn,
|
|
116
|
+
history,
|
|
117
|
+
metadata: input.metadata,
|
|
118
|
+
});
|
|
119
|
+
for await (const event of this.options.runtime.stream(agent, runInput, {
|
|
120
|
+
tenant: this.tenant,
|
|
121
|
+
runId: turnId,
|
|
122
|
+
agentId: speaker.id,
|
|
123
|
+
signal: input.signal,
|
|
124
|
+
credentials: this.credentials,
|
|
125
|
+
policies: sessionPolicies,
|
|
126
|
+
metadata: {
|
|
127
|
+
...(input.metadata ?? {}),
|
|
128
|
+
sessionId,
|
|
129
|
+
speakerId: speaker.id,
|
|
130
|
+
round,
|
|
131
|
+
turn,
|
|
132
|
+
},
|
|
133
|
+
})) {
|
|
134
|
+
switch (event.type) {
|
|
135
|
+
case 'started':
|
|
136
|
+
break;
|
|
137
|
+
case 'token':
|
|
138
|
+
output += event.content;
|
|
139
|
+
yield {
|
|
140
|
+
type: 'token',
|
|
141
|
+
runId: turnId,
|
|
142
|
+
content: event.content,
|
|
143
|
+
payload: turnPayload,
|
|
144
|
+
};
|
|
145
|
+
break;
|
|
146
|
+
case 'tool_call':
|
|
147
|
+
case 'tool_result':
|
|
148
|
+
yield {
|
|
149
|
+
type: event.type,
|
|
150
|
+
runId: turnId,
|
|
151
|
+
content: event.content,
|
|
152
|
+
payload: {
|
|
153
|
+
...turnPayload,
|
|
154
|
+
...(event.payload ? { runtimePayload: event.payload } : {}),
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
break;
|
|
158
|
+
case 'completed':
|
|
159
|
+
output = event.content ?? output;
|
|
160
|
+
completion = event.payload;
|
|
161
|
+
break;
|
|
162
|
+
case 'failed':
|
|
163
|
+
turnFailure = event.content;
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
if (input.signal?.aborted) {
|
|
170
|
+
stopReason = 'aborted';
|
|
171
|
+
stopDetail = abortMessage(input.signal);
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
stopReason = 'failed';
|
|
175
|
+
stopDetail = turnFailure ?? errorMessage(error);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (turnFailure && !stopReason) {
|
|
179
|
+
stopReason = 'failed';
|
|
180
|
+
stopDetail = turnFailure;
|
|
181
|
+
}
|
|
182
|
+
if (stopReason === 'aborted' || stopReason === 'failed') {
|
|
183
|
+
if (stopReason === 'failed') {
|
|
184
|
+
yield {
|
|
185
|
+
type: 'session_failed',
|
|
186
|
+
runId: sessionId,
|
|
187
|
+
content: stopDetail ?? 'Session turn failed',
|
|
188
|
+
payload: {
|
|
189
|
+
...turnPayload,
|
|
190
|
+
reason: 'failed',
|
|
191
|
+
...(stopDetail ? { detail: stopDetail } : {}),
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
break outer;
|
|
196
|
+
}
|
|
197
|
+
const reportedUsage = normalizedUsage(completion?.usage);
|
|
198
|
+
addUsage(usage, reportedUsage, completion?.usage !== undefined);
|
|
199
|
+
turnsCompleted = turn;
|
|
200
|
+
roundsCompleted = round;
|
|
201
|
+
const message = {
|
|
202
|
+
speakerId: speaker.id,
|
|
203
|
+
speakerName: speaker.name,
|
|
204
|
+
content: output,
|
|
205
|
+
round,
|
|
206
|
+
turn,
|
|
207
|
+
createdAt: this.clock().toISOString(),
|
|
208
|
+
};
|
|
209
|
+
history.push(message);
|
|
210
|
+
if (history.length > this.historyLimit)
|
|
211
|
+
history.shift();
|
|
212
|
+
yield {
|
|
213
|
+
type: 'turn_completed',
|
|
214
|
+
runId: turnId,
|
|
215
|
+
content: output,
|
|
216
|
+
payload: {
|
|
217
|
+
...turnPayload,
|
|
218
|
+
usage: reportedUsage,
|
|
219
|
+
aggregateUsage: { ...usage },
|
|
220
|
+
latencyMs: completion?.latencyMs ?? elapsedMilliseconds(turnStartedAt),
|
|
221
|
+
...(completion?.model ? { model: completion.model } : {}),
|
|
222
|
+
...(completion?.finishReason
|
|
223
|
+
? { finishReason: completion.finishReason }
|
|
224
|
+
: {}),
|
|
225
|
+
},
|
|
226
|
+
};
|
|
227
|
+
stopMarker = matchingMarker(output, this.stopMarkers);
|
|
228
|
+
if (stopMarker) {
|
|
229
|
+
stopReason = 'marker';
|
|
230
|
+
stopDetail = `Matched stop marker: ${stopMarker}`;
|
|
231
|
+
break outer;
|
|
232
|
+
}
|
|
233
|
+
if (this.options.stopWhen) {
|
|
234
|
+
try {
|
|
235
|
+
const decision = await this.options.stopWhen({
|
|
236
|
+
sessionId,
|
|
237
|
+
speaker,
|
|
238
|
+
round,
|
|
239
|
+
turn,
|
|
240
|
+
history: cloneHistory(history),
|
|
241
|
+
latest: { ...message },
|
|
242
|
+
usage: { ...usage },
|
|
243
|
+
});
|
|
244
|
+
if (decision === true ||
|
|
245
|
+
(typeof decision === 'object' && decision.stop)) {
|
|
246
|
+
stopReason = 'predicate';
|
|
247
|
+
stopDetail =
|
|
248
|
+
typeof decision === 'object' ? decision.detail : undefined;
|
|
249
|
+
break outer;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
catch (error) {
|
|
253
|
+
stopReason = 'failed';
|
|
254
|
+
stopDetail = errorMessage(error);
|
|
255
|
+
yield {
|
|
256
|
+
type: 'session_failed',
|
|
257
|
+
runId: sessionId,
|
|
258
|
+
content: stopDetail,
|
|
259
|
+
payload: {
|
|
260
|
+
...turnPayload,
|
|
261
|
+
reason: 'failed',
|
|
262
|
+
detail: stopDetail,
|
|
263
|
+
},
|
|
264
|
+
};
|
|
265
|
+
break outer;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
stopReason ??= input.signal?.aborted ? 'aborted' : 'max_rounds';
|
|
271
|
+
if (stopReason === 'aborted') {
|
|
272
|
+
stopDetail ??= input.signal ? abortMessage(input.signal) : undefined;
|
|
273
|
+
}
|
|
274
|
+
yield {
|
|
275
|
+
type: 'stop_reason',
|
|
276
|
+
runId: sessionId,
|
|
277
|
+
payload: {
|
|
278
|
+
sessionId,
|
|
279
|
+
reason: stopReason,
|
|
280
|
+
...(stopDetail ? { detail: stopDetail } : {}),
|
|
281
|
+
...(stopMarker ? { marker: stopMarker } : {}),
|
|
282
|
+
round: roundsCompleted,
|
|
283
|
+
turn: turnsCompleted,
|
|
284
|
+
},
|
|
285
|
+
};
|
|
286
|
+
const status = stopReason === 'aborted'
|
|
287
|
+
? 'aborted'
|
|
288
|
+
: stopReason === 'failed'
|
|
289
|
+
? 'failed'
|
|
290
|
+
: 'completed';
|
|
291
|
+
const result = {
|
|
292
|
+
sessionId,
|
|
293
|
+
status,
|
|
294
|
+
stopReason,
|
|
295
|
+
stopDetail,
|
|
296
|
+
roundsCompleted,
|
|
297
|
+
turnsCompleted,
|
|
298
|
+
history: cloneHistory(history),
|
|
299
|
+
usage: { ...usage },
|
|
300
|
+
durationMs: elapsedMilliseconds(startedAt),
|
|
301
|
+
};
|
|
302
|
+
onResult?.(result);
|
|
303
|
+
yield {
|
|
304
|
+
type: 'session_completed',
|
|
305
|
+
runId: sessionId,
|
|
306
|
+
payload: {
|
|
307
|
+
sessionId,
|
|
308
|
+
status,
|
|
309
|
+
stopReason,
|
|
310
|
+
...(stopDetail ? { stopDetail } : {}),
|
|
311
|
+
roundsCompleted,
|
|
312
|
+
turnsCompleted,
|
|
313
|
+
usage: { ...usage },
|
|
314
|
+
durationMs: result.durationMs,
|
|
315
|
+
},
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
agentDefinition(speaker) {
|
|
319
|
+
const now = this.clock().toISOString();
|
|
320
|
+
return {
|
|
321
|
+
id: speaker.id,
|
|
322
|
+
tenantId: this.tenant.tenantId,
|
|
323
|
+
name: speaker.name,
|
|
324
|
+
description: speaker.description,
|
|
325
|
+
instructions: speaker.instructions,
|
|
326
|
+
platform: speaker.platform,
|
|
327
|
+
modelName: speaker.modelName,
|
|
328
|
+
config: speaker.config,
|
|
329
|
+
metadata: speaker.metadata,
|
|
330
|
+
createdAt: now,
|
|
331
|
+
updatedAt: now,
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
buildInput(context) {
|
|
335
|
+
return (this.options.buildInput?.({
|
|
336
|
+
...context,
|
|
337
|
+
history: cloneHistory(context.history),
|
|
338
|
+
}) ?? defaultInput(context));
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
/** Create a reusable ephemeral multi-agent session. */
|
|
342
|
+
export function createMultiAgentSession(options) {
|
|
343
|
+
return new MultiAgentSession(options);
|
|
344
|
+
}
|
|
345
|
+
function validateSpeakers(speakers) {
|
|
346
|
+
if (!Array.isArray(speakers) || speakers.length < 2) {
|
|
347
|
+
throw new AgentPlatError('VALIDATION_ERROR', 'A multi-agent session requires at least two speakers');
|
|
348
|
+
}
|
|
349
|
+
const ids = new Set();
|
|
350
|
+
return speakers.map((speaker, index) => {
|
|
351
|
+
required(speaker.id, `speakers[${index}].id`);
|
|
352
|
+
required(speaker.name, `speakers[${index}].name`);
|
|
353
|
+
required(speaker.instructions, `speakers[${index}].instructions`);
|
|
354
|
+
required(speaker.platform, `speakers[${index}].platform`);
|
|
355
|
+
if (ids.has(speaker.id)) {
|
|
356
|
+
throw new AgentPlatError('VALIDATION_ERROR', `Duplicate session speaker id: ${speaker.id}`);
|
|
357
|
+
}
|
|
358
|
+
ids.add(speaker.id);
|
|
359
|
+
return structuredClone(speaker);
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
function validateInput(input) {
|
|
363
|
+
if ((typeof input === 'string' && !input.trim()) ||
|
|
364
|
+
(Array.isArray(input) && input.length === 0)) {
|
|
365
|
+
throw new AgentPlatError('VALIDATION_ERROR', 'Session input is required');
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
function defaultInput(context) {
|
|
369
|
+
const scenario = typeof context.scenario === 'string'
|
|
370
|
+
? context.scenario
|
|
371
|
+
: JSON.stringify(context.scenario);
|
|
372
|
+
const transcript = context.history.length
|
|
373
|
+
? context.history
|
|
374
|
+
.map((message) => `${message.speakerName}: ${message.content}`)
|
|
375
|
+
.join('\n')
|
|
376
|
+
: '(no previous turns)';
|
|
377
|
+
return {
|
|
378
|
+
input: [
|
|
379
|
+
{
|
|
380
|
+
role: 'user',
|
|
381
|
+
content: [
|
|
382
|
+
`Scenario:\n${scenario}`,
|
|
383
|
+
`Conversation so far:\n${transcript}`,
|
|
384
|
+
`It is now your turn as ${context.speaker.name}. Respond in character.`,
|
|
385
|
+
].join('\n\n'),
|
|
386
|
+
},
|
|
387
|
+
],
|
|
388
|
+
mode: 'chat',
|
|
389
|
+
metadata: {
|
|
390
|
+
...(context.metadata ?? {}),
|
|
391
|
+
sessionId: context.sessionId,
|
|
392
|
+
speakerId: context.speaker.id,
|
|
393
|
+
round: context.round,
|
|
394
|
+
turn: context.turn,
|
|
395
|
+
},
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
function speakerRef(speaker) {
|
|
399
|
+
return { id: speaker.id, name: speaker.name };
|
|
400
|
+
}
|
|
401
|
+
function emptyUsage() {
|
|
402
|
+
return {
|
|
403
|
+
inputTokens: 0,
|
|
404
|
+
outputTokens: 0,
|
|
405
|
+
totalTokens: 0,
|
|
406
|
+
reportedTurns: 0,
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
function normalizedUsage(usage) {
|
|
410
|
+
return {
|
|
411
|
+
inputTokens: normalizedCount(usage?.inputTokens),
|
|
412
|
+
outputTokens: normalizedCount(usage?.outputTokens),
|
|
413
|
+
totalTokens: normalizedCount(usage?.totalTokens),
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
function addUsage(total, usage, providerReported) {
|
|
417
|
+
total.inputTokens += usage.inputTokens ?? 0;
|
|
418
|
+
total.outputTokens += usage.outputTokens ?? 0;
|
|
419
|
+
total.totalTokens += usage.totalTokens ?? 0;
|
|
420
|
+
if (providerReported)
|
|
421
|
+
total.reportedTurns += 1;
|
|
422
|
+
}
|
|
423
|
+
function normalizedCount(value) {
|
|
424
|
+
return typeof value === 'number' && Number.isFinite(value) && value >= 0
|
|
425
|
+
? value
|
|
426
|
+
: 0;
|
|
427
|
+
}
|
|
428
|
+
function matchingMarker(output, markers) {
|
|
429
|
+
const normalized = output.toLocaleLowerCase();
|
|
430
|
+
return markers.find((marker) => normalized.includes(marker.toLocaleLowerCase()));
|
|
431
|
+
}
|
|
432
|
+
function cloneHistory(history) {
|
|
433
|
+
return history.map((message) => ({ ...message }));
|
|
434
|
+
}
|
|
435
|
+
function elapsedMilliseconds(startedAt) {
|
|
436
|
+
return Math.max(0, Math.round((performance.now() - startedAt) * 100) / 100);
|
|
437
|
+
}
|
|
438
|
+
function abortMessage(signal) {
|
|
439
|
+
return signal.reason instanceof Error
|
|
440
|
+
? signal.reason.message
|
|
441
|
+
: 'Session aborted';
|
|
442
|
+
}
|
|
443
|
+
function errorMessage(error) {
|
|
444
|
+
return error instanceof Error ? error.message : 'Session execution failed';
|
|
445
|
+
}
|
|
446
|
+
function required(value, field) {
|
|
447
|
+
if (typeof value !== 'string' || !value.trim()) {
|
|
448
|
+
throw new AgentPlatError('VALIDATION_ERROR', `${field} is required`);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
function positiveInteger(value, field, maximum) {
|
|
452
|
+
if (!Number.isInteger(value) || value < 1 || value > maximum) {
|
|
453
|
+
throw new AgentPlatError('VALIDATION_ERROR', `${field} must be an integer between 1 and ${maximum}`);
|
|
454
|
+
}
|
|
455
|
+
return value;
|
|
456
|
+
}
|
|
457
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAgBjD,MA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,CAAC;AAED,SAAS,mBAAmB,CAAC,SAAiB;IAC5C,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,YAAY,CAAC,MAAmB;IACvC,OAAO,MAAM,CAAC,MAAM,YAAY,KAAK;QACnC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO;QACvB,CAAC,CAAC,iBAAiB,CAAC;AACxB,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IAClC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,0BAA0B,CAAC;AAC7E,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc,EAAE,KAAa;IAC7C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC;QAC/C,MAAM,IAAI,cAAc,CAAC,kBAAkB,EAAE,GAAG,KAAK,cAAc,CAAC,CAAC;IACvE,CAAC;AACH,CAAC;AAED,SAAS,eAAe,CACtB,KAAa,EACb,KAAa,EACb,OAAe;IAEf,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,OAAO,EAAE,CAAC;QAC7D,MAAM,IAAI,cAAc,CACtB,kBAAkB,EAClB,GAAG,KAAK,qCAAqC,OAAO,EAAE,CACvD,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agentplat/sessions",
|
|
3
|
+
"version": "0.2.0-beta.2",
|
|
4
|
+
"description": "Typed ephemeral multi-agent sessions for AgentPlat runtimes.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@agentplat/core": "^0.2.0-beta.2",
|
|
22
|
+
"@agentplat/runtime": "^0.2.0-beta.2"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/Agentplat/agentplat.git",
|
|
30
|
+
"directory": "packages/sessions"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsc -p tsconfig.json",
|
|
34
|
+
"type-check": "tsc -p tsconfig.json --noEmit",
|
|
35
|
+
"clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\""
|
|
36
|
+
}
|
|
37
|
+
}
|