@axiastudio/aioc 0.1.0 → 0.1.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/README.md CHANGED
@@ -8,12 +8,14 @@ Project home and documentation: [https://axiastudio.github.io/aioc](https://axia
8
8
 
9
9
  ## Release Status
10
10
 
11
- This package is stable as of `0.1.0`.
11
+ Current stable release: `0.1.1`.
12
+ AIOC is stable as of `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` stabilizes 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.
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.
17
19
 
18
20
  - Release notes: `CHANGELOG.md`
19
21
  - Historical beta contract snapshot: `docs/BETA-CONTRACT.md`
@@ -97,7 +99,9 @@ console.log(result.finalOutput);
97
99
  - provider setup helpers `setupMistral(...)`, `setupOpenAI(...)`, `setupProvider(...)`
98
100
  - run logger hook `run(..., { logger })`
99
101
  - run record hook `run(..., { record })`
102
+ - run output adapter `toRunOutputEvents(...)`
100
103
  - run-record utilities `extractToolCalls(...)`, `compareRunRecords(...)`, `replayFromRunRecord(...)`
104
+ - thread history utilities `toThreadHistory(...)`, `appendUserMessage(...)`, `replaceThreadHistory(...)`, `applyRunResultHistory(...)`
101
105
  - JSON helper `toJsonValue(...)`
102
106
 
103
107
  ## Policy Gate (Minimal)
@@ -259,9 +263,10 @@ AIOC adopts the following non-negotiable principles:
259
263
  - `docs/RFC-0002-policy-gates-for-tools-and-handoffs.md` (`Accepted`)
260
264
  - `docs/RFC-0003-run-record-audit-trail-and-persistence.md` (`Accepted`)
261
265
  - `docs/RFC-0004-policy-outcomes-and-approval-model.md` (`Accepted`)
262
- - `docs/RFC-0005-suspended-proposals-and-approval-lifecycle.md` (`Draft`)
266
+ - `docs/RFC-0005-suspended-proposals-and-approval-lifecycle.md` (`Accepted`)
263
267
  - `docs/RFC-0006-approval-evidence-helpers.md` (`Draft`)
264
- - `docs/RFC-0007-thread-state-utilities.md` (`Draft`)
268
+ - `docs/RFC-0007-thread-state-utilities.md` (`Accepted`)
269
+ - `docs/RFC-0008-run-stream-consumer-utilities.md` (`Accepted`)
265
270
  - `docs/PRIVACY-BASELINE.md`
266
271
 
267
272
  ## Historical Snapshots
package/dist/index.d.ts CHANGED
@@ -13,9 +13,11 @@ export * from "./providers/chat-completions";
13
13
  export * from "./providers/mistral";
14
14
  export * from "./providers/openai";
15
15
  export * from "./run";
16
+ export * from "./run-output-events";
16
17
  export * from "./run-record";
17
18
  export * from "./run-record-utils";
18
19
  export * from "./run-context";
20
+ export * from "./thread-history";
19
21
  export * from "./tool";
20
22
  export * from "./types";
21
23
  //# sourceMappingURL=index.d.ts.map
@@ -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,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
@@ -29,8 +29,10 @@ __exportStar(require("./providers/chat-completions"), exports);
29
29
  __exportStar(require("./providers/mistral"), exports);
30
30
  __exportStar(require("./providers/openai"), exports);
31
31
  __exportStar(require("./run"), exports);
32
+ __exportStar(require("./run-output-events"), exports);
32
33
  __exportStar(require("./run-record"), exports);
33
34
  __exportStar(require("./run-record-utils"), exports);
34
35
  __exportStar(require("./run-context"), exports);
36
+ __exportStar(require("./thread-history"), exports);
35
37
  __exportStar(require("./tool"), exports);
36
38
  __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;AA6SD,qBAAa,uBAAwB,YAAW,aAAa;IAC3D,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,OAAO,CAAc;gBAEjB,OAAO,EAAE,8BAA8B;IAK5C,MAAM,CAAC,QAAQ,GAAG,OAAO,EAC9B,OAAO,EAAE,eAAe,CAAC,QAAQ,CAAC,GACjC,aAAa,CAAC,aAAa,CAAC;CAoHhC"}
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: "system",
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;CAO3C"}
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"}
@@ -19,5 +19,8 @@ class OpenAIProvider extends chat_completions_1.ChatCompletionsProvider {
19
19
  headers: toOpenAIHeaders(options),
20
20
  });
21
21
  }
22
+ getInstructionRole() {
23
+ return "developer";
24
+ }
22
25
  }
23
26
  exports.OpenAIProvider = OpenAIProvider;
@@ -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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axiastudio/aioc",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [