@axiastudio/aioc 0.1.0 → 0.1.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/README.md +13 -5
- package/dist/approval-helpers.d.ts +24 -0
- package/dist/approval-helpers.d.ts.map +1 -0
- package/dist/approval-helpers.js +94 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/providers/chat-completions.d.ts +1 -0
- package/dist/providers/chat-completions.d.ts.map +1 -1
- package/dist/providers/chat-completions.js +6 -3
- package/dist/providers/openai.d.ts +1 -0
- package/dist/providers/openai.d.ts.map +1 -1
- package/dist/providers/openai.js +3 -0
- package/dist/run-output-events.d.ts +31 -0
- package/dist/run-output-events.d.ts.map +1 -0
- package/dist/run-output-events.js +64 -0
- package/dist/thread-history.d.ts +10 -0
- package/dist/thread-history.d.ts.map +1 -0
- package/dist/thread-history.js +25 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,12 +8,15 @@ Project home and documentation: [https://axiastudio.github.io/aioc](https://axia
|
|
|
8
8
|
|
|
9
9
|
## Release Status
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Current stable release: `0.1.2`.
|
|
12
|
+
The stable `0.1.x` line started with `0.1.0`.
|
|
12
13
|
The core runtime surface is compatibility-managed. Breaking changes to the stable surface should ship only with explicit migration guidance and release notes.
|
|
13
14
|
|
|
14
15
|
### Stable Scope
|
|
15
16
|
|
|
16
|
-
AIOC `0.1.0`
|
|
17
|
+
AIOC `0.1.0` stabilized the core runtime surface, public documentation aligned to the exported contract, `RunRecord` and replay/compare workflows, and the governance-first runtime model validated in real applications beyond toy examples.
|
|
18
|
+
AIOC `0.1.1` adds thread-history utilities, the run-output stream adapter, and provider-specific instruction-role documentation without changing the stable governance model.
|
|
19
|
+
AIOC `0.1.2` adds approval evidence helpers for application-owned approval workflows.
|
|
17
20
|
|
|
18
21
|
- Release notes: `CHANGELOG.md`
|
|
19
22
|
- Historical beta contract snapshot: `docs/BETA-CONTRACT.md`
|
|
@@ -94,10 +97,13 @@ console.log(result.finalOutput);
|
|
|
94
97
|
- handoffs via `Agent({ handoffs: [...] })`
|
|
95
98
|
- `run(...)` with streaming support (`stream` defaults to `false`)
|
|
96
99
|
- policy helpers `allow(...)` / `deny(...)` / `requireApproval(...)`
|
|
100
|
+
- approval evidence helpers `createApprovalRequestSeed(...)`, `toApprovedProposalHashes(...)`, `toActiveApprovalGrantMap(...)`
|
|
97
101
|
- provider setup helpers `setupMistral(...)`, `setupOpenAI(...)`, `setupProvider(...)`
|
|
98
102
|
- run logger hook `run(..., { logger })`
|
|
99
103
|
- run record hook `run(..., { record })`
|
|
104
|
+
- run output adapter `toRunOutputEvents(...)`
|
|
100
105
|
- run-record utilities `extractToolCalls(...)`, `compareRunRecords(...)`, `replayFromRunRecord(...)`
|
|
106
|
+
- thread history utilities `toThreadHistory(...)`, `appendUserMessage(...)`, `replaceThreadHistory(...)`, `applyRunResultHistory(...)`
|
|
101
107
|
- JSON helper `toJsonValue(...)`
|
|
102
108
|
|
|
103
109
|
## Policy Gate (Minimal)
|
|
@@ -259,9 +265,11 @@ AIOC adopts the following non-negotiable principles:
|
|
|
259
265
|
- `docs/RFC-0002-policy-gates-for-tools-and-handoffs.md` (`Accepted`)
|
|
260
266
|
- `docs/RFC-0003-run-record-audit-trail-and-persistence.md` (`Accepted`)
|
|
261
267
|
- `docs/RFC-0004-policy-outcomes-and-approval-model.md` (`Accepted`)
|
|
262
|
-
- `docs/RFC-0005-suspended-proposals-and-approval-lifecycle.md` (`
|
|
263
|
-
- `docs/RFC-0006-approval-evidence-helpers.md` (`
|
|
264
|
-
- `docs/RFC-0007-thread-state-utilities.md` (`
|
|
268
|
+
- `docs/RFC-0005-suspended-proposals-and-approval-lifecycle.md` (`Accepted`)
|
|
269
|
+
- `docs/RFC-0006-approval-evidence-helpers.md` (`Accepted`)
|
|
270
|
+
- `docs/RFC-0007-thread-state-utilities.md` (`Accepted`)
|
|
271
|
+
- `docs/RFC-0008-run-stream-consumer-utilities.md` (`Accepted`)
|
|
272
|
+
- `docs/RFC-0010-policy-composition-helpers.md` (`Draft`)
|
|
265
273
|
- `docs/PRIVACY-BASELINE.md`
|
|
266
274
|
|
|
267
275
|
## Historical Snapshots
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { SuspendedProposal } from "./run-record";
|
|
2
|
+
export interface ApprovalGrant {
|
|
3
|
+
proposalHash: string;
|
|
4
|
+
approvedAt: string;
|
|
5
|
+
expiresAt?: string;
|
|
6
|
+
revokedAt?: string;
|
|
7
|
+
metadata?: Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
export interface ApprovalRequestSeed {
|
|
10
|
+
proposalHash: string;
|
|
11
|
+
kind: "tool" | "handoff";
|
|
12
|
+
reason: string;
|
|
13
|
+
publicReason?: string;
|
|
14
|
+
policyVersion?: string;
|
|
15
|
+
expiresAt?: string;
|
|
16
|
+
resourceName: string;
|
|
17
|
+
canonicalPayloadJson: string;
|
|
18
|
+
}
|
|
19
|
+
export declare function createApprovalRequestSeed(proposal: SuspendedProposal): ApprovalRequestSeed;
|
|
20
|
+
export declare function isApprovalGrantActive(grant: ApprovalGrant, now?: string): boolean;
|
|
21
|
+
export declare function findActiveApprovalGrant(proposalHash: string, grants: readonly ApprovalGrant[], now?: string): ApprovalGrant | null;
|
|
22
|
+
export declare function toActiveApprovalGrantMap(grants: readonly ApprovalGrant[], now?: string): Record<string, ApprovalGrant>;
|
|
23
|
+
export declare function toApprovedProposalHashes(grants: readonly ApprovalGrant[], now?: string): string[];
|
|
24
|
+
//# sourceMappingURL=approval-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"approval-helpers.d.ts","sourceRoot":"","sources":["../src/approval-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEtD,MAAM,WAAW,aAAa;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,mBAAmB;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,oBAAoB,EAAE,MAAM,CAAC;CAC9B;AAsCD,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,iBAAiB,GAC1B,mBAAmB,CAoBrB;AAED,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,aAAa,EACpB,GAAG,CAAC,EAAE,MAAM,GACX,OAAO,CAYT;AAED,wBAAgB,uBAAuB,CACrC,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,SAAS,aAAa,EAAE,EAChC,GAAG,CAAC,EAAE,MAAM,GACX,aAAa,GAAG,IAAI,CAgBtB;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,SAAS,aAAa,EAAE,EAChC,GAAG,CAAC,EAAE,MAAM,GACX,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAe/B;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,SAAS,aAAa,EAAE,EAChC,GAAG,CAAC,EAAE,MAAM,GACX,MAAM,EAAE,CAEV"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createApprovalRequestSeed = createApprovalRequestSeed;
|
|
4
|
+
exports.isApprovalGrantActive = isApprovalGrantActive;
|
|
5
|
+
exports.findActiveApprovalGrant = findActiveApprovalGrant;
|
|
6
|
+
exports.toActiveApprovalGrantMap = toActiveApprovalGrantMap;
|
|
7
|
+
exports.toApprovedProposalHashes = toApprovedProposalHashes;
|
|
8
|
+
function parseTimestamp(value, label) {
|
|
9
|
+
const timestamp = Date.parse(value);
|
|
10
|
+
if (Number.isNaN(timestamp)) {
|
|
11
|
+
throw new Error(`${label} must be a valid timestamp.`);
|
|
12
|
+
}
|
|
13
|
+
return timestamp;
|
|
14
|
+
}
|
|
15
|
+
function getNowTimestamp(now) {
|
|
16
|
+
return parseTimestamp(now ?? new Date().toISOString(), "now");
|
|
17
|
+
}
|
|
18
|
+
function isGrantNewer(candidate, current) {
|
|
19
|
+
return (parseTimestamp(candidate.approvedAt, "grant.approvedAt") >
|
|
20
|
+
parseTimestamp(current.approvedAt, "grant.approvedAt"));
|
|
21
|
+
}
|
|
22
|
+
function getProposalMetadata(proposal) {
|
|
23
|
+
return {
|
|
24
|
+
...(typeof proposal.publicReason !== "undefined"
|
|
25
|
+
? { publicReason: proposal.publicReason }
|
|
26
|
+
: {}),
|
|
27
|
+
...(typeof proposal.policyVersion !== "undefined"
|
|
28
|
+
? { policyVersion: proposal.policyVersion }
|
|
29
|
+
: {}),
|
|
30
|
+
...(typeof proposal.expiresAt !== "undefined"
|
|
31
|
+
? { expiresAt: proposal.expiresAt }
|
|
32
|
+
: {}),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function createApprovalRequestSeed(proposal) {
|
|
36
|
+
if (proposal.kind === "tool") {
|
|
37
|
+
return {
|
|
38
|
+
proposalHash: proposal.proposalHash,
|
|
39
|
+
kind: proposal.kind,
|
|
40
|
+
reason: proposal.reason,
|
|
41
|
+
...getProposalMetadata(proposal),
|
|
42
|
+
resourceName: proposal.toolName,
|
|
43
|
+
canonicalPayloadJson: proposal.argsCanonicalJson,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
proposalHash: proposal.proposalHash,
|
|
48
|
+
kind: proposal.kind,
|
|
49
|
+
reason: proposal.reason,
|
|
50
|
+
...getProposalMetadata(proposal),
|
|
51
|
+
resourceName: proposal.toAgentName,
|
|
52
|
+
canonicalPayloadJson: proposal.payloadCanonicalJson,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function isApprovalGrantActive(grant, now) {
|
|
56
|
+
if (typeof grant.revokedAt !== "undefined") {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
if (typeof grant.expiresAt === "undefined") {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
return (parseTimestamp(grant.expiresAt, "grant.expiresAt") >= getNowTimestamp(now));
|
|
63
|
+
}
|
|
64
|
+
function findActiveApprovalGrant(proposalHash, grants, now) {
|
|
65
|
+
let match = null;
|
|
66
|
+
for (const grant of grants) {
|
|
67
|
+
if (grant.proposalHash !== proposalHash) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (!isApprovalGrantActive(grant, now)) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (!match || isGrantNewer(grant, match)) {
|
|
74
|
+
match = grant;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return match;
|
|
78
|
+
}
|
|
79
|
+
function toActiveApprovalGrantMap(grants, now) {
|
|
80
|
+
const grantMap = {};
|
|
81
|
+
for (const grant of grants) {
|
|
82
|
+
if (!isApprovalGrantActive(grant, now)) {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
const current = grantMap[grant.proposalHash];
|
|
86
|
+
if (!current || isGrantNewer(grant, current)) {
|
|
87
|
+
grantMap[grant.proposalHash] = grant;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return grantMap;
|
|
91
|
+
}
|
|
92
|
+
function toApprovedProposalHashes(grants, now) {
|
|
93
|
+
return Object.keys(toActiveApprovalGrantMap(grants, now));
|
|
94
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from "./agent";
|
|
2
|
+
export * from "./approval-helpers";
|
|
2
3
|
export * from "./config";
|
|
3
4
|
export * from "./errors";
|
|
4
5
|
export * from "./guardrails";
|
|
@@ -13,9 +14,11 @@ export * from "./providers/chat-completions";
|
|
|
13
14
|
export * from "./providers/mistral";
|
|
14
15
|
export * from "./providers/openai";
|
|
15
16
|
export * from "./run";
|
|
17
|
+
export * from "./run-output-events";
|
|
16
18
|
export * from "./run-record";
|
|
17
19
|
export * from "./run-record-utils";
|
|
18
20
|
export * from "./run-context";
|
|
21
|
+
export * from "./thread-history";
|
|
19
22
|
export * from "./tool";
|
|
20
23
|
export * from "./types";
|
|
21
24
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,OAAO,CAAC;AACtB,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,oBAAoB,CAAC;AACnC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,OAAO,CAAC;AACtB,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./agent"), exports);
|
|
18
|
+
__exportStar(require("./approval-helpers"), exports);
|
|
18
19
|
__exportStar(require("./config"), exports);
|
|
19
20
|
__exportStar(require("./errors"), exports);
|
|
20
21
|
__exportStar(require("./guardrails"), exports);
|
|
@@ -29,8 +30,10 @@ __exportStar(require("./providers/chat-completions"), exports);
|
|
|
29
30
|
__exportStar(require("./providers/mistral"), exports);
|
|
30
31
|
__exportStar(require("./providers/openai"), exports);
|
|
31
32
|
__exportStar(require("./run"), exports);
|
|
33
|
+
__exportStar(require("./run-output-events"), exports);
|
|
32
34
|
__exportStar(require("./run-record"), exports);
|
|
33
35
|
__exportStar(require("./run-record-utils"), exports);
|
|
34
36
|
__exportStar(require("./run-context"), exports);
|
|
37
|
+
__exportStar(require("./thread-history"), exports);
|
|
35
38
|
__exportStar(require("./tool"), exports);
|
|
36
39
|
__exportStar(require("./types"), exports);
|
|
@@ -8,6 +8,7 @@ export declare class ChatCompletionsProvider implements ModelProvider {
|
|
|
8
8
|
private baseURL;
|
|
9
9
|
private headers;
|
|
10
10
|
constructor(options: ChatCompletionsProviderOptions);
|
|
11
|
+
protected getInstructionRole(): "system" | "developer";
|
|
11
12
|
stream<TContext = unknown>(request: ProviderRequest<TContext>): AsyncIterable<ProviderEvent>;
|
|
12
13
|
}
|
|
13
14
|
//# sourceMappingURL=chat-completions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-completions.d.ts","sourceRoot":"","sources":["../../src/providers/chat-completions.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAEvE,MAAM,WAAW,8BAA8B;IAC7C,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;
|
|
1
|
+
{"version":3,"file":"chat-completions.d.ts","sourceRoot":"","sources":["../../src/providers/chat-completions.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAEvE,MAAM,WAAW,8BAA8B;IAC7C,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AA8SD,qBAAa,uBAAwB,YAAW,aAAa;IAC3D,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,OAAO,CAAc;gBAEjB,OAAO,EAAE,8BAA8B;IAKnD,SAAS,CAAC,kBAAkB,IAAI,QAAQ,GAAG,WAAW;IAI/C,MAAM,CAAC,QAAQ,GAAG,OAAO,EAC9B,OAAO,EAAE,eAAe,CAAC,QAAQ,CAAC,GACjC,aAAa,CAAC,aAAa,CAAC;CAwHhC"}
|
|
@@ -69,11 +69,11 @@ function normalizeMessageContent(content) {
|
|
|
69
69
|
}
|
|
70
70
|
return stringifySafe(content);
|
|
71
71
|
}
|
|
72
|
-
function toChatMessages(items, systemPrompt) {
|
|
72
|
+
function toChatMessages(items, systemPrompt, instructionRole = "system") {
|
|
73
73
|
const messages = [];
|
|
74
74
|
if (systemPrompt) {
|
|
75
75
|
messages.push({
|
|
76
|
-
role:
|
|
76
|
+
role: instructionRole,
|
|
77
77
|
content: systemPrompt,
|
|
78
78
|
});
|
|
79
79
|
}
|
|
@@ -208,10 +208,13 @@ class ChatCompletionsProvider {
|
|
|
208
208
|
this.baseURL = normalizeBaseURL(options.baseURL);
|
|
209
209
|
this.headers = buildHeaders(options);
|
|
210
210
|
}
|
|
211
|
+
getInstructionRole() {
|
|
212
|
+
return "system";
|
|
213
|
+
}
|
|
211
214
|
async *stream(request) {
|
|
212
215
|
const payload = {
|
|
213
216
|
model: request.model,
|
|
214
|
-
messages: toChatMessages(request.messages, request.systemPrompt),
|
|
217
|
+
messages: toChatMessages(request.messages, request.systemPrompt, this.getInstructionRole()),
|
|
215
218
|
tools: request.tools.length > 0 ? toTools(request.tools) : undefined,
|
|
216
219
|
tool_choice: request.tools.length > 0 ? "auto" : undefined,
|
|
217
220
|
stream: true,
|
|
@@ -7,5 +7,6 @@ export type OpenAIProviderOptions = Omit<ChatCompletionsProviderOptions, "baseUR
|
|
|
7
7
|
};
|
|
8
8
|
export declare class OpenAIProvider extends ChatCompletionsProvider {
|
|
9
9
|
constructor(options: OpenAIProviderOptions);
|
|
10
|
+
protected getInstructionRole(): "developer";
|
|
10
11
|
}
|
|
11
12
|
//# sourceMappingURL=openai.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../src/providers/openai.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,8BAA8B,EAC/B,MAAM,oBAAoB,CAAC;AAE5B,MAAM,MAAM,qBAAqB,GAAG,IAAI,CACtC,8BAA8B,EAC9B,SAAS,GAAG,SAAS,CACtB,GAAG;IACF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC,CAAC;AAcF,qBAAa,cAAe,SAAQ,uBAAuB;gBAC7C,OAAO,EAAE,qBAAqB;
|
|
1
|
+
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../src/providers/openai.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,8BAA8B,EAC/B,MAAM,oBAAoB,CAAC;AAE5B,MAAM,MAAM,qBAAqB,GAAG,IAAI,CACtC,8BAA8B,EAC9B,SAAS,GAAG,SAAS,CACtB,GAAG;IACF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC,CAAC;AAcF,qBAAa,cAAe,SAAQ,uBAAuB;gBAC7C,OAAO,EAAE,qBAAqB;cAQvB,kBAAkB,IAAI,WAAW;CAGrD"}
|
package/dist/providers/openai.js
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Agent } from "./agent";
|
|
2
|
+
import { type ExtractedToolCall } from "./run-record-utils";
|
|
3
|
+
import type { StreamedRunResult } from "./run";
|
|
4
|
+
import type { AgentInputItem, ToolCallItem, ToolCallOutputItem } from "./types";
|
|
5
|
+
export type RunOutputEvent<TContext = unknown> = {
|
|
6
|
+
type: "text_delta";
|
|
7
|
+
delta: string;
|
|
8
|
+
} | {
|
|
9
|
+
type: "completed";
|
|
10
|
+
finalOutput: string;
|
|
11
|
+
history: AgentInputItem[];
|
|
12
|
+
lastAgent: Agent<TContext>;
|
|
13
|
+
toolCalls: ExtractedToolCall[];
|
|
14
|
+
} | {
|
|
15
|
+
type: "agent_updated";
|
|
16
|
+
agent: Agent<TContext>;
|
|
17
|
+
} | {
|
|
18
|
+
type: "tool_call";
|
|
19
|
+
item: ToolCallItem;
|
|
20
|
+
} | {
|
|
21
|
+
type: "tool_output";
|
|
22
|
+
item: ToolCallOutputItem;
|
|
23
|
+
output: unknown;
|
|
24
|
+
toolCall?: ToolCallItem;
|
|
25
|
+
};
|
|
26
|
+
export declare function toRunOutputEvents<TContext = unknown>(result: StreamedRunResult<TContext>, options?: {
|
|
27
|
+
emitAgentUpdates?: boolean;
|
|
28
|
+
emitToolCalls?: boolean;
|
|
29
|
+
emitToolOutputs?: boolean;
|
|
30
|
+
}): AsyncIterable<RunOutputEvent<TContext>>;
|
|
31
|
+
//# sourceMappingURL=run-output-events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-output-events.d.ts","sourceRoot":"","sources":["../src/run-output-events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAoB,KAAK,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAEhF,MAAM,MAAM,cAAc,CAAC,QAAQ,GAAG,OAAO,IACzC;IACE,IAAI,EAAE,YAAY,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;CACf,GACD;IACE,IAAI,EAAE,WAAW,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC3B,SAAS,EAAE,iBAAiB,EAAE,CAAC;CAChC,GACD;IACE,IAAI,EAAE,eAAe,CAAC;IACtB,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;CACxB,GACD;IACE,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,YAAY,CAAC;CACpB,GACD;IACE,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,EAAE,kBAAkB,CAAC;IACzB,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,YAAY,CAAC;CACzB,CAAC;AAEN,wBAAuB,iBAAiB,CAAC,QAAQ,GAAG,OAAO,EACzD,MAAM,EAAE,iBAAiB,CAAC,QAAQ,CAAC,EACnC,OAAO,CAAC,EAAE;IACR,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,GACA,aAAa,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAmEzC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toRunOutputEvents = toRunOutputEvents;
|
|
4
|
+
const run_record_utils_1 = require("./run-record-utils");
|
|
5
|
+
async function* toRunOutputEvents(result, options) {
|
|
6
|
+
const toolCallsById = new Map();
|
|
7
|
+
let finalOutput = "";
|
|
8
|
+
let hasSeenInitialAgent = false;
|
|
9
|
+
for await (const event of result.toStream()) {
|
|
10
|
+
if (event.type === "raw_model_stream_event") {
|
|
11
|
+
if (typeof event.data.delta === "string") {
|
|
12
|
+
yield {
|
|
13
|
+
type: "text_delta",
|
|
14
|
+
delta: event.data.delta,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (event.type === "agent_updated_stream_event") {
|
|
20
|
+
if (!hasSeenInitialAgent) {
|
|
21
|
+
hasSeenInitialAgent = true;
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (options?.emitAgentUpdates) {
|
|
25
|
+
yield {
|
|
26
|
+
type: "agent_updated",
|
|
27
|
+
agent: event.agent,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (event.item.type === "tool_call_item") {
|
|
33
|
+
toolCallsById.set(event.item.callId, event.item);
|
|
34
|
+
if (options?.emitToolCalls) {
|
|
35
|
+
yield {
|
|
36
|
+
type: "tool_call",
|
|
37
|
+
item: event.item,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (event.item.type === "tool_call_output_item") {
|
|
43
|
+
if (options?.emitToolOutputs) {
|
|
44
|
+
const toolCall = toolCallsById.get(event.item.callId);
|
|
45
|
+
yield {
|
|
46
|
+
type: "tool_output",
|
|
47
|
+
item: event.item,
|
|
48
|
+
output: event.item.output,
|
|
49
|
+
...(toolCall ? { toolCall } : {}),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
finalOutput = event.item.content;
|
|
55
|
+
}
|
|
56
|
+
const history = [...result.history];
|
|
57
|
+
yield {
|
|
58
|
+
type: "completed",
|
|
59
|
+
finalOutput,
|
|
60
|
+
history,
|
|
61
|
+
lastAgent: result.lastAgent,
|
|
62
|
+
toolCalls: (0, run_record_utils_1.extractToolCalls)(history),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AgentInputItem, RunResult } from "./types";
|
|
2
|
+
export interface ThreadHistoryState {
|
|
3
|
+
history: AgentInputItem[];
|
|
4
|
+
}
|
|
5
|
+
export type RunHistorySource<TContext = unknown> = Pick<RunResult<TContext>, "history">;
|
|
6
|
+
export declare function toThreadHistory(input: string | readonly AgentInputItem[]): AgentInputItem[];
|
|
7
|
+
export declare function appendUserMessage(history: readonly AgentInputItem[], content: string): AgentInputItem[];
|
|
8
|
+
export declare function replaceThreadHistory<TThread extends ThreadHistoryState>(thread: TThread, history: readonly AgentInputItem[]): TThread;
|
|
9
|
+
export declare function applyRunResultHistory<TContext, TThread extends ThreadHistoryState>(thread: TThread, result: RunHistorySource<TContext>): TThread;
|
|
10
|
+
//# sourceMappingURL=thread-history.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"thread-history.d.ts","sourceRoot":"","sources":["../src/thread-history.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzD,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,cAAc,EAAE,CAAC;CAC3B;AAED,MAAM,MAAM,gBAAgB,CAAC,QAAQ,GAAG,OAAO,IAAI,IAAI,CACrD,SAAS,CAAC,QAAQ,CAAC,EACnB,SAAS,CACV,CAAC;AAEF,wBAAgB,eAAe,CAC7B,KAAK,EAAE,MAAM,GAAG,SAAS,cAAc,EAAE,GACxC,cAAc,EAAE,CAMlB;AAED,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,SAAS,cAAc,EAAE,EAClC,OAAO,EAAE,MAAM,GACd,cAAc,EAAE,CAElB;AAED,wBAAgB,oBAAoB,CAAC,OAAO,SAAS,kBAAkB,EACrE,MAAM,EAAE,OAAO,EACf,OAAO,EAAE,SAAS,cAAc,EAAE,GACjC,OAAO,CAKT;AAED,wBAAgB,qBAAqB,CACnC,QAAQ,EACR,OAAO,SAAS,kBAAkB,EAClC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,gBAAgB,CAAC,QAAQ,CAAC,GAAG,OAAO,CAE9D"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toThreadHistory = toThreadHistory;
|
|
4
|
+
exports.appendUserMessage = appendUserMessage;
|
|
5
|
+
exports.replaceThreadHistory = replaceThreadHistory;
|
|
6
|
+
exports.applyRunResultHistory = applyRunResultHistory;
|
|
7
|
+
const messages_1 = require("./messages");
|
|
8
|
+
function toThreadHistory(input) {
|
|
9
|
+
if (typeof input === "string") {
|
|
10
|
+
return [(0, messages_1.user)(input)];
|
|
11
|
+
}
|
|
12
|
+
return [...input];
|
|
13
|
+
}
|
|
14
|
+
function appendUserMessage(history, content) {
|
|
15
|
+
return [...history, (0, messages_1.user)(content)];
|
|
16
|
+
}
|
|
17
|
+
function replaceThreadHistory(thread, history) {
|
|
18
|
+
return {
|
|
19
|
+
...thread,
|
|
20
|
+
history: [...history],
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function applyRunResultHistory(thread, result) {
|
|
24
|
+
return replaceThreadHistory(thread, result.history);
|
|
25
|
+
}
|