@tangle-network/agent-interface 5.10.2 → 5.10.3
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/README.md +6 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/speaker.d.ts +41 -0
- package/dist/speaker.js +39 -0
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -5,6 +5,12 @@ agents, the sidecar, and provider adapters: capabilities, agent profiles,
|
|
|
5
5
|
message parts, and harness descriptors. This is the canonical home for those
|
|
6
6
|
shapes; higher-level packages import from here rather than redefining them.
|
|
7
7
|
|
|
8
|
+
`partitionBySpeaker` and its `Speaker`, `SpeakerPart`, `SpeakerState` and
|
|
9
|
+
`SpeakerSection` types are available from the root and the server-safe `/speaker`
|
|
10
|
+
entry. Stored parts follow their preceding speaker; explicit live `speaker` tags
|
|
11
|
+
win over position. Repeated headers update the same section, unowned parts come
|
|
12
|
+
first, and input objects retain their identity. UI chat re-exports this contract.
|
|
13
|
+
|
|
8
14
|
## Authored subscription seats
|
|
9
15
|
|
|
10
16
|
`AgentProfile.seats` is an optional ordered chain for continuing one logical agent
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** Where one responder is in its answer. */
|
|
2
|
+
export type SpeakerState = "answering" | "done" | "failed";
|
|
3
|
+
/**
|
|
4
|
+
* A responder of a turn addressed to several agents. In the turn's parts it is
|
|
5
|
+
* a `{ type: "speaker", id, name, handle?, state? }` part written before the
|
|
6
|
+
* responder's answer.
|
|
7
|
+
*/
|
|
8
|
+
export interface Speaker {
|
|
9
|
+
/** The agent's stable id. It keys the avatar's tone and a live part's `speaker` tag. */
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
/** What a person types after `@` to address the agent. */
|
|
13
|
+
handle?: string;
|
|
14
|
+
/** Set once the responder ended; absent while it answers and on rows written before responders reported an end. */
|
|
15
|
+
state?: SpeakerState;
|
|
16
|
+
}
|
|
17
|
+
export type SpeakerPart = Speaker & {
|
|
18
|
+
type: "speaker";
|
|
19
|
+
};
|
|
20
|
+
/** One responder's share of a turn: its speaker part and the parts it wrote. */
|
|
21
|
+
export interface SpeakerSection<T> {
|
|
22
|
+
/** The latest speaker part for this responder; null for the parts no speaker owns. */
|
|
23
|
+
speaker: (T & SpeakerPart) | null;
|
|
24
|
+
parts: T[];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Splits one assistant turn's parts by the agent that wrote them.
|
|
28
|
+
*
|
|
29
|
+
* A stored row holds a speaker part before each responder's answer, so a part
|
|
30
|
+
* belongs to the speaker part before it. A live stream announces every
|
|
31
|
+
* responder first and then interleaves their output, so a part names its owner
|
|
32
|
+
* in `speaker` (the responder's id), which wins over position. A later speaker
|
|
33
|
+
* part with an id already seen replaces that responder's speaker part, which is
|
|
34
|
+
* how its end state arrives, and never opens a second section.
|
|
35
|
+
*
|
|
36
|
+
* Sections keep the order speakers were first announced. Parts no speaker owns
|
|
37
|
+
* come first, in a section whose `speaker` is null; a turn without speaker
|
|
38
|
+
* parts is that one section. No part is dropped, copied or reordered within its
|
|
39
|
+
* section.
|
|
40
|
+
*/
|
|
41
|
+
export declare function partitionBySpeaker<T extends object>(parts: readonly T[]): SpeakerSection<T>[];
|
package/dist/speaker.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
function isSpeakerPart(part) {
|
|
2
|
+
const record = part;
|
|
3
|
+
return !!record && record.type === "speaker" && typeof record.id === "string" && typeof record.name === "string";
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Splits one assistant turn's parts by the agent that wrote them.
|
|
7
|
+
*
|
|
8
|
+
* A stored row holds a speaker part before each responder's answer, so a part
|
|
9
|
+
* belongs to the speaker part before it. A live stream announces every
|
|
10
|
+
* responder first and then interleaves their output, so a part names its owner
|
|
11
|
+
* in `speaker` (the responder's id), which wins over position. A later speaker
|
|
12
|
+
* part with an id already seen replaces that responder's speaker part, which is
|
|
13
|
+
* how its end state arrives, and never opens a second section.
|
|
14
|
+
*
|
|
15
|
+
* Sections keep the order speakers were first announced. Parts no speaker owns
|
|
16
|
+
* come first, in a section whose `speaker` is null; a turn without speaker
|
|
17
|
+
* parts is that one section. No part is dropped, copied or reordered within its
|
|
18
|
+
* section.
|
|
19
|
+
*/
|
|
20
|
+
export function partitionBySpeaker(parts) {
|
|
21
|
+
const sections = new Map();
|
|
22
|
+
const unowned = [];
|
|
23
|
+
let current;
|
|
24
|
+
for (const part of parts) {
|
|
25
|
+
if (isSpeakerPart(part)) {
|
|
26
|
+
current = sections.get(part.id);
|
|
27
|
+
if (current)
|
|
28
|
+
current.speaker = part;
|
|
29
|
+
else
|
|
30
|
+
sections.set(part.id, (current = { speaker: part, parts: [] }));
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const tag = part.speaker;
|
|
34
|
+
const owner = typeof tag === "string" ? sections.get(tag) : current;
|
|
35
|
+
(owner?.parts ?? unowned).push(part);
|
|
36
|
+
}
|
|
37
|
+
const owned = [...sections.values()];
|
|
38
|
+
return unowned.length > 0 || owned.length === 0 ? [{ speaker: null, parts: unowned }, ...owned] : owned;
|
|
39
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tangle-network/agent-interface",
|
|
3
|
-
"version": "5.10.
|
|
3
|
+
"version": "5.10.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"license": "MIT",
|
|
@@ -66,6 +66,11 @@
|
|
|
66
66
|
"import": "./dist/learning-state.js",
|
|
67
67
|
"types": "./dist/learning-state.d.ts",
|
|
68
68
|
"default": "./dist/learning-state.js"
|
|
69
|
+
},
|
|
70
|
+
"./speaker": {
|
|
71
|
+
"import": "./dist/speaker.js",
|
|
72
|
+
"types": "./dist/speaker.d.ts",
|
|
73
|
+
"default": "./dist/speaker.js"
|
|
69
74
|
}
|
|
70
75
|
},
|
|
71
76
|
"repository": {
|