@proposit/proposit-core 2.3.1 → 2.4.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/dist/cli/builder-repl.d.ts +3 -0
- package/dist/cli/builder-repl.d.ts.map +1 -0
- package/dist/cli/builder-repl.js +174 -0
- package/dist/cli/builder-repl.js.map +1 -0
- package/dist/extensions/builder/distill.d.ts +38 -0
- package/dist/extensions/builder/distill.d.ts.map +1 -0
- package/dist/extensions/builder/distill.js +81 -0
- package/dist/extensions/builder/distill.js.map +1 -0
- package/dist/extensions/builder/index.d.ts +7 -0
- package/dist/extensions/builder/index.d.ts.map +1 -0
- package/dist/extensions/builder/index.js +11 -0
- package/dist/extensions/builder/index.js.map +1 -0
- package/dist/extensions/builder/review.d.ts +11 -0
- package/dist/extensions/builder/review.d.ts.map +1 -0
- package/dist/extensions/builder/review.js +32 -0
- package/dist/extensions/builder/review.js.map +1 -0
- package/dist/extensions/builder/simulate.d.ts +12 -0
- package/dist/extensions/builder/simulate.d.ts.map +1 -0
- package/dist/extensions/builder/simulate.js +33 -0
- package/dist/extensions/builder/simulate.js.map +1 -0
- package/dist/extensions/openai/provider.d.ts.map +1 -1
- package/dist/extensions/openai/provider.js +3 -0
- package/dist/extensions/openai/provider.js.map +1 -1
- package/dist/extensions/openai/types.d.ts +2 -0
- package/dist/extensions/openai/types.d.ts.map +1 -1
- package/dist/lib/conversation/contract.d.ts +16 -0
- package/dist/lib/conversation/contract.d.ts.map +1 -0
- package/dist/lib/conversation/contract.js +9 -0
- package/dist/lib/conversation/contract.js.map +1 -0
- package/dist/lib/conversation/conversation.d.ts +43 -0
- package/dist/lib/conversation/conversation.d.ts.map +1 -0
- package/dist/lib/conversation/conversation.js +65 -0
- package/dist/lib/conversation/conversation.js.map +1 -0
- package/dist/lib/conversation/index.d.ts +8 -0
- package/dist/lib/conversation/index.d.ts.map +1 -0
- package/dist/lib/conversation/index.js +7 -0
- package/dist/lib/conversation/index.js.map +1 -0
- package/dist/lib/conversation/turn.d.ts +55 -0
- package/dist/lib/conversation/turn.d.ts.map +1 -0
- package/dist/lib/conversation/turn.js +112 -0
- package/dist/lib/conversation/turn.js.map +1 -0
- package/dist/lib/core/expression-manager-checks.d.ts +73 -0
- package/dist/lib/core/expression-manager-checks.d.ts.map +1 -0
- package/dist/lib/core/expression-manager-checks.js +355 -0
- package/dist/lib/core/expression-manager-checks.js.map +1 -0
- package/dist/lib/core/expression-manager-dirty-set.d.ts +21 -0
- package/dist/lib/core/expression-manager-dirty-set.d.ts.map +1 -0
- package/dist/lib/core/expression-manager-dirty-set.js +93 -0
- package/dist/lib/core/expression-manager-dirty-set.js.map +1 -0
- package/dist/lib/core/expression-manager-invariants.d.ts +14 -0
- package/dist/lib/core/expression-manager-invariants.d.ts.map +1 -0
- package/dist/lib/core/expression-manager-invariants.js +171 -0
- package/dist/lib/core/expression-manager-invariants.js.map +1 -0
- package/dist/lib/core/expression-manager.d.ts +2 -3
- package/dist/lib/core/expression-manager.d.ts.map +1 -1
- package/dist/lib/core/expression-manager.js +18 -523
- package/dist/lib/core/expression-manager.js.map +1 -1
- package/dist/lib/index.d.ts +4 -0
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +6 -0
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/llm/index.d.ts +1 -1
- package/dist/lib/llm/index.d.ts.map +1 -1
- package/dist/lib/llm/types.d.ts +13 -0
- package/dist/lib/llm/types.d.ts.map +1 -1
- package/dist/lib/parsing/prompt-builder.d.ts.map +1 -1
- package/dist/lib/parsing/prompt-builder.js +13 -5
- package/dist/lib/parsing/prompt-builder.js.map +1 -1
- package/dist/lib/pipelines/index.d.ts +4 -2
- package/dist/lib/pipelines/index.d.ts.map +1 -1
- package/dist/lib/pipelines/index.js +2 -1
- package/dist/lib/pipelines/index.js.map +1 -1
- package/dist/lib/pipelines/llm-stage-helpers.d.ts +126 -0
- package/dist/lib/pipelines/llm-stage-helpers.d.ts.map +1 -0
- package/dist/lib/pipelines/llm-stage-helpers.js +567 -0
- package/dist/lib/pipelines/llm-stage-helpers.js.map +1 -0
- package/dist/lib/pipelines/scheduler.d.ts +62 -0
- package/dist/lib/pipelines/scheduler.d.ts.map +1 -0
- package/dist/lib/pipelines/{execute.js → scheduler.js} +8 -325
- package/dist/lib/pipelines/scheduler.js.map +1 -0
- package/dist/lib/pipelines/{execute.d.ts → single-stage.d.ts} +2 -22
- package/dist/lib/pipelines/{execute.d.ts.map → single-stage.d.ts.map} +1 -1
- package/dist/lib/pipelines/single-stage.js +333 -0
- package/dist/lib/pipelines/single-stage.js.map +1 -0
- package/dist/lib/pipelines/stage-helpers.d.ts +4 -123
- package/dist/lib/pipelines/stage-helpers.d.ts.map +1 -1
- package/dist/lib/pipelines/stage-helpers.js +28 -567
- package/dist/lib/pipelines/stage-helpers.js.map +1 -1
- package/package.json +13 -3
- package/dist/lib/pipelines/execute.js.map +0 -1
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Stateful conversation primitive for interactive, user-driven multi-turn
|
|
2
|
+
// LLM exchanges.
|
|
3
|
+
//
|
|
4
|
+
// Holds the response-ID chain and cumulative token usage. The user
|
|
5
|
+
// decides which turn runs next, in any amount and order, until a
|
|
6
|
+
// terminal `finalize` turn ends it.
|
|
7
|
+
//
|
|
8
|
+
// A conversation is NOT a pipeline. It is a thin, builder-agnostic
|
|
9
|
+
// stateful object that threads response-IDs and tallies tokens.
|
|
10
|
+
import { executeTurn } from "./turn.js";
|
|
11
|
+
/** Thrown when `.turn` is called on a closed conversation. */
|
|
12
|
+
export class ConversationClosedError extends Error {
|
|
13
|
+
constructor() {
|
|
14
|
+
super("Conversation is closed — no more turns allowed.");
|
|
15
|
+
this.name = "ConversationClosedError";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
// -- createConversation ----------------------------------------------------
|
|
19
|
+
/**
|
|
20
|
+
* Create a new stateful conversation object.
|
|
21
|
+
*
|
|
22
|
+
* The conversation holds the response-ID chain and cumulative token
|
|
23
|
+
* usage. Each `.turn(...)` call executes a single stage through the
|
|
24
|
+
* conversation primitive's execution path, threading `previousResponseId`
|
|
25
|
+
* so the provider can chain against the upstream response.
|
|
26
|
+
*/
|
|
27
|
+
export function createConversation(deps) {
|
|
28
|
+
let closed = false;
|
|
29
|
+
let lastResponseId = null;
|
|
30
|
+
let cumulativeTokens = { input: 0, output: 0 };
|
|
31
|
+
return {
|
|
32
|
+
async turn(stage, input, opts) {
|
|
33
|
+
if (closed) {
|
|
34
|
+
throw new ConversationClosedError();
|
|
35
|
+
}
|
|
36
|
+
const turnInput = {
|
|
37
|
+
userMessage: input.userMessage,
|
|
38
|
+
previousResponseId: opts?.branchFrom ?? lastResponseId ?? undefined,
|
|
39
|
+
};
|
|
40
|
+
const result = await executeTurn(stage, turnInput, {
|
|
41
|
+
...deps,
|
|
42
|
+
onComplete: opts?.onComplete,
|
|
43
|
+
});
|
|
44
|
+
lastResponseId = result.responseId;
|
|
45
|
+
cumulativeTokens = {
|
|
46
|
+
input: cumulativeTokens.input + result.tokenUsage.input,
|
|
47
|
+
output: cumulativeTokens.output + result.tokenUsage.output,
|
|
48
|
+
};
|
|
49
|
+
return result;
|
|
50
|
+
},
|
|
51
|
+
get lastResponseId() {
|
|
52
|
+
return lastResponseId;
|
|
53
|
+
},
|
|
54
|
+
get tokenUsage() {
|
|
55
|
+
return cumulativeTokens;
|
|
56
|
+
},
|
|
57
|
+
get closed() {
|
|
58
|
+
return closed;
|
|
59
|
+
},
|
|
60
|
+
close() {
|
|
61
|
+
closed = true;
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=conversation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversation.js","sourceRoot":"","sources":["../../../src/lib/conversation/conversation.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,iBAAiB;AACjB,EAAE;AACF,mEAAmE;AACnE,iEAAiE;AACjE,o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ACzB,CAAC;QAED,IAAI,UAAU;YACV,OAAO,gBAAgB,CAAA;QAC3B,CAAC;QAED,IAAI,MAAM;YACN,OAAO,MAAM,CAAA;QACjB,CAAC;QAED,KAAK;YACD,MAAM,GAAG,IAAI,CAAA;QACjB,CAAC;KACJ,CAAA;AACL,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { executeTurn } from "./turn.js";
|
|
2
|
+
export type { TTurnInput, TTurnResult, TExecuteTurnDeps } from "./turn.js";
|
|
3
|
+
export { createConversation } from "./conversation.js";
|
|
4
|
+
export type { TConversation } from "./conversation.js";
|
|
5
|
+
export { ConversationClosedError } from "./conversation.js";
|
|
6
|
+
export type { TMultiTurnInput, TMultiTurnOutput } from "./contract.js";
|
|
7
|
+
export type { TResponseId } from "../llm/types.js";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/conversation/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AACvC,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAA;AAE1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AACtD,YAAY,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAA;AAE3D,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AACtE,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Barrel export for the conversation primitive module.
|
|
2
|
+
//
|
|
3
|
+
// Subpath: @proposit/proposit-core/conversation
|
|
4
|
+
export { executeTurn } from "./turn.js";
|
|
5
|
+
export { createConversation } from "./conversation.js";
|
|
6
|
+
export { ConversationClosedError } from "./conversation.js";
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/conversation/index.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,EAAE;AACF,gDAAgD;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAGvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAEtD,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAA"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { TStage, TProcessingFailure, TPipelineEvent } from "../pipelines/types.js";
|
|
2
|
+
import type { TLlmProvider, TLlmTokenUsage, TResponseId } from "../llm/types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Input supplied to a single conversational turn. The caller is
|
|
5
|
+
* responsible for assembling the user message (which may include the
|
|
6
|
+
* full transcript when the provider cannot chain by reference).
|
|
7
|
+
*/
|
|
8
|
+
export type TTurnInput = {
|
|
9
|
+
/** The user message for this turn. */
|
|
10
|
+
userMessage: string;
|
|
11
|
+
/** The provider response id to chain against; absent for the first turn. */
|
|
12
|
+
previousResponseId?: TResponseId;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Result of a single conversational turn. Mirrors the shape the
|
|
16
|
+
* server's Argument Builder actions need: output, the new response id,
|
|
17
|
+
* token usage, and any processing failures.
|
|
18
|
+
*/
|
|
19
|
+
export type TTurnResult<TOut> = {
|
|
20
|
+
/** The stage's parsed output, or `null` when the turn failed. */
|
|
21
|
+
output: TOut | null;
|
|
22
|
+
/** The provider response id for this turn (nullable for
|
|
23
|
+
* non-chaining providers such as chat-completions). */
|
|
24
|
+
responseId: TResponseId | null;
|
|
25
|
+
/** Cumulative token usage for this turn's LLM call. */
|
|
26
|
+
tokenUsage: TLlmTokenUsage;
|
|
27
|
+
/** Processing failures recorded during the turn. */
|
|
28
|
+
failures: TProcessingFailure[];
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Minimal dependencies for a single-turn execution. A subset of the
|
|
32
|
+
* full pipeline deps — no concurrency or pipeline-level bookkeeping.
|
|
33
|
+
*/
|
|
34
|
+
export type TExecuteTurnDeps = {
|
|
35
|
+
llm: TLlmProvider;
|
|
36
|
+
signal?: AbortSignal;
|
|
37
|
+
onEvent?: (event: TPipelineEvent) => void;
|
|
38
|
+
/** Called after the stage completes (after retry loop + validation).
|
|
39
|
+
* Useful for terminal turns that need to seal a conversation. */
|
|
40
|
+
onComplete?: () => void;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Run one conversational turn: execute the stage through the single-stage
|
|
44
|
+
* executor (preserving retry loop, output-schema validation, event
|
|
45
|
+
* emission, token accounting) while threading `previousResponseId` into
|
|
46
|
+
* the LLM request and surfacing the provider response id.
|
|
47
|
+
*
|
|
48
|
+
* Uses a synthetic pipeline so `executeStage` can run the arbitrary stage
|
|
49
|
+
* through the same execution machinery the full pipeline uses. The stage's
|
|
50
|
+
* own `dependsOn` are preserved; since no upstream stages exist, any
|
|
51
|
+
* dependencies that are satisfied will be `completed` (they simply don't
|
|
52
|
+
* exist, so `ctx.get` returns `undefined` for them).
|
|
53
|
+
*/
|
|
54
|
+
export declare function executeTurn<TOut>(stage: TStage<TOut>, input: TTurnInput, deps: TExecuteTurnDeps): Promise<TTurnResult<TOut>>;
|
|
55
|
+
//# sourceMappingURL=turn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"turn.d.ts","sourceRoot":"","sources":["../../../src/lib/conversation/turn.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EACR,MAAM,EACN,kBAAkB,EAClB,cAAc,EACjB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAShF;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG;IACrB,sCAAsC;IACtC,WAAW,EAAE,MAAM,CAAA;IACnB,4EAA4E;IAC5E,kBAAkB,CAAC,EAAE,WAAW,CAAA;CACnC,CAAA;AAED;;;;GAIG;AACH,MAAM,MAAM,WAAW,CAAC,IAAI,IAAI;IAC5B,iEAAiE;IACjE,MAAM,EAAE,IAAI,GAAG,IAAI,CAAA;IACnB;2DACuD;IACvD,UAAU,EAAE,WAAW,GAAG,IAAI,CAAA;IAC9B,uDAAuD;IACvD,UAAU,EAAE,cAAc,CAAA;IAC1B,oDAAoD;IACpD,QAAQ,EAAE,kBAAkB,EAAE,CAAA;CACjC,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC3B,GAAG,EAAE,YAAY,CAAA;IACjB,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAA;IACzC;qEACiE;IACjE,UAAU,CAAC,EAAE,MAAM,IAAI,CAAA;CAC1B,CAAA;AA+CD;;;;;;;;;;;GAWG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAClC,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,EACnB,KAAK,EAAE,UAAU,EACjB,IAAI,EAAE,gBAAgB,GACvB,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CA6D5B"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// Stateless single-turn execution primitive.
|
|
2
|
+
//
|
|
3
|
+
// Wraps one `TStage` run with the full pipeline machinery (retry loop,
|
|
4
|
+
// output-schema validation, event emission, token accounting) and
|
|
5
|
+
// threads `previousResponseId` into the LLM request so the provider can
|
|
6
|
+
// chain against the upstream response. Surfaces the provider response id
|
|
7
|
+
// so the caller can forward it on the next turn.
|
|
8
|
+
//
|
|
9
|
+
// This is the shared substrate for both:
|
|
10
|
+
// - the server's stateless per-request executor (threads the chain
|
|
11
|
+
// from the client-supplied `lastResponseId`)
|
|
12
|
+
// - the CLI's stateful conversation object (accumulates the chain)
|
|
13
|
+
import { executeStage } from "../pipelines/single-stage.js";
|
|
14
|
+
import { Value } from "typebox/value";
|
|
15
|
+
import Type from "typebox";
|
|
16
|
+
// -- Internal: module-level bridge for user message ------------------------
|
|
17
|
+
//
|
|
18
|
+
// `llmStage` builds its user message from `buildPrompt(ctx)`. To override
|
|
19
|
+
// it without modifying the stage, we use a module-level variable that the
|
|
20
|
+
// provider wrapper reads. This keeps `executeTurn`'s signature clean
|
|
21
|
+
// while still letting the caller supply the actual user message.
|
|
22
|
+
//
|
|
23
|
+
// The variable is set synchronously before `executeStage` and cleared
|
|
24
|
+
// after it resolves, so it's safe for sequential (non-concurrent) use.
|
|
25
|
+
let currentTurnInput = null;
|
|
26
|
+
// -- Internal: LLM provider wrapper ----------------------------------------
|
|
27
|
+
//
|
|
28
|
+
// Wraps the underlying provider to inject `previousResponseId` into each
|
|
29
|
+
// `respond` call and capture the surfaced response id. Also overrides the
|
|
30
|
+
// user message via the module-level bridge so `llmStage`'s `buildPrompt`
|
|
31
|
+
// user message is replaced with the caller-supplied one.
|
|
32
|
+
function wrapProviderForTurn(llm, previousResponseId, captured) {
|
|
33
|
+
const underlying = llm;
|
|
34
|
+
return {
|
|
35
|
+
async respond(req) {
|
|
36
|
+
// Inject `previousResponseId` into the request.
|
|
37
|
+
req.previousResponseId = previousResponseId;
|
|
38
|
+
// Override user message via the module-level bridge.
|
|
39
|
+
if (currentTurnInput) {
|
|
40
|
+
req.userMessage = currentTurnInput.userMessage;
|
|
41
|
+
}
|
|
42
|
+
const response = await underlying.respond(req);
|
|
43
|
+
// Capture the response id if surfaced.
|
|
44
|
+
if (response.rawResponseId) {
|
|
45
|
+
captured.responseId = response.rawResponseId;
|
|
46
|
+
}
|
|
47
|
+
return response;
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
// -- executeTurn -----------------------------------------------------------
|
|
52
|
+
/**
|
|
53
|
+
* Run one conversational turn: execute the stage through the single-stage
|
|
54
|
+
* executor (preserving retry loop, output-schema validation, event
|
|
55
|
+
* emission, token accounting) while threading `previousResponseId` into
|
|
56
|
+
* the LLM request and surfacing the provider response id.
|
|
57
|
+
*
|
|
58
|
+
* Uses a synthetic pipeline so `executeStage` can run the arbitrary stage
|
|
59
|
+
* through the same execution machinery the full pipeline uses. The stage's
|
|
60
|
+
* own `dependsOn` are preserved; since no upstream stages exist, any
|
|
61
|
+
* dependencies that are satisfied will be `completed` (they simply don't
|
|
62
|
+
* exist, so `ctx.get` returns `undefined` for them).
|
|
63
|
+
*/
|
|
64
|
+
export async function executeTurn(stage, input, deps) {
|
|
65
|
+
// Capture the response id from the provider's response.
|
|
66
|
+
const captured = {
|
|
67
|
+
responseId: null,
|
|
68
|
+
};
|
|
69
|
+
// Wrap the LLM provider to inject `previousResponseId` and capture
|
|
70
|
+
// the response id.
|
|
71
|
+
const wrapped = wrapProviderForTurn(deps.llm, input.previousResponseId, captured);
|
|
72
|
+
// Bridge the user message to the provider wrapper.
|
|
73
|
+
currentTurnInput = input;
|
|
74
|
+
// Create a synthetic pipeline containing just this stage.
|
|
75
|
+
const stageId = stage.id;
|
|
76
|
+
const pipeline = {
|
|
77
|
+
id: "turn",
|
|
78
|
+
version: "0.0.0",
|
|
79
|
+
inputSchema: Value.Check(TypeAnySchema, {})
|
|
80
|
+
? TypeAnySchema
|
|
81
|
+
: Type.Object({}),
|
|
82
|
+
outputSchema: stage.outputSchema,
|
|
83
|
+
stages: [stage],
|
|
84
|
+
finalize: {
|
|
85
|
+
dependsOn: [stageId],
|
|
86
|
+
run: (ctx) => ctx.get(stageId),
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
// Run the stage through the single-stage executor.
|
|
90
|
+
const upstream = {};
|
|
91
|
+
const result = await executeStage(pipeline, stageId, upstream, {}, {
|
|
92
|
+
llm: wrapped,
|
|
93
|
+
signal: deps.signal,
|
|
94
|
+
onEvent: deps.onEvent,
|
|
95
|
+
});
|
|
96
|
+
// Clear the user message bridge.
|
|
97
|
+
currentTurnInput = null;
|
|
98
|
+
// Call the completion callback (for terminal turns like finalize).
|
|
99
|
+
deps.onComplete?.();
|
|
100
|
+
return {
|
|
101
|
+
output: (result.outcome === "completed"
|
|
102
|
+
? (result.output ?? null)
|
|
103
|
+
: null),
|
|
104
|
+
responseId: captured.responseId,
|
|
105
|
+
tokenUsage: result.tokenUsage ?? { input: 0, output: 0 },
|
|
106
|
+
failures: result.failures,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
// -- Minimal `Type.Any()` without importing TypeBox ------------------------
|
|
110
|
+
// Used as the synthetic pipeline's input schema.
|
|
111
|
+
const TypeAnySchema = { type: "any" };
|
|
112
|
+
//# sourceMappingURL=turn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"turn.js","sourceRoot":"","sources":["../../../src/lib/conversation/turn.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,EAAE;AACF,uEAAuE;AACvE,kEAAkE;AAClE,wEAAwE;AACxE,yEAAyE;AACzE,iDAAiD;AACjD,EAAE;AACF,yCAAyC;AACzC,qEAAqE;AACrE,iDAAiD;AACjD,qEAAqE;AAQrE,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAG3D,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AACrC,OAAO,IAAI,MAAM,SAAS,CAAA;AA8C1B,6EAA6E;AAC7E,EAAE;AACF,0EAA0E;AAC1E,0EAA0E;AAC1E,qEAAqE;AACrE,iEAAiE;AACjE,EAAE;AACF,sEAAsE;AACtE,uEAAuE;AAEvE,IAAI,gBAAgB,GAAsB,IAAI,CAAA;AAE9C,6EAA6E;AAC7E,EAAE;AACF,yEAAyE;AACzE,0EAA0E;AAC1E,yEAAyE;AACzE,yDAAyD;AAEzD,SAAS,mBAAmB,CACxB,GAAiB,EACjB,kBAA2C,EAC3C,QAA4C;IAE5C,MAAM,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CAAC;QACf,QAAQ,EAAE;YACN,SAAS,EAAE,CAAC,OAAO,CAAC;YACpB,GAAG,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAS;SACzC;KACJ,CAAA;IAED,mDAAmD;IACnD,MAAM,QAAQ,GAAwC,EAAE,CAAA;IACxD,MAAM,MAAM,GAAG,MAAM,YAAY,CAC7B,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,EAAE,EACF;QACI,GAAG,EAAE,OAAO;QACZ,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,OAAO,EAAE,IAAI,CAAC,OAAO;KACxB,CACJ,CAAA;IAED,iCAAiC;IACjC,gBAAgB,GAAG,IAAI,CAAA;IAEvB,mEAAmE;IACnE,IAAI,CAAC,UAAU,EAAE,EAAE,CAAA;IAEnB,OAAO;QACH,MAAM,EAAE,CAAC,MAAM,CAAC,OAAO,KAAK,WAAW;YACnC,CAAC,CAAC,CAAE,MAAM,CAAC,MAAkC,IAAI,IAAI,CAAC;YACtD,CAAC,CAAC,IAAI,CAAgB;QAC1B,UAAU,EAAE,QAAQ,CAAC,UAAU;QAC/B,UAAU,EAAE,MAAM,CAAC,UAAU,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE;QACxD,QAAQ,EAAE,MAAM,CAAC,QAAQ;KAC5B,CAAA;AACL,CAAC;AAED,6EAA6E;AAC7E,iDAAiD;AAEjD,MAAM,aAAa,GAAY,EAAE,IAAI,EAAE,KAAK,EAAE,CAAA"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { TCorePropositionalExpression } from "../schemata/index.js";
|
|
2
|
+
import type { TCorePositionConfig } from "../utils/position.js";
|
|
3
|
+
import type { TExpressionInput, TExpressionWithoutPosition, TExpressionUpdate } from "./expression-manager.js";
|
|
4
|
+
/**
|
|
5
|
+
* Validates the preconditions for `ExpressionManager.insertExpression`
|
|
6
|
+
* (existence, arity, and root-only-operator rules) and returns the anchor
|
|
7
|
+
* slot the new expression inherits.
|
|
8
|
+
*
|
|
9
|
+
* @throws Under the same conditions documented on `insertExpression`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function validateInsertExpression<TExpr extends TCorePropositionalExpression>(expression: TExpressionInput<TExpr>, leftNodeId: string | undefined, rightNodeId: string | undefined, expressions: Map<string, TExpr>): {
|
|
12
|
+
anchorParentId: string | null;
|
|
13
|
+
anchorPosition: number;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Validates the preconditions for `ExpressionManager.wrapExpression`
|
|
17
|
+
* (existence, arity, and root-only-operator rules) and returns the existing
|
|
18
|
+
* node's ID plus the anchor slot the operator inherits.
|
|
19
|
+
*
|
|
20
|
+
* @throws Under the same conditions documented on `wrapExpression`.
|
|
21
|
+
*/
|
|
22
|
+
export declare function validateWrapExpression<TExpr extends TCorePropositionalExpression>(operator: TExpressionWithoutPosition<TExpr>, newSibling: TExpressionWithoutPosition<TExpr>, leftNodeId: string | undefined, rightNodeId: string | undefined, expressions: Map<string, TExpr>): {
|
|
23
|
+
existingNodeId: string;
|
|
24
|
+
anchorParentId: string | null;
|
|
25
|
+
anchorPosition: number;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Computes the sibling-position redistribution range for
|
|
29
|
+
* `ExpressionManager.repositionSiblings`: which contiguous run of
|
|
30
|
+
* `children` to shift, and the bounds to spread them across.
|
|
31
|
+
*
|
|
32
|
+
* @throws If neither direction has enough space to redistribute into.
|
|
33
|
+
*/
|
|
34
|
+
export declare function validateRepositionSiblings<TExpr extends TCorePropositionalExpression>(children: TExpr[], leftPos: number, rightPos: number, positionConfig: TCorePositionConfig): {
|
|
35
|
+
startIdx: number;
|
|
36
|
+
endIdx: number;
|
|
37
|
+
lowerBound: number;
|
|
38
|
+
upperBound: number;
|
|
39
|
+
count: number;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Validates the preconditions for `ExpressionManager.updateExpression`
|
|
43
|
+
* and, when the update includes a position change, performs the sibling
|
|
44
|
+
* position-set swap (delete old position, reject or accept the new one).
|
|
45
|
+
*
|
|
46
|
+
* Mutates `childPositionsByParentId` in place when a position update is
|
|
47
|
+
* accepted — this is the one check in this module that isn't a pure
|
|
48
|
+
* throw-or-void helper, since the swap must happen atomically with the
|
|
49
|
+
* collision check to avoid leaving the position set inconsistent.
|
|
50
|
+
*
|
|
51
|
+
* @throws Under the same conditions documented on `updateExpression`.
|
|
52
|
+
*/
|
|
53
|
+
export declare function validateUpdateExpression<TExpr extends TCorePropositionalExpression>(expressionId: string, expression: TExpr, updates: TExpressionUpdate, childPositionsByParentId: Map<string | null, Set<number>>): void;
|
|
54
|
+
/**
|
|
55
|
+
* Validates the preconditions for the single-child-promotion branch of
|
|
56
|
+
* `ExpressionManager.removeAndPromote` and returns which of the two
|
|
57
|
+
* branches applies.
|
|
58
|
+
*
|
|
59
|
+
* @throws If `target` has more than one child.
|
|
60
|
+
* @throws If the single child is a root-only operator (`implies`/`iff`)
|
|
61
|
+
* that would be placed in a non-root position.
|
|
62
|
+
* @returns The child to promote, or `undefined` for a plain leaf removal.
|
|
63
|
+
*/
|
|
64
|
+
export declare function validateRemoveAndPromote<TExpr extends TCorePropositionalExpression>(expressionId: string, target: TExpr, children: TExpr[]): TExpr | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Validates the preconditions for
|
|
67
|
+
* `ExpressionManager.addExpressionRelative` and returns the sibling
|
|
68
|
+
* looked up by ID.
|
|
69
|
+
*
|
|
70
|
+
* @throws If the sibling does not exist.
|
|
71
|
+
*/
|
|
72
|
+
export declare function validateAddExpressionRelative<TExpr extends TCorePropositionalExpression>(siblingId: string, expressions: Map<string, TExpr>): TExpr;
|
|
73
|
+
//# sourceMappingURL=expression-manager-checks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expression-manager-checks.d.ts","sourceRoot":"","sources":["../../../src/lib/core/expression-manager-checks.ts"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