@orkestrel/agent 0.0.12 → 0.0.13
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.
|
@@ -4,6 +4,7 @@ import { DriverInterface } from '@orkestrel/database';
|
|
|
4
4
|
import { EmitterErrorHandler } from '@orkestrel/emitter';
|
|
5
5
|
import { EmitterHooks } from '@orkestrel/emitter';
|
|
6
6
|
import { EmitterInterface } from '@orkestrel/emitter';
|
|
7
|
+
import { JSONValue } from '@orkestrel/contract';
|
|
7
8
|
import { QueueExecution } from '@orkestrel/queue';
|
|
8
9
|
import { QueueInterface } from '@orkestrel/queue';
|
|
9
10
|
import { QueueStoreInterface } from '@orkestrel/queue';
|
|
@@ -848,6 +849,32 @@ export declare interface AgentResult {
|
|
|
848
849
|
readonly partial: boolean;
|
|
849
850
|
}
|
|
850
851
|
|
|
852
|
+
/**
|
|
853
|
+
* Project an unknown value onto the canonical JSON representation of an
|
|
854
|
+
* {@link AgentResult}.
|
|
855
|
+
*
|
|
856
|
+
* @remarks
|
|
857
|
+
* This is a total hostile-boundary projection. Each structural field is captured once
|
|
858
|
+
* through Contract's sanctioned exception boundary, so conforming accessors and inherited
|
|
859
|
+
* properties are supported while a throwing getter or revoked proxy returns `undefined`.
|
|
860
|
+
* Present usage counts must be finite numbers; negative and fractional values are preserved,
|
|
861
|
+
* not normalized. Extra input properties are dropped while a fresh exact plain object is rebuilt
|
|
862
|
+
* and deep-gated through
|
|
863
|
+
* {@link import('@orkestrel/contract').parseJSONValue}.
|
|
864
|
+
*
|
|
865
|
+
* @param value - The unknown value to project
|
|
866
|
+
* @returns A fresh JSON value containing only AgentResult fields, or `undefined` when invalid
|
|
867
|
+
*
|
|
868
|
+
* @example
|
|
869
|
+
* ```ts
|
|
870
|
+
* import { agentResultToJSON } from '@orkestrel/agent'
|
|
871
|
+
*
|
|
872
|
+
* agentResultToJSON({ content: 'done', usage: { prompt: 2, completion: 1, total: 3 }, partial: false })
|
|
873
|
+
* // { content: 'done', usage: { prompt: 2, completion: 1, total: 3 }, partial: false }
|
|
874
|
+
* ```
|
|
875
|
+
*/
|
|
876
|
+
export declare function agentResultToJSON(value: unknown): JSONValue | undefined;
|
|
877
|
+
|
|
851
878
|
/**
|
|
852
879
|
* Options for `createAgentRunner` — the registry that rehydrates jobs, the partial-result
|
|
853
880
|
* policy, and the substrate knobs threaded into the backing `createRunner`.
|
package/dist/src/core/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { DriverInterface } from '@orkestrel/database';
|
|
|
4
4
|
import { EmitterErrorHandler } from '@orkestrel/emitter';
|
|
5
5
|
import { EmitterHooks } from '@orkestrel/emitter';
|
|
6
6
|
import { EmitterInterface } from '@orkestrel/emitter';
|
|
7
|
+
import { JSONValue } from '@orkestrel/contract';
|
|
7
8
|
import { QueueExecution } from '@orkestrel/queue';
|
|
8
9
|
import { QueueInterface } from '@orkestrel/queue';
|
|
9
10
|
import { QueueStoreInterface } from '@orkestrel/queue';
|
|
@@ -848,6 +849,32 @@ export declare interface AgentResult {
|
|
|
848
849
|
readonly partial: boolean;
|
|
849
850
|
}
|
|
850
851
|
|
|
852
|
+
/**
|
|
853
|
+
* Project an unknown value onto the canonical JSON representation of an
|
|
854
|
+
* {@link AgentResult}.
|
|
855
|
+
*
|
|
856
|
+
* @remarks
|
|
857
|
+
* This is a total hostile-boundary projection. Each structural field is captured once
|
|
858
|
+
* through Contract's sanctioned exception boundary, so conforming accessors and inherited
|
|
859
|
+
* properties are supported while a throwing getter or revoked proxy returns `undefined`.
|
|
860
|
+
* Present usage counts must be finite numbers; negative and fractional values are preserved,
|
|
861
|
+
* not normalized. Extra input properties are dropped while a fresh exact plain object is rebuilt
|
|
862
|
+
* and deep-gated through
|
|
863
|
+
* {@link import('@orkestrel/contract').parseJSONValue}.
|
|
864
|
+
*
|
|
865
|
+
* @param value - The unknown value to project
|
|
866
|
+
* @returns A fresh JSON value containing only AgentResult fields, or `undefined` when invalid
|
|
867
|
+
*
|
|
868
|
+
* @example
|
|
869
|
+
* ```ts
|
|
870
|
+
* import { agentResultToJSON } from '@orkestrel/agent'
|
|
871
|
+
*
|
|
872
|
+
* agentResultToJSON({ content: 'done', usage: { prompt: 2, completion: 1, total: 3 }, partial: false })
|
|
873
|
+
* // { content: 'done', usage: { prompt: 2, completion: 1, total: 3 }, partial: false }
|
|
874
|
+
* ```
|
|
875
|
+
*/
|
|
876
|
+
export declare function agentResultToJSON(value: unknown): JSONValue | undefined;
|
|
877
|
+
|
|
851
878
|
/**
|
|
852
879
|
* Options for `createAgentRunner` — the registry that rehydrates jobs, the partial-result
|
|
853
880
|
* policy, and the substrate knobs threaded into the backing `createRunner`.
|
package/dist/src/core/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isArray, isRecord, isString, rawShape, stringShape } from "@orkestrel/contract";
|
|
1
|
+
import { attempt, isArray, isBoolean, isFiniteNumber, isObject, isRecord, isString, parseJSONValue, rawShape, stringShape } from "@orkestrel/contract";
|
|
2
2
|
import { createDatabase, createMemoryDriver } from "@orkestrel/database";
|
|
3
3
|
import { createQueue } from "@orkestrel/queue";
|
|
4
4
|
import { createDeferred, createRunner } from "@orkestrel/workflow";
|
|
@@ -582,6 +582,61 @@ var ConversationManager = class {
|
|
|
582
582
|
//#endregion
|
|
583
583
|
//#region src/core/helpers.ts
|
|
584
584
|
/**
|
|
585
|
+
* Project an unknown value onto the canonical JSON representation of an
|
|
586
|
+
* {@link AgentResult}.
|
|
587
|
+
*
|
|
588
|
+
* @remarks
|
|
589
|
+
* This is a total hostile-boundary projection. Each structural field is captured once
|
|
590
|
+
* through Contract's sanctioned exception boundary, so conforming accessors and inherited
|
|
591
|
+
* properties are supported while a throwing getter or revoked proxy returns `undefined`.
|
|
592
|
+
* Present usage counts must be finite numbers; negative and fractional values are preserved,
|
|
593
|
+
* not normalized. Extra input properties are dropped while a fresh exact plain object is rebuilt
|
|
594
|
+
* and deep-gated through
|
|
595
|
+
* {@link import('@orkestrel/contract').parseJSONValue}.
|
|
596
|
+
*
|
|
597
|
+
* @param value - The unknown value to project
|
|
598
|
+
* @returns A fresh JSON value containing only AgentResult fields, or `undefined` when invalid
|
|
599
|
+
*
|
|
600
|
+
* @example
|
|
601
|
+
* ```ts
|
|
602
|
+
* import { agentResultToJSON } from '@orkestrel/agent'
|
|
603
|
+
*
|
|
604
|
+
* agentResultToJSON({ content: 'done', usage: { prompt: 2, completion: 1, total: 3 }, partial: false })
|
|
605
|
+
* // { content: 'done', usage: { prompt: 2, completion: 1, total: 3 }, partial: false }
|
|
606
|
+
* ```
|
|
607
|
+
*/
|
|
608
|
+
function agentResultToJSON(value) {
|
|
609
|
+
const captured = attempt(() => {
|
|
610
|
+
if (!isObject(value)) return void 0;
|
|
611
|
+
const content = Reflect.get(value, "content");
|
|
612
|
+
const thinking = Reflect.get(value, "thinking");
|
|
613
|
+
const usage = Reflect.get(value, "usage");
|
|
614
|
+
const partial = Reflect.get(value, "partial");
|
|
615
|
+
if (!isString(content) || !isBoolean(partial)) return void 0;
|
|
616
|
+
if (thinking !== void 0 && !isString(thinking)) return void 0;
|
|
617
|
+
let projectedUsage;
|
|
618
|
+
if (usage !== void 0) {
|
|
619
|
+
if (!isObject(usage)) return void 0;
|
|
620
|
+
const prompt = Reflect.get(usage, "prompt");
|
|
621
|
+
const completion = Reflect.get(usage, "completion");
|
|
622
|
+
const total = Reflect.get(usage, "total");
|
|
623
|
+
if (!isFiniteNumber(prompt) || !isFiniteNumber(completion) || !isFiniteNumber(total)) return;
|
|
624
|
+
projectedUsage = {
|
|
625
|
+
prompt,
|
|
626
|
+
completion,
|
|
627
|
+
total
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
return {
|
|
631
|
+
content,
|
|
632
|
+
...thinking === void 0 ? {} : { thinking },
|
|
633
|
+
...projectedUsage === void 0 ? {} : { usage: projectedUsage },
|
|
634
|
+
partial
|
|
635
|
+
};
|
|
636
|
+
});
|
|
637
|
+
return captured.success ? parseJSONValue(captured.value) : void 0;
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
585
640
|
* Filter a list of items by a {@link import('./types.js').ScopeInterface} allow-list of
|
|
586
641
|
* keys — the pure, total set-membership primitive the context's build step and the agent
|
|
587
642
|
* loop's tool-advertise step apply a scope through.
|
|
@@ -2743,6 +2798,6 @@ function createAgentRunner(options) {
|
|
|
2743
2798
|
});
|
|
2744
2799
|
}
|
|
2745
2800
|
//#endregion
|
|
2746
|
-
export { Agent, AgentContext, AgentError, AgentJobError, AgentRegistry, Authority, CONVERSATION_RECAP_PREFIX, Channel, Conversation, ConversationError, ConversationManager, DEFAULT_AGENT_LIMIT, DEFAULT_AUTHORITY_ZONE, DEFAULT_CONVERSATION_KEEP, DatabaseConversationStore, IMAGE_TOKEN_ESTIMATE, Instruction, InstructionManager, MESSAGE_TOKEN_OVERHEAD, MemoryConversationStore, ProviderAbortError, Scope, ScopeManager, THINK_CLOSE, THINK_OPEN, ThinkSplitter, WORKSPACE_SECTION_HEADER, createAgent, createAgentContext, createAgentQueue, createAgentRegistry, createAgentRunner, createAuthority, createConversation, createConversationManager, createDatabaseConversationStore, createInstruction, createInstructionManager, createMemoryConversationStore, createScope, createScopeManager, createThinkSplitter, estimateMessages, estimateTokens, fencedFile, filterAllowList, handleAgentQueueJob, handleAgentRunnerJob, isAgentError, isAgentJobError, isConversationError, isConversationSnapshot, isMessage, isProviderAbortError, isSection, sanitizeToken, sanitizeUsage, settleAgentJob };
|
|
2801
|
+
export { Agent, AgentContext, AgentError, AgentJobError, AgentRegistry, Authority, CONVERSATION_RECAP_PREFIX, Channel, Conversation, ConversationError, ConversationManager, DEFAULT_AGENT_LIMIT, DEFAULT_AUTHORITY_ZONE, DEFAULT_CONVERSATION_KEEP, DatabaseConversationStore, IMAGE_TOKEN_ESTIMATE, Instruction, InstructionManager, MESSAGE_TOKEN_OVERHEAD, MemoryConversationStore, ProviderAbortError, Scope, ScopeManager, THINK_CLOSE, THINK_OPEN, ThinkSplitter, WORKSPACE_SECTION_HEADER, agentResultToJSON, createAgent, createAgentContext, createAgentQueue, createAgentRegistry, createAgentRunner, createAuthority, createConversation, createConversationManager, createDatabaseConversationStore, createInstruction, createInstructionManager, createMemoryConversationStore, createScope, createScopeManager, createThinkSplitter, estimateMessages, estimateTokens, fencedFile, filterAllowList, handleAgentQueueJob, handleAgentRunnerJob, isAgentError, isAgentJobError, isConversationError, isConversationSnapshot, isMessage, isProviderAbortError, isSection, sanitizeToken, sanitizeUsage, settleAgentJob };
|
|
2747
2802
|
|
|
2748
2803
|
//# sourceMappingURL=index.js.map
|