@elevasis/sdk 1.43.0 → 1.44.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.cjs +3733 -3255
- package/dist/index.d.ts +744 -582
- package/dist/index.js +3833 -3355
- package/dist/node/index.d.ts +626 -483
- package/dist/test-utils/index.d.ts +636 -490
- package/dist/test-utils/index.js +1128 -318
- package/dist/types/worker/index.d.ts +4 -1
- package/dist/worker/index.js +775 -298
- package/package.json +4 -4
- package/reference/claude-config/sync-notes/2026-08-02-auth-guard-defaults-and-truncation-fix.md +122 -0
- package/reference/sdk/resources/index.mdx +46 -11
- package/reference/sdk/resources/types.mdx +14 -14
package/dist/node/index.d.ts
CHANGED
|
@@ -274,152 +274,6 @@ interface IExecutionLogger {
|
|
|
274
274
|
error(message: string, context?: LogContext): void;
|
|
275
275
|
}
|
|
276
276
|
|
|
277
|
-
/**
|
|
278
|
-
* Model Configuration
|
|
279
|
-
* Centralized model information, configuration, options, constraints, and validation
|
|
280
|
-
* Single source of truth for all model-related definitions
|
|
281
|
-
* Update manually when pricing changes or new models are added
|
|
282
|
-
*/
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* Supported Open AI models (direct SDK access)
|
|
286
|
-
*/
|
|
287
|
-
type OpenAIModel = 'gpt-5' | 'gpt-5.4-mini' | 'gpt-5.4-nano';
|
|
288
|
-
/**
|
|
289
|
-
* Supported OpenRouter models (explicit union for type safety)
|
|
290
|
-
*/
|
|
291
|
-
type OpenRouterModel = 'openrouter/z-ai/glm-5';
|
|
292
|
-
/**
|
|
293
|
-
* Supported Anthropic models (direct SDK access via @anthropic-ai/sdk)
|
|
294
|
-
*/
|
|
295
|
-
type AnthropicModel = 'claude-opus-5' | 'claude-sonnet-5' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5';
|
|
296
|
-
/** Supported LLM models */
|
|
297
|
-
type LLMModel = OpenAIModel | OpenRouterModel | AnthropicModel | 'mock';
|
|
298
|
-
/**
|
|
299
|
-
* GPT-5 model options schema
|
|
300
|
-
*/
|
|
301
|
-
declare const GPT5OptionsSchema: z.ZodObject<{
|
|
302
|
-
reasoning_effort: z.ZodOptional<z.ZodEnum<{
|
|
303
|
-
minimal: "minimal";
|
|
304
|
-
low: "low";
|
|
305
|
-
medium: "medium";
|
|
306
|
-
high: "high";
|
|
307
|
-
}>>;
|
|
308
|
-
verbosity: z.ZodOptional<z.ZodEnum<{
|
|
309
|
-
low: "low";
|
|
310
|
-
medium: "medium";
|
|
311
|
-
high: "high";
|
|
312
|
-
}>>;
|
|
313
|
-
}, z.core.$strip>;
|
|
314
|
-
/**
|
|
315
|
-
* OpenRouter model options schema
|
|
316
|
-
* OpenRouter-specific options for routing and transforms
|
|
317
|
-
*/
|
|
318
|
-
declare const OpenRouterOptionsSchema: z.ZodObject<{
|
|
319
|
-
transforms: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
320
|
-
route: z.ZodOptional<z.ZodEnum<{
|
|
321
|
-
fallback: "fallback";
|
|
322
|
-
}>>;
|
|
323
|
-
}, z.core.$strip>;
|
|
324
|
-
/**
|
|
325
|
-
* Anthropic model options schema
|
|
326
|
-
* Currently empty - future options must be added per supported model family
|
|
327
|
-
*/
|
|
328
|
-
declare const AnthropicOptionsSchema: z.ZodObject<{}, z.core.$strict>;
|
|
329
|
-
/**
|
|
330
|
-
* Infer TypeScript types from schemas
|
|
331
|
-
*/
|
|
332
|
-
type GPT5Options = z.infer<typeof GPT5OptionsSchema>;
|
|
333
|
-
type MockOptions = Record<string, never>;
|
|
334
|
-
type OpenRouterOptions = z.infer<typeof OpenRouterOptionsSchema>;
|
|
335
|
-
type AnthropicOptions = z.infer<typeof AnthropicOptionsSchema>;
|
|
336
|
-
type ModelSpecificOptions = GPT5Options | MockOptions | OpenRouterOptions | AnthropicOptions;
|
|
337
|
-
/**
|
|
338
|
-
* Model configuration for LLM execution
|
|
339
|
-
* Belongs in resource definition (AgentDefinition, WorkflowDefinition, etc.)
|
|
340
|
-
*/
|
|
341
|
-
interface ModelConfig {
|
|
342
|
-
model: LLMModel;
|
|
343
|
-
provider: 'openai' | 'anthropic' | 'openrouter' | 'mock';
|
|
344
|
-
apiKey: string;
|
|
345
|
-
temperature?: number;
|
|
346
|
-
/** Maximum output tokens per LLM call. NOT the model's context window — see ModelInfo.maxTokens for that. */
|
|
347
|
-
maxOutputTokens?: number;
|
|
348
|
-
topP?: number;
|
|
349
|
-
/**
|
|
350
|
-
* Model-specific options (flat structure)
|
|
351
|
-
* Options are model-specific, not vendor-specific
|
|
352
|
-
* Available options defined in MODEL_INFO per model
|
|
353
|
-
* Validated at build time via validateModelOptions()
|
|
354
|
-
*/
|
|
355
|
-
modelOptions?: ModelSpecificOptions;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
/**
|
|
359
|
-
* Types for the schema compiler. `compile.ts` walks a `JsonSchema` once, driven entirely by a
|
|
360
|
-
* `ProviderDialect`, and every server adapter compiles through it.
|
|
361
|
-
*/
|
|
362
|
-
/**
|
|
363
|
-
* What happened to `strict` on a request, recorded per call rather than inferred.
|
|
364
|
-
*
|
|
365
|
-
* `applied` and `notAttempted` are the two states that a refusal-only field cannot tell apart --
|
|
366
|
-
* both leave `strictRefusalReasons` empty. Recording the verdict positively is what makes "was
|
|
367
|
-
* this agent's output actually enforced?" answerable from an `ai_calls` row.
|
|
368
|
-
*/
|
|
369
|
-
type StrictStatus = 'applied' | 'refused' | 'compileRejected' | 'notAttempted';
|
|
370
|
-
/**
|
|
371
|
-
* A JSON Schema node, typed enough to be useful without pretending to validate the spec.
|
|
372
|
-
*
|
|
373
|
-
* The compiler has to accept schemas that arrive OUTSIDE the strict subset (that is the whole
|
|
374
|
-
* point of a dialect that can refuse or rewrite them) as well as the `$ref`/`$defs`/`const`/
|
|
375
|
-
* `$schema` shapes the strict subset has no vocabulary for at all. The index signature exists
|
|
376
|
-
* because tenant schemas carry keywords (`minLength`, `pattern`, `minimum`, ...) this compiler
|
|
377
|
-
* drops or refuses on, and they still need somewhere to type-check while they pass through
|
|
378
|
-
* `Object.entries`.
|
|
379
|
-
*/
|
|
380
|
-
interface JsonSchema {
|
|
381
|
-
type?: string | string[];
|
|
382
|
-
/**
|
|
383
|
-
* The value is `JsonSchema | undefined`, not `JsonSchema`, because a property really can be
|
|
384
|
-
* declared with nothing describing it. `buildIterationResponseSchema` emits one per tool as
|
|
385
|
-
* `input: tool.inputSchema`, and `ToolDefinition.inputSchema` is typed `unknown` -- a tool
|
|
386
|
-
* deployed without one puts `undefined` under a key that exists.
|
|
387
|
-
*
|
|
388
|
-
* Both readers already handle it: `compileSchema` passes each value through `convertNode`, which
|
|
389
|
-
* takes `unknown`, and `collectErrors` opens with `if (!schema || typeof schema !== 'object')`
|
|
390
|
-
* above a comment naming this exact case. Declaring the value non-optional only hid that they
|
|
391
|
-
* were right to.
|
|
392
|
-
*/
|
|
393
|
-
properties?: Record<string, JsonSchema | undefined>;
|
|
394
|
-
items?: JsonSchema;
|
|
395
|
-
anyOf?: JsonSchema[];
|
|
396
|
-
oneOf?: JsonSchema[];
|
|
397
|
-
allOf?: JsonSchema[];
|
|
398
|
-
required?: string[];
|
|
399
|
-
additionalProperties?: boolean | JsonSchema;
|
|
400
|
-
minItems?: number;
|
|
401
|
-
maxItems?: number;
|
|
402
|
-
format?: string;
|
|
403
|
-
enum?: unknown[];
|
|
404
|
-
const?: unknown;
|
|
405
|
-
description?: string;
|
|
406
|
-
default?: unknown;
|
|
407
|
-
$ref?: string;
|
|
408
|
-
$defs?: Record<string, JsonSchema>;
|
|
409
|
-
definitions?: Record<string, JsonSchema>;
|
|
410
|
-
$schema?: string;
|
|
411
|
-
$id?: string;
|
|
412
|
-
$anchor?: string;
|
|
413
|
-
/**
|
|
414
|
-
* OpenAPI's nullability spelling, which is not JSON Schema's. It is declared because
|
|
415
|
-
* `response-schema-validator.ts` READS it (`schemaPermitsNull`) -- Google's schema dialect is
|
|
416
|
-
* OpenAPI-derived, so a schema that reaches the validator can carry it. No dialect in `compile.ts`
|
|
417
|
-
* writes or rewrites it; the canonical spelling this compiler emits is `type: ['x', 'null']`.
|
|
418
|
-
*/
|
|
419
|
-
nullable?: boolean;
|
|
420
|
-
[key: string]: unknown;
|
|
421
|
-
}
|
|
422
|
-
|
|
423
277
|
declare const ResourceGovernanceStatusSchema: z.ZodEnum<{
|
|
424
278
|
active: "active";
|
|
425
279
|
deprecated: "deprecated";
|
|
@@ -782,165 +636,194 @@ type AgentResourceEntry = z.infer<typeof AgentResourceEntrySchema$1>;
|
|
|
782
636
|
type ResourceEntry = z.infer<typeof ResourceEntrySchema>;
|
|
783
637
|
|
|
784
638
|
/**
|
|
785
|
-
*
|
|
786
|
-
*
|
|
787
|
-
*/
|
|
788
|
-
/**
|
|
789
|
-
* Supported form field types for action payloads
|
|
790
|
-
* Maps to Mantine form components
|
|
791
|
-
*/
|
|
792
|
-
type FormFieldType = 'text' | 'textarea' | 'number' | 'select' | 'checkbox' | 'radio' | 'richtext';
|
|
793
|
-
/**
|
|
794
|
-
* Form field definition
|
|
639
|
+
* Memory type definitions
|
|
640
|
+
* Types for agent memory management with semantic entry types
|
|
795
641
|
*/
|
|
796
|
-
interface FormField {
|
|
797
|
-
/** Field key in payload object */
|
|
798
|
-
name: string;
|
|
799
|
-
/** Field label for UI */
|
|
800
|
-
label: string;
|
|
801
|
-
/** Field type (determines UI component) */
|
|
802
|
-
type: FormFieldType;
|
|
803
|
-
/** Default value */
|
|
804
|
-
defaultValue?: unknown;
|
|
805
|
-
/** Required field */
|
|
806
|
-
required?: boolean;
|
|
807
|
-
/** Placeholder text */
|
|
808
|
-
placeholder?: string;
|
|
809
|
-
/** Help text */
|
|
810
|
-
description?: string;
|
|
811
|
-
/** Options for select/radio */
|
|
812
|
-
options?: Array<{
|
|
813
|
-
label: string;
|
|
814
|
-
value: string | number;
|
|
815
|
-
}>;
|
|
816
|
-
/** Min/max for number */
|
|
817
|
-
min?: number;
|
|
818
|
-
max?: number;
|
|
819
|
-
/** Path to context value for pre-filling (dot notation, e.g., 'proposal.summary') */
|
|
820
|
-
defaultValueFromContext?: string;
|
|
821
|
-
}
|
|
822
642
|
/**
|
|
823
|
-
*
|
|
643
|
+
* Semantic memory entry types
|
|
644
|
+
* Use-case agnostic types that describe the purpose of each entry
|
|
645
|
+
* Memory types mirror action types for clarity and filtering
|
|
824
646
|
*/
|
|
825
|
-
|
|
826
|
-
/** Form title */
|
|
827
|
-
title?: string;
|
|
828
|
-
/** Form description */
|
|
829
|
-
description?: string;
|
|
830
|
-
/** Form fields */
|
|
831
|
-
fields: FormField[];
|
|
832
|
-
}
|
|
833
|
-
|
|
647
|
+
type MemoryEntryType = 'context' | 'input' | 'reasoning' | 'tool-result' | 'error';
|
|
834
648
|
/**
|
|
835
|
-
*
|
|
836
|
-
*
|
|
837
|
-
*
|
|
649
|
+
* Who authored an entry's content.
|
|
650
|
+
*
|
|
651
|
+
* This is what lets the assembled prompt tell framework-authored text apart from text that
|
|
652
|
+
* originated outside the trust boundary. `'framework'` content is ours; the other three are not
|
|
653
|
+
* and are rendered inside the JSON data envelope (see `MemoryManager.toContextParts`).
|
|
838
654
|
*/
|
|
839
|
-
|
|
840
|
-
/** Form configuration for execution inputs */
|
|
841
|
-
form: ExecutionFormSchema;
|
|
842
|
-
/** Optional: Schedule configuration */
|
|
843
|
-
schedule?: ScheduleConfig;
|
|
844
|
-
/** Optional: Webhook trigger configuration */
|
|
845
|
-
webhook?: WebhookConfig;
|
|
846
|
-
}
|
|
655
|
+
type MemoryEntrySource = 'framework' | 'user' | 'tool' | 'model';
|
|
847
656
|
/**
|
|
848
|
-
*
|
|
849
|
-
*
|
|
657
|
+
* Memory entry - represents a single entry in agent memory
|
|
658
|
+
* Stored in agent memory, translated by adapters to vendor-specific formats
|
|
850
659
|
*/
|
|
851
|
-
interface
|
|
660
|
+
interface MemoryEntry {
|
|
661
|
+
type: MemoryEntryType;
|
|
662
|
+
content: string;
|
|
663
|
+
timestamp: number;
|
|
664
|
+
turnNumber: number | null;
|
|
665
|
+
iterationNumber: number | null;
|
|
852
666
|
/**
|
|
853
|
-
*
|
|
854
|
-
*
|
|
855
|
-
*
|
|
667
|
+
* Provenance. **Optional on purpose** — `undefined` means unknown, which is what every
|
|
668
|
+
* pre-existing snapshot and every not-yet-redeployed tenant bundle produces. Read sites MUST
|
|
669
|
+
* test `== null`, never `=== undefined`: the `inTurnScope` predicate in `manager.ts` is the
|
|
670
|
+
* cautionary precedent, where a `=== undefined` check silently dropped every `null`-stamped
|
|
671
|
+
* entry. `isMemoryEntry` is deliberately NOT tightened to require this field; doing so would
|
|
672
|
+
* make every stored snapshot fail validation, and `restoreSessionMemory` fails open by
|
|
673
|
+
* starting the agent with empty memory rather than throwing.
|
|
856
674
|
*/
|
|
857
|
-
|
|
675
|
+
source?: MemoryEntrySource;
|
|
858
676
|
/**
|
|
859
|
-
*
|
|
860
|
-
*
|
|
677
|
+
* Which tool produced this entry. Set on `tool-result` entries so the model can tell N parallel
|
|
678
|
+
* results apart -- the framework instructs batching independent tool calls in one iteration, and
|
|
679
|
+
* an anonymous result is unattributable the moment two land in the same iteration. `addToolError`
|
|
680
|
+
* already carries this (folded into its `content` JSON); this is the same fact for the success
|
|
681
|
+
* path, carried as a real field instead of prose the caller has to parse back out.
|
|
861
682
|
*/
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
683
|
+
toolName?: string;
|
|
684
|
+
/**
|
|
685
|
+
* Present when `truncateContent` cut this entry's `content` to fit its token budget. A sibling
|
|
686
|
+
* field, never text appended into `content` -- the notice used to be spliced into the string
|
|
687
|
+
* itself, which could (and did) land inside a JSON string literal `truncateContent` had just cut
|
|
688
|
+
* open, breaking `JSON.parse` on the far end. Absent means never truncated.
|
|
689
|
+
*/
|
|
690
|
+
truncated?: {
|
|
691
|
+
omittedTokens: number;
|
|
866
692
|
};
|
|
693
|
+
/**
|
|
694
|
+
* Prompt-injection warning types found in `content`, screened once here -- when the entry is
|
|
695
|
+
* written -- instead of by re-scanning the whole accumulated envelope on every iteration it gets
|
|
696
|
+
* re-sent for (`screenRequest`'s `data-envelope` slot used to do exactly that). Empty array means
|
|
697
|
+
* screened and clean; `undefined` means never screened (entries that bypass `addToHistory`/`set`,
|
|
698
|
+
* or pre-existing snapshots from before this field existed).
|
|
699
|
+
*/
|
|
700
|
+
warnings?: string[];
|
|
867
701
|
}
|
|
868
702
|
/**
|
|
869
|
-
*
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
703
|
+
* Agent memory - Self-orchestrated memory with session + working storage
|
|
704
|
+
* Agent has full control over what persists, framework handles auto-compaction
|
|
705
|
+
*/
|
|
706
|
+
interface AgentMemory {
|
|
707
|
+
/**
|
|
708
|
+
* Session memory - Persists for session/conversation duration
|
|
709
|
+
* Never auto-trimmed by framework
|
|
710
|
+
* Agent-managed key-value store for critical information
|
|
711
|
+
* Agent provides strings, framework wraps in MemoryEntry
|
|
712
|
+
*/
|
|
713
|
+
sessionMemory: Record<string, MemoryEntry>;
|
|
714
|
+
/**
|
|
715
|
+
* Working memory - Execution history
|
|
716
|
+
* Automatically compacted by framework when needed
|
|
717
|
+
* Agent doesn't control compaction
|
|
718
|
+
*/
|
|
719
|
+
history: MemoryEntry[];
|
|
878
720
|
}
|
|
879
721
|
/**
|
|
880
|
-
*
|
|
722
|
+
* Memory status for agent awareness
|
|
881
723
|
*/
|
|
882
|
-
interface
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
}
|
|
888
|
-
|
|
889
|
-
interface WorkflowConfig extends ResourceDefinition {
|
|
890
|
-
type: 'workflow';
|
|
891
|
-
/** OM descriptor backing canonical identity and governance metadata. */
|
|
892
|
-
resource?: WorkflowResourceEntry;
|
|
893
|
-
}
|
|
894
|
-
interface WorkflowStepDefinition {
|
|
895
|
-
id: string;
|
|
896
|
-
name: string;
|
|
897
|
-
description: string;
|
|
898
|
-
}
|
|
899
|
-
type StepHandler = (input: unknown, context: ExecutionContext) => Promise<unknown>;
|
|
900
|
-
interface LinearNext {
|
|
901
|
-
type: 'linear';
|
|
902
|
-
target: string;
|
|
903
|
-
}
|
|
904
|
-
interface ConditionalNext {
|
|
905
|
-
type: 'conditional';
|
|
906
|
-
routes: Array<{
|
|
907
|
-
condition: (data: unknown) => boolean;
|
|
908
|
-
target: string;
|
|
909
|
-
}>;
|
|
910
|
-
default: string;
|
|
911
|
-
}
|
|
912
|
-
type NextConfig = LinearNext | ConditionalNext | null;
|
|
913
|
-
interface WorkflowStep extends WorkflowStepDefinition {
|
|
914
|
-
handler: StepHandler;
|
|
915
|
-
inputSchema: z.ZodSchema;
|
|
916
|
-
outputSchema: z.ZodSchema;
|
|
917
|
-
next: NextConfig;
|
|
918
|
-
}
|
|
919
|
-
interface WorkflowDefinition {
|
|
920
|
-
config: WorkflowConfig;
|
|
921
|
-
contract: Contract;
|
|
922
|
-
steps: Record<string, WorkflowStep>;
|
|
923
|
-
entryPoint: string;
|
|
724
|
+
interface MemoryStatus {
|
|
725
|
+
sessionMemoryKeys: number;
|
|
726
|
+
sessionMemoryLimit: number;
|
|
727
|
+
sessionMemoryTokens: number;
|
|
728
|
+
sessionMemoryTokenLimit: number;
|
|
924
729
|
/**
|
|
925
|
-
*
|
|
926
|
-
*
|
|
730
|
+
* History tokens as a percentage of `historyBudget` — history ALONE, not history plus session
|
|
731
|
+
* memory. It previously reported the combined total under this name, so session memory growth
|
|
732
|
+
* read as history pressure and triggered history compaction that could not relieve it.
|
|
927
733
|
*/
|
|
928
|
-
|
|
734
|
+
historyPercent: number;
|
|
929
735
|
/**
|
|
930
|
-
*
|
|
931
|
-
*
|
|
736
|
+
* Tokens the history entries **in scope for the requested turn** occupy — the same set
|
|
737
|
+
* `toContextParts` puts in the envelope. Equal to `storedHistoryTokens` when `getStatus` is
|
|
738
|
+
* called without a turn.
|
|
739
|
+
*
|
|
740
|
+
* This is the number the model is shown, and it is scoped because the model is handed a scoped
|
|
741
|
+
* set. Counting the whole cross-turn array here meant the framing quoted the size of a store
|
|
742
|
+
* while the envelope beside it carried one turn's worth of it.
|
|
932
743
|
*/
|
|
933
|
-
|
|
744
|
+
historyTokens: number;
|
|
934
745
|
/**
|
|
935
|
-
*
|
|
936
|
-
* Must match a key in the platform lead-gen stage catalog.
|
|
937
|
-
* Used by org-os graph derivation to surface workflow→stage edges and
|
|
938
|
-
* by pipeline_config validation to confirm each catalog stage has an
|
|
939
|
-
* implementing workflow before a list is activated.
|
|
746
|
+
* Tokens the **entire** history array occupies, across every turn the session snapshot restored.
|
|
940
747
|
*
|
|
941
|
-
*
|
|
748
|
+
* This is what compaction measures, because compaction trims that array. Scoping it to a turn
|
|
749
|
+
* would let the store grow without bound whenever the current turn happened to be small.
|
|
942
750
|
*/
|
|
943
|
-
|
|
751
|
+
storedHistoryTokens: number;
|
|
752
|
+
/** `storedHistoryTokens` as a percentage of `historyBudget`. The auto-compaction trigger. */
|
|
753
|
+
storedHistoryPercent: number;
|
|
754
|
+
historyBudget: number;
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* Memory constraints (optional limits)
|
|
758
|
+
*/
|
|
759
|
+
interface MemoryConstraints {
|
|
760
|
+
maxSessionMemoryKeys?: number;
|
|
761
|
+
maxMemoryTokens?: number;
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
/**
|
|
765
|
+
* Types for the schema compiler. `compile.ts` walks a `JsonSchema` once, driven entirely by a
|
|
766
|
+
* `ProviderDialect`, and every server adapter compiles through it.
|
|
767
|
+
*/
|
|
768
|
+
/**
|
|
769
|
+
* What happened to `strict` on a request, recorded per call rather than inferred.
|
|
770
|
+
*
|
|
771
|
+
* `applied` and `notAttempted` are the two states that a refusal-only field cannot tell apart --
|
|
772
|
+
* both leave `strictRefusalReasons` empty. Recording the verdict positively is what makes "was
|
|
773
|
+
* this agent's output actually enforced?" answerable from an `ai_calls` row.
|
|
774
|
+
*/
|
|
775
|
+
type StrictStatus = 'applied' | 'refused' | 'compileRejected' | 'notAttempted';
|
|
776
|
+
/**
|
|
777
|
+
* A JSON Schema node, typed enough to be useful without pretending to validate the spec.
|
|
778
|
+
*
|
|
779
|
+
* The compiler has to accept schemas that arrive OUTSIDE the strict subset (that is the whole
|
|
780
|
+
* point of a dialect that can refuse or rewrite them) as well as the `$ref`/`$defs`/`const`/
|
|
781
|
+
* `$schema` shapes the strict subset has no vocabulary for at all. The index signature exists
|
|
782
|
+
* because tenant schemas carry keywords (`minLength`, `pattern`, `minimum`, ...) this compiler
|
|
783
|
+
* drops or refuses on, and they still need somewhere to type-check while they pass through
|
|
784
|
+
* `Object.entries`.
|
|
785
|
+
*/
|
|
786
|
+
interface JsonSchema {
|
|
787
|
+
type?: string | string[];
|
|
788
|
+
/**
|
|
789
|
+
* The value is `JsonSchema | undefined`, not `JsonSchema`, because a property really can be
|
|
790
|
+
* declared with nothing describing it. `buildIterationResponseSchema` emits one per tool as
|
|
791
|
+
* `input: tool.inputSchema`, and `ToolDefinition.inputSchema` is typed `unknown` -- a tool
|
|
792
|
+
* deployed without one puts `undefined` under a key that exists.
|
|
793
|
+
*
|
|
794
|
+
* Both readers already handle it: `compileSchema` passes each value through `convertNode`, which
|
|
795
|
+
* takes `unknown`, and `collectErrors` opens with `if (!schema || typeof schema !== 'object')`
|
|
796
|
+
* above a comment naming this exact case. Declaring the value non-optional only hid that they
|
|
797
|
+
* were right to.
|
|
798
|
+
*/
|
|
799
|
+
properties?: Record<string, JsonSchema | undefined>;
|
|
800
|
+
items?: JsonSchema;
|
|
801
|
+
anyOf?: JsonSchema[];
|
|
802
|
+
oneOf?: JsonSchema[];
|
|
803
|
+
allOf?: JsonSchema[];
|
|
804
|
+
required?: string[];
|
|
805
|
+
additionalProperties?: boolean | JsonSchema;
|
|
806
|
+
minItems?: number;
|
|
807
|
+
maxItems?: number;
|
|
808
|
+
format?: string;
|
|
809
|
+
enum?: unknown[];
|
|
810
|
+
const?: unknown;
|
|
811
|
+
description?: string;
|
|
812
|
+
default?: unknown;
|
|
813
|
+
$ref?: string;
|
|
814
|
+
$defs?: Record<string, JsonSchema>;
|
|
815
|
+
definitions?: Record<string, JsonSchema>;
|
|
816
|
+
$schema?: string;
|
|
817
|
+
$id?: string;
|
|
818
|
+
$anchor?: string;
|
|
819
|
+
/**
|
|
820
|
+
* OpenAPI's nullability spelling, which is not JSON Schema's. It is declared because
|
|
821
|
+
* `response-schema-validator.ts` READS it (`schemaPermitsNull`) -- Google's schema dialect is
|
|
822
|
+
* OpenAPI-derived, so a schema that reaches the validator can carry it. No dialect in `compile.ts`
|
|
823
|
+
* writes or rewrites it; the canonical spelling this compiler emits is `type: ['x', 'null']`.
|
|
824
|
+
*/
|
|
825
|
+
nullable?: boolean;
|
|
826
|
+
[key: string]: unknown;
|
|
944
827
|
}
|
|
945
828
|
|
|
946
829
|
/**
|
|
@@ -955,6 +838,31 @@ interface WorkflowDefinition {
|
|
|
955
838
|
interface LLMMessage {
|
|
956
839
|
role: 'system' | 'user' | 'assistant';
|
|
957
840
|
content: string;
|
|
841
|
+
/**
|
|
842
|
+
* Marks this message as the end of a byte-stable prefix worth an Anthropic cache breakpoint,
|
|
843
|
+
* beyond the one the system prompt already gets. Anthropic's rule is "everything up to and
|
|
844
|
+
* including the marked block is cached", so this only ever needs to sit on ONE message -- the
|
|
845
|
+
* last one before content that changes.
|
|
846
|
+
*
|
|
847
|
+
* `buildAgentMessages` sets it on the last replayed prior-turn message: conversation history is
|
|
848
|
+
* fixed for the whole turn (only the framing/envelope after it grow per iteration), so it is the
|
|
849
|
+
* only part of a session agent's messages, besides the system prompt, that is ever byte-identical
|
|
850
|
+
* call to call. A hint rather than a mechanism deliberately -- an adapter that does not read it
|
|
851
|
+
* (OpenAI, OpenRouter, any test stub) just ignores the extra property; only the Anthropic adapter
|
|
852
|
+
* turns it into a wire `cache_control` block.
|
|
853
|
+
*/
|
|
854
|
+
cacheBreakpoint?: boolean;
|
|
855
|
+
/**
|
|
856
|
+
* Prompt-injection warning types already found in this message's content, when the caller has
|
|
857
|
+
* already screened it and wants `screenRequest` to use that verdict instead of re-scanning.
|
|
858
|
+
*
|
|
859
|
+
* Set only on the data-envelope message by `buildAgentMessages`, sourced from
|
|
860
|
+
* `MemoryContextParts.envelopeWarnings` -- itself an aggregate of `MemoryEntry.warnings` stamped
|
|
861
|
+
* once per fragment when it entered memory. `undefined` means "not pre-screened"; `screenRequest`
|
|
862
|
+
* falls back to scanning the content directly, which is what every other message role/slot still
|
|
863
|
+
* does and what a hand-built message (tests, other callers) gets by default.
|
|
864
|
+
*/
|
|
865
|
+
envelopeWarnings?: string[];
|
|
958
866
|
}
|
|
959
867
|
/**
|
|
960
868
|
* Generic LLM generation request
|
|
@@ -1120,112 +1028,84 @@ interface LLMAdapter {
|
|
|
1120
1028
|
}
|
|
1121
1029
|
|
|
1122
1030
|
/**
|
|
1123
|
-
*
|
|
1124
|
-
*
|
|
1031
|
+
* Model Configuration
|
|
1032
|
+
* Centralized model information, configuration, options, constraints, and validation
|
|
1033
|
+
* Single source of truth for all model-related definitions
|
|
1034
|
+
* Update manually when pricing changes or new models are added
|
|
1125
1035
|
*/
|
|
1036
|
+
|
|
1126
1037
|
/**
|
|
1127
|
-
*
|
|
1128
|
-
* Use-case agnostic types that describe the purpose of each entry
|
|
1129
|
-
* Memory types mirror action types for clarity and filtering
|
|
1038
|
+
* Supported Open AI models (direct SDK access)
|
|
1130
1039
|
*/
|
|
1131
|
-
type
|
|
1040
|
+
type OpenAIModel = 'gpt-5' | 'gpt-5.4-mini' | 'gpt-5.4-nano';
|
|
1132
1041
|
/**
|
|
1133
|
-
*
|
|
1134
|
-
*
|
|
1135
|
-
* This is what lets the assembled prompt tell framework-authored text apart from text that
|
|
1136
|
-
* originated outside the trust boundary. `'framework'` content is ours; the other three are not
|
|
1137
|
-
* and are rendered inside the JSON data envelope (see `MemoryManager.toContextParts`).
|
|
1042
|
+
* Supported OpenRouter models (explicit union for type safety)
|
|
1138
1043
|
*/
|
|
1139
|
-
type
|
|
1044
|
+
type OpenRouterModel = 'openrouter/z-ai/glm-5';
|
|
1140
1045
|
/**
|
|
1141
|
-
*
|
|
1142
|
-
* Stored in agent memory, translated by adapters to vendor-specific formats
|
|
1046
|
+
* Supported Anthropic models (direct SDK access via @anthropic-ai/sdk)
|
|
1143
1047
|
*/
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
timestamp: number;
|
|
1148
|
-
turnNumber: number | null;
|
|
1149
|
-
iterationNumber: number | null;
|
|
1150
|
-
/**
|
|
1151
|
-
* Provenance. **Optional on purpose** — `undefined` means unknown, which is what every
|
|
1152
|
-
* pre-existing snapshot and every not-yet-redeployed tenant bundle produces. Read sites MUST
|
|
1153
|
-
* test `== null`, never `=== undefined`: the `inTurnScope` predicate in `manager.ts` is the
|
|
1154
|
-
* cautionary precedent, where a `=== undefined` check silently dropped every `null`-stamped
|
|
1155
|
-
* entry. `isMemoryEntry` is deliberately NOT tightened to require this field; doing so would
|
|
1156
|
-
* make every stored snapshot fail validation, and `restoreSessionMemory` fails open by
|
|
1157
|
-
* starting the agent with empty memory rather than throwing.
|
|
1158
|
-
*/
|
|
1159
|
-
source?: MemoryEntrySource;
|
|
1160
|
-
/**
|
|
1161
|
-
* Which tool produced this entry. Set on `tool-result` entries so the model can tell N parallel
|
|
1162
|
-
* results apart -- the framework instructs batching independent tool calls in one iteration, and
|
|
1163
|
-
* an anonymous result is unattributable the moment two land in the same iteration. `addToolError`
|
|
1164
|
-
* already carries this (folded into its `content` JSON); this is the same fact for the success
|
|
1165
|
-
* path, carried as a real field instead of prose the caller has to parse back out.
|
|
1166
|
-
*/
|
|
1167
|
-
toolName?: string;
|
|
1168
|
-
}
|
|
1048
|
+
type AnthropicModel = 'claude-opus-5' | 'claude-sonnet-5' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5';
|
|
1049
|
+
/** Supported LLM models */
|
|
1050
|
+
type LLMModel = OpenAIModel | OpenRouterModel | AnthropicModel | 'mock';
|
|
1169
1051
|
/**
|
|
1170
|
-
*
|
|
1171
|
-
* Agent has full control over what persists, framework handles auto-compaction
|
|
1052
|
+
* GPT-5 model options schema
|
|
1172
1053
|
*/
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
history: MemoryEntry[];
|
|
1187
|
-
}
|
|
1054
|
+
declare const GPT5OptionsSchema: z.ZodObject<{
|
|
1055
|
+
reasoning_effort: z.ZodOptional<z.ZodEnum<{
|
|
1056
|
+
minimal: "minimal";
|
|
1057
|
+
low: "low";
|
|
1058
|
+
medium: "medium";
|
|
1059
|
+
high: "high";
|
|
1060
|
+
}>>;
|
|
1061
|
+
verbosity: z.ZodOptional<z.ZodEnum<{
|
|
1062
|
+
low: "low";
|
|
1063
|
+
medium: "medium";
|
|
1064
|
+
high: "high";
|
|
1065
|
+
}>>;
|
|
1066
|
+
}, z.core.$strip>;
|
|
1188
1067
|
/**
|
|
1189
|
-
*
|
|
1068
|
+
* OpenRouter model options schema
|
|
1069
|
+
* OpenRouter-specific options for routing and transforms
|
|
1190
1070
|
*/
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
* History tokens as a percentage of `historyBudget` — history ALONE, not history plus session
|
|
1198
|
-
* memory. It previously reported the combined total under this name, so session memory growth
|
|
1199
|
-
* read as history pressure and triggered history compaction that could not relieve it.
|
|
1200
|
-
*/
|
|
1201
|
-
historyPercent: number;
|
|
1202
|
-
/**
|
|
1203
|
-
* Tokens the history entries **in scope for the requested turn** occupy — the same set
|
|
1204
|
-
* `toContextParts` puts in the envelope. Equal to `storedHistoryTokens` when `getStatus` is
|
|
1205
|
-
* called without a turn.
|
|
1206
|
-
*
|
|
1207
|
-
* This is the number the model is shown, and it is scoped because the model is handed a scoped
|
|
1208
|
-
* set. Counting the whole cross-turn array here meant the framing quoted the size of a store
|
|
1209
|
-
* while the envelope beside it carried one turn's worth of it.
|
|
1210
|
-
*/
|
|
1211
|
-
historyTokens: number;
|
|
1212
|
-
/**
|
|
1213
|
-
* Tokens the **entire** history array occupies, across every turn the session snapshot restored.
|
|
1214
|
-
*
|
|
1215
|
-
* This is what compaction measures, because compaction trims that array. Scoping it to a turn
|
|
1216
|
-
* would let the store grow without bound whenever the current turn happened to be small.
|
|
1217
|
-
*/
|
|
1218
|
-
storedHistoryTokens: number;
|
|
1219
|
-
/** `storedHistoryTokens` as a percentage of `historyBudget`. The auto-compaction trigger. */
|
|
1220
|
-
storedHistoryPercent: number;
|
|
1221
|
-
historyBudget: number;
|
|
1222
|
-
}
|
|
1071
|
+
declare const OpenRouterOptionsSchema: z.ZodObject<{
|
|
1072
|
+
transforms: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
1073
|
+
route: z.ZodOptional<z.ZodEnum<{
|
|
1074
|
+
fallback: "fallback";
|
|
1075
|
+
}>>;
|
|
1076
|
+
}, z.core.$strip>;
|
|
1223
1077
|
/**
|
|
1224
|
-
*
|
|
1078
|
+
* Anthropic model options schema
|
|
1079
|
+
* Currently empty - future options must be added per supported model family
|
|
1225
1080
|
*/
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1081
|
+
declare const AnthropicOptionsSchema: z.ZodObject<{}, z.core.$strict>;
|
|
1082
|
+
/**
|
|
1083
|
+
* Infer TypeScript types from schemas
|
|
1084
|
+
*/
|
|
1085
|
+
type GPT5Options = z.infer<typeof GPT5OptionsSchema>;
|
|
1086
|
+
type MockOptions = Record<string, never>;
|
|
1087
|
+
type OpenRouterOptions = z.infer<typeof OpenRouterOptionsSchema>;
|
|
1088
|
+
type AnthropicOptions = z.infer<typeof AnthropicOptionsSchema>;
|
|
1089
|
+
type ModelSpecificOptions = GPT5Options | MockOptions | OpenRouterOptions | AnthropicOptions;
|
|
1090
|
+
/**
|
|
1091
|
+
* Model configuration for LLM execution
|
|
1092
|
+
* Belongs in resource definition (AgentDefinition, WorkflowDefinition, etc.)
|
|
1093
|
+
*/
|
|
1094
|
+
interface ModelConfig {
|
|
1095
|
+
model: LLMModel;
|
|
1096
|
+
provider: 'openai' | 'anthropic' | 'openrouter' | 'mock';
|
|
1097
|
+
apiKey: string;
|
|
1098
|
+
temperature?: number;
|
|
1099
|
+
/** Maximum output tokens per LLM call. NOT the model's context window — see ModelInfo.maxTokens for that. */
|
|
1100
|
+
maxOutputTokens?: number;
|
|
1101
|
+
topP?: number;
|
|
1102
|
+
/**
|
|
1103
|
+
* Model-specific options (flat structure)
|
|
1104
|
+
* Options are model-specific, not vendor-specific
|
|
1105
|
+
* Available options defined in MODEL_INFO per model
|
|
1106
|
+
* Validated at build time via validateModelOptions()
|
|
1107
|
+
*/
|
|
1108
|
+
modelOptions?: ModelSpecificOptions;
|
|
1229
1109
|
}
|
|
1230
1110
|
|
|
1231
1111
|
/**
|
|
@@ -1245,8 +1125,27 @@ interface MemoryConstraints {
|
|
|
1245
1125
|
interface MemoryContextParts {
|
|
1246
1126
|
/** Framework-authored. Memory status and a description of the envelope. Carries NO stored content. */
|
|
1247
1127
|
framing: string;
|
|
1248
|
-
/** Every stored fragment, JSON-encoded
|
|
1128
|
+
/** Every stored fragment, JSON-encoded. Untrusted. */
|
|
1249
1129
|
dataEnvelope: string;
|
|
1130
|
+
/**
|
|
1131
|
+
* Union of prompt-injection warning types already found across every fragment `dataEnvelope`
|
|
1132
|
+
* actually carries this call, aggregated from verdicts stamped once when each fragment entered
|
|
1133
|
+
* memory (see `MemoryEntry.warnings`) rather than by re-scanning `dataEnvelope`'s text on every
|
|
1134
|
+
* iteration it gets rebuilt for. Elided fragments (see `ENVELOPE_FULL_RESULT_WINDOW`) contribute
|
|
1135
|
+
* nothing here — their original content isn't what gets sent once they're stubbed.
|
|
1136
|
+
*
|
|
1137
|
+
* This is metadata about the envelope, not part of it: folding a detector's own finding into the
|
|
1138
|
+
* model-visible JSON would hand a would-be attacker — plausibly the same person on the other end
|
|
1139
|
+
* of a session conversation — direct feedback on which pattern tripped. A caller wiring this up
|
|
1140
|
+
* (`screenRequest`'s `data-envelope` slot is the one that currently re-scans instead of reading
|
|
1141
|
+
* this) should treat it exactly the way `screenRequest` already treats cross-turn history: it
|
|
1142
|
+
* warns, but whether it blocks is that caller's decision to make, not this one's.
|
|
1143
|
+
*
|
|
1144
|
+
* Optional (not just possibly-empty): the fixture literals in `agent/reasoning/**` tests build
|
|
1145
|
+
* `MemoryContextParts` by hand without it, and requiring it would make this signature's landing
|
|
1146
|
+
* a forced edit across files this change does not otherwise touch.
|
|
1147
|
+
*/
|
|
1148
|
+
envelopeWarnings?: string[];
|
|
1250
1149
|
}
|
|
1251
1150
|
/**
|
|
1252
1151
|
* Memory Manager - Agent memory orchestration
|
|
@@ -1258,7 +1157,41 @@ declare class MemoryManager {
|
|
|
1258
1157
|
private constraints;
|
|
1259
1158
|
private logger?;
|
|
1260
1159
|
private cachedSnapshot?;
|
|
1160
|
+
/**
|
|
1161
|
+
* Rolling correction for `estimateTokens`'s bias, learned from real provider usage.
|
|
1162
|
+
* `undefined` until the first `recordActualUsage` call -- the cold-start state, where
|
|
1163
|
+
* `estimate()` returns the raw `estimateTokens` output unscaled. See `recordActualUsage`.
|
|
1164
|
+
*/
|
|
1165
|
+
private tokenCorrectionFactor?;
|
|
1261
1166
|
constructor(memory: AgentMemory, constraints?: MemoryConstraints, logger?: AgentScopedLogger | undefined);
|
|
1167
|
+
/**
|
|
1168
|
+
* Record how far `estimateTokens` was from reality on a real provider call, and roll it into a
|
|
1169
|
+
* correction applied to every estimate this instance makes from here on -- `getStatus`'s three
|
|
1170
|
+
* token fields and `enforceSessionMemoryTokenLimit`'s eviction check, which is what
|
|
1171
|
+
* `autoCompact`/`enforceHardLimits` actually decide compaction from (C3 / Wave M3).
|
|
1172
|
+
*
|
|
1173
|
+
* `estimateTokens` is `chars / 3.5` -- a constant-ratio guess with no knowledge of JSON escaping,
|
|
1174
|
+
* key overhead, or real tokenizer behaviour. Every provider call already returns an EXACT count
|
|
1175
|
+
* (`usage.inputTokens`) that reaches `ai_calls` and is then dropped; this is where it stops being
|
|
1176
|
+
* dropped, without replacing the estimator outright -- a cold session still needs SOME number
|
|
1177
|
+
* before its first real call completes, so the estimator stays the prior and this only corrects
|
|
1178
|
+
* it once real data exists.
|
|
1179
|
+
*
|
|
1180
|
+
* `estimatedRequestTokens` must be `estimateTokens` applied to the SAME text `actualInputTokens`
|
|
1181
|
+
* was billed for -- the whole assembled request (system prompt, tools, conversation history, the
|
|
1182
|
+
* envelope, everything), not just what this class itself emits. `estimateTokens`'s bias is a
|
|
1183
|
+
* property of the heuristic, not of which slice of the request it is pointed at, so measuring it
|
|
1184
|
+
* against the full request (visible to the caller, not to this class) and applying the result to
|
|
1185
|
+
* this class's own estimates (which can only ever see its own slice) is a fair trade -- one ratio,
|
|
1186
|
+
* calibrated on real data, standing in for a per-segment breakdown nothing needs.
|
|
1187
|
+
*
|
|
1188
|
+
* Exponential moving average, not a straight replace: a single call's ratio is noisy, and a
|
|
1189
|
+
* straight replace lets one outlier swing every compaction decision made afterward. Each new
|
|
1190
|
+
* observation gets 30% weight, converging within a handful of calls without chasing one spike.
|
|
1191
|
+
*/
|
|
1192
|
+
recordActualUsage(estimatedRequestTokens: number, actualInputTokens: number): void;
|
|
1193
|
+
/** `estimateTokens`, scaled by the learned correction once one exists. See `recordActualUsage`. */
|
|
1194
|
+
private estimate;
|
|
1262
1195
|
/**
|
|
1263
1196
|
* Set session memory entry (agent provides string, framework wraps it)
|
|
1264
1197
|
* @param key - Session memory key
|
|
@@ -1354,7 +1287,15 @@ declare class MemoryManager {
|
|
|
1354
1287
|
* treat "everything in this block" as data was also being handed the live question inside that
|
|
1355
1288
|
* block.
|
|
1356
1289
|
*
|
|
1357
|
-
*
|
|
1290
|
+
* History entries stay chronological. They used to be split into a "current iteration" slot
|
|
1291
|
+
* (reverse chronological, for LLM positional bias) and an "earlier" slot -- but the LLM call
|
|
1292
|
+
* always happens BEFORE `addToHistory` writes that iteration's own entries, so the
|
|
1293
|
+
* current-iteration slot held nothing on any call that mattered. One chronological list replaces
|
|
1294
|
+
* both.
|
|
1295
|
+
*
|
|
1296
|
+
* Tool results (and tool errors) older than `ENVELOPE_FULL_RESULT_WINDOW` iterations are carried
|
|
1297
|
+
* as a short stub instead of their full content -- see `ENVELOPE_FULL_RESULT_WINDOW`. The STORE
|
|
1298
|
+
* (`this.memory.history`) is untouched; only what this call carries is capped.
|
|
1358
1299
|
*
|
|
1359
1300
|
* @param currentIteration - Current iteration number (0 = pre-iteration)
|
|
1360
1301
|
* @param currentTurn - Current turn number (optional, for session context filtering)
|
|
@@ -1363,89 +1304,145 @@ declare class MemoryManager {
|
|
|
1363
1304
|
}
|
|
1364
1305
|
|
|
1365
1306
|
/**
|
|
1366
|
-
*
|
|
1367
|
-
*
|
|
1307
|
+
* Shared form field types for dynamic form generation
|
|
1308
|
+
* Used by: Command Queue, Execution Runner UI, future form-based features
|
|
1368
1309
|
*/
|
|
1310
|
+
/**
|
|
1311
|
+
* Supported form field types for action payloads
|
|
1312
|
+
* Maps to Mantine form components
|
|
1313
|
+
*/
|
|
1314
|
+
type FormFieldType = 'text' | 'textarea' | 'number' | 'select' | 'checkbox' | 'radio' | 'richtext';
|
|
1315
|
+
/**
|
|
1316
|
+
* Form field definition
|
|
1317
|
+
*/
|
|
1318
|
+
interface FormField {
|
|
1319
|
+
/** Field key in payload object */
|
|
1320
|
+
name: string;
|
|
1321
|
+
/** Field label for UI */
|
|
1322
|
+
label: string;
|
|
1323
|
+
/** Field type (determines UI component) */
|
|
1324
|
+
type: FormFieldType;
|
|
1325
|
+
/** Default value */
|
|
1326
|
+
defaultValue?: unknown;
|
|
1327
|
+
/** Required field */
|
|
1328
|
+
required?: boolean;
|
|
1329
|
+
/** Placeholder text */
|
|
1330
|
+
placeholder?: string;
|
|
1331
|
+
/** Help text */
|
|
1332
|
+
description?: string;
|
|
1333
|
+
/** Options for select/radio */
|
|
1334
|
+
options?: Array<{
|
|
1335
|
+
label: string;
|
|
1336
|
+
value: string | number;
|
|
1337
|
+
}>;
|
|
1338
|
+
/** Min/max for number */
|
|
1339
|
+
min?: number;
|
|
1340
|
+
max?: number;
|
|
1341
|
+
/** Path to context value for pre-filling (dot notation, e.g., 'proposal.summary') */
|
|
1342
|
+
defaultValueFromContext?: string;
|
|
1343
|
+
}
|
|
1344
|
+
/**
|
|
1345
|
+
* Form schema for action payload collection
|
|
1346
|
+
*/
|
|
1347
|
+
interface FormSchema {
|
|
1348
|
+
/** Form title */
|
|
1349
|
+
title?: string;
|
|
1350
|
+
/** Form description */
|
|
1351
|
+
description?: string;
|
|
1352
|
+
/** Form fields */
|
|
1353
|
+
fields: FormField[];
|
|
1354
|
+
}
|
|
1369
1355
|
|
|
1370
1356
|
/**
|
|
1371
|
-
*
|
|
1372
|
-
*
|
|
1373
|
-
*
|
|
1374
|
-
* - SDK worker: provides PostMessageLLMAdapter (proxies via platform.call)
|
|
1375
|
-
*
|
|
1376
|
-
* Uses `any` for optional params so both the real createLLMAdapter (with typed
|
|
1377
|
-
* AIUsageCollector/AICallContext) and the worker proxy (which ignores them) satisfy the type.
|
|
1357
|
+
* Execution interface configuration
|
|
1358
|
+
* Defines how a resource is executed via the UI (forms, scheduling, webhooks)
|
|
1359
|
+
* Applies to both agents and workflows
|
|
1378
1360
|
*/
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
*
|
|
1393
|
-
* Use for:
|
|
1394
|
-
* - Conversational agents with multi-turn interactions
|
|
1395
|
-
* - Agents requiring persistent context across turns
|
|
1396
|
-
* - Agents that need human-in-the-loop communication
|
|
1397
|
-
*/
|
|
1398
|
-
sessionCapable?: boolean;
|
|
1361
|
+
interface ExecutionInterface {
|
|
1362
|
+
/** Form configuration for execution inputs */
|
|
1363
|
+
form: ExecutionFormSchema;
|
|
1364
|
+
/** Optional: Schedule configuration */
|
|
1365
|
+
schedule?: ScheduleConfig;
|
|
1366
|
+
/** Optional: Webhook trigger configuration */
|
|
1367
|
+
webhook?: WebhookConfig;
|
|
1368
|
+
}
|
|
1369
|
+
/**
|
|
1370
|
+
* Execution form schema
|
|
1371
|
+
* Extends FormSchema with execution-specific fields
|
|
1372
|
+
*/
|
|
1373
|
+
interface ExecutionFormSchema extends FormSchema {
|
|
1399
1374
|
/**
|
|
1400
|
-
*
|
|
1401
|
-
*
|
|
1402
|
-
*
|
|
1403
|
-
* - 'hardened': Comprehensive defense (5 rules) - default for session-capable agents
|
|
1404
|
-
* - 'none': No security prompt - for pure internal agents with no external input
|
|
1405
|
-
*
|
|
1406
|
-
* If omitted, derived from sessionCapable:
|
|
1407
|
-
* sessionCapable: true -> 'hardened'
|
|
1408
|
-
* sessionCapable: false -> 'standard'
|
|
1375
|
+
* Field mappings to resource input schema
|
|
1376
|
+
* Maps form field names to contract input paths
|
|
1377
|
+
* If omitted, field names must match contract input keys exactly
|
|
1409
1378
|
*/
|
|
1410
|
-
|
|
1379
|
+
fieldMappings?: Record<string, string>;
|
|
1411
1380
|
/**
|
|
1412
|
-
*
|
|
1413
|
-
*
|
|
1414
|
-
* If omitted, agent has no memory management capabilities
|
|
1415
|
-
*
|
|
1416
|
-
* Agent-specific guidance on what to preserve, when to persist, and what to clean up.
|
|
1417
|
-
* This guidance is injected into the system prompt when memory management is enabled.
|
|
1418
|
-
*
|
|
1419
|
-
* Use for:
|
|
1420
|
-
* - Conversational agents needing cross-turn context
|
|
1421
|
-
* - Agents managing complex user preferences
|
|
1422
|
-
* - Agents tracking decisions over multiple iterations
|
|
1381
|
+
* Submit button configuration
|
|
1382
|
+
* Default: { label: 'Run', loadingLabel: 'Running...' }
|
|
1423
1383
|
*/
|
|
1424
|
-
|
|
1384
|
+
submitButton?: {
|
|
1385
|
+
label?: string;
|
|
1386
|
+
loadingLabel?: string;
|
|
1387
|
+
confirmMessage?: string;
|
|
1388
|
+
};
|
|
1389
|
+
}
|
|
1390
|
+
/**
|
|
1391
|
+
* Schedule configuration for automated execution
|
|
1392
|
+
*/
|
|
1393
|
+
interface ScheduleConfig {
|
|
1394
|
+
/** Whether scheduling is enabled for this resource */
|
|
1395
|
+
enabled: boolean;
|
|
1396
|
+
/** Default schedule (cron expression) */
|
|
1397
|
+
defaultSchedule?: string;
|
|
1398
|
+
/** Allowed schedule patterns (if restricted) */
|
|
1399
|
+
allowedPatterns?: string[];
|
|
1425
1400
|
}
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1401
|
+
/**
|
|
1402
|
+
* Webhook configuration for external triggers
|
|
1403
|
+
*/
|
|
1404
|
+
interface WebhookConfig {
|
|
1405
|
+
/** Whether webhook trigger is enabled */
|
|
1406
|
+
enabled: boolean;
|
|
1407
|
+
/** Expected payload schema (for documentation) */
|
|
1408
|
+
payloadSchema?: unknown;
|
|
1431
1409
|
}
|
|
1432
|
-
|
|
1433
|
-
|
|
1410
|
+
|
|
1411
|
+
interface WorkflowConfig extends ResourceDefinition {
|
|
1412
|
+
type: 'workflow';
|
|
1413
|
+
/** OM descriptor backing canonical identity and governance metadata. */
|
|
1414
|
+
resource?: WorkflowResourceEntry;
|
|
1415
|
+
}
|
|
1416
|
+
interface WorkflowStepDefinition {
|
|
1417
|
+
id: string;
|
|
1418
|
+
name: string;
|
|
1419
|
+
description: string;
|
|
1420
|
+
}
|
|
1421
|
+
type StepHandler = (input: unknown, context: ExecutionContext) => Promise<unknown>;
|
|
1422
|
+
interface LinearNext {
|
|
1423
|
+
type: 'linear';
|
|
1424
|
+
target: string;
|
|
1425
|
+
}
|
|
1426
|
+
interface ConditionalNext {
|
|
1427
|
+
type: 'conditional';
|
|
1428
|
+
routes: Array<{
|
|
1429
|
+
condition: (data: unknown) => boolean;
|
|
1430
|
+
target: string;
|
|
1431
|
+
}>;
|
|
1432
|
+
default: string;
|
|
1433
|
+
}
|
|
1434
|
+
type NextConfig = LinearNext | ConditionalNext | null;
|
|
1435
|
+
interface WorkflowStep extends WorkflowStepDefinition {
|
|
1436
|
+
handler: StepHandler;
|
|
1437
|
+
inputSchema: z.ZodSchema;
|
|
1438
|
+
outputSchema: z.ZodSchema;
|
|
1439
|
+
next: NextConfig;
|
|
1440
|
+
}
|
|
1441
|
+
interface WorkflowDefinition {
|
|
1442
|
+
config: WorkflowConfig;
|
|
1434
1443
|
contract: Contract;
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
* Model configuration for LLM execution
|
|
1438
|
-
* Specifies provider, API key, and model-specific options
|
|
1439
|
-
*/
|
|
1440
|
-
modelConfig: ModelConfig;
|
|
1441
|
-
/**
|
|
1442
|
-
* Preload memory before execution starts
|
|
1443
|
-
* Handles BOTH context loading AND session restoration
|
|
1444
|
-
*
|
|
1445
|
-
* @param context - Execution context (includes sessionId if session turn)
|
|
1446
|
-
* @returns Initial AgentMemory state (sessionMemory entries + optionally history)
|
|
1447
|
-
*/
|
|
1448
|
-
preloadMemory?: (context: ExecutionContext) => Promise<AgentMemory> | AgentMemory;
|
|
1444
|
+
steps: Record<string, WorkflowStep>;
|
|
1445
|
+
entryPoint: string;
|
|
1449
1446
|
/**
|
|
1450
1447
|
* Metrics configuration for ROI calculations
|
|
1451
1448
|
* Optional: Only needed if tracking automation savings
|
|
@@ -1453,30 +1450,19 @@ interface AgentDefinition {
|
|
|
1453
1450
|
metricsConfig?: ResourceMetricsConfig;
|
|
1454
1451
|
/**
|
|
1455
1452
|
* Execution interface configuration (optional)
|
|
1456
|
-
* If provided,
|
|
1453
|
+
* If provided, workflow appears in Execution Runner UI
|
|
1457
1454
|
*/
|
|
1458
1455
|
interface?: ExecutionInterface;
|
|
1459
|
-
}
|
|
1460
|
-
/**
|
|
1461
|
-
* Agent execution context
|
|
1462
|
-
* Groups all state needed for agent execution phases
|
|
1463
|
-
*/
|
|
1464
|
-
interface IterationContext {
|
|
1465
|
-
config: AgentConfig;
|
|
1466
|
-
contract: Contract;
|
|
1467
|
-
toolRegistry: Map<string, Tool>;
|
|
1468
|
-
memoryManager: MemoryManager;
|
|
1469
|
-
executionContext: ExecutionContext;
|
|
1470
|
-
iteration: number;
|
|
1471
|
-
logger: AgentScopedLogger;
|
|
1472
|
-
modelConfig: ModelConfig;
|
|
1473
|
-
adapterFactory: LLMAdapterFactory;
|
|
1474
1456
|
/**
|
|
1475
|
-
*
|
|
1476
|
-
*
|
|
1477
|
-
*
|
|
1457
|
+
* Lead-gen processing stage this workflow implements (optional).
|
|
1458
|
+
* Must match a key in the platform lead-gen stage catalog.
|
|
1459
|
+
* Used by org-os graph derivation to surface workflow→stage edges and
|
|
1460
|
+
* by pipeline_config validation to confirm each catalog stage has an
|
|
1461
|
+
* implementing workflow before a list is activated.
|
|
1462
|
+
*
|
|
1463
|
+
* Example: stageImplemented: 'verified' on the email-verification workflow.
|
|
1478
1464
|
*/
|
|
1479
|
-
|
|
1465
|
+
stageImplemented?: string;
|
|
1480
1466
|
}
|
|
1481
1467
|
|
|
1482
1468
|
declare const OntologyScopeSchema: z.ZodDefault<z.ZodObject<{
|
|
@@ -2756,6 +2742,32 @@ declare const OrganizationModelSchema$1: z.ZodObject<{
|
|
|
2756
2742
|
|
|
2757
2743
|
type OrganizationModel$1 = z.infer<typeof OrganizationModelSchema$1>;
|
|
2758
2744
|
|
|
2745
|
+
/**
|
|
2746
|
+
* AIUsageCollector
|
|
2747
|
+
* Centralized token tracking that aggregates usage across all LLM calls in an execution
|
|
2748
|
+
*/
|
|
2749
|
+
declare class AIUsageCollector {
|
|
2750
|
+
private model;
|
|
2751
|
+
private calls;
|
|
2752
|
+
private callSequence;
|
|
2753
|
+
/**
|
|
2754
|
+
* Record a single AI call with usage metrics
|
|
2755
|
+
*
|
|
2756
|
+
* @param usage - Token usage and latency data from LLM adapter
|
|
2757
|
+
* @param callType - Type discriminator (agent-reasoning, tool, etc.)
|
|
2758
|
+
* @param context - Optional typed context specific to callType
|
|
2759
|
+
*/
|
|
2760
|
+
record(usage: LLMUsageData, callType?: BaseAICall['callType'], context?: AICallContext): void;
|
|
2761
|
+
/**
|
|
2762
|
+
* Get aggregated summary of all AI calls
|
|
2763
|
+
*/
|
|
2764
|
+
getSummary(): AIUsageSummary;
|
|
2765
|
+
/**
|
|
2766
|
+
* Check if any usage has been recorded
|
|
2767
|
+
*/
|
|
2768
|
+
hasUsage(): boolean;
|
|
2769
|
+
}
|
|
2770
|
+
|
|
2759
2771
|
/**
|
|
2760
2772
|
* MetricsCollector
|
|
2761
2773
|
* Tracks execution timing and ROI metrics
|
|
@@ -3014,29 +3026,147 @@ interface ResourceMetricsConfig {
|
|
|
3014
3026
|
}
|
|
3015
3027
|
|
|
3016
3028
|
/**
|
|
3017
|
-
*
|
|
3018
|
-
*
|
|
3029
|
+
* Agent-specific type definitions
|
|
3030
|
+
* Types for autonomous agents with tools, memory, and constraints
|
|
3019
3031
|
*/
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3032
|
+
|
|
3033
|
+
/**
|
|
3034
|
+
* Factory function for creating LLM adapters.
|
|
3035
|
+
* Injected into the Agent class to decouple the engine from server-only provider SDKs.
|
|
3036
|
+
* - API process: provides createLLMAdapter (real SDKs + process.env API keys)
|
|
3037
|
+
* - SDK worker: provides PostMessageLLMAdapter (proxies via platform.call)
|
|
3038
|
+
*
|
|
3039
|
+
* Uses `any` for optional params so both the real createLLMAdapter (with typed
|
|
3040
|
+
* AIUsageCollector/AICallContext) and the worker proxy (which ignores them) satisfy the type.
|
|
3041
|
+
*/
|
|
3042
|
+
type LLMAdapterFactory = (config: ModelConfig, ...args: any[]) => LLMAdapter;
|
|
3043
|
+
type AgentKind = 'orchestrator' | 'specialist' | 'utility' | 'platform';
|
|
3044
|
+
interface AgentConfig extends ResourceDefinition {
|
|
3045
|
+
type: 'agent';
|
|
3046
|
+
/** OM descriptor backing canonical identity and governance metadata. */
|
|
3047
|
+
resource?: AgentResourceEntry;
|
|
3048
|
+
kind: AgentKind;
|
|
3049
|
+
systemPrompt: string;
|
|
3050
|
+
constraints?: AgentConstraints;
|
|
3024
3051
|
/**
|
|
3025
|
-
*
|
|
3052
|
+
* Session capability declaration (opt-in)
|
|
3053
|
+
* If true, agent is designed for multi-turn session interactions
|
|
3054
|
+
* Controls whether agent can use message action and appears in Sessions UI
|
|
3026
3055
|
*
|
|
3027
|
-
*
|
|
3028
|
-
*
|
|
3029
|
-
*
|
|
3056
|
+
* Use for:
|
|
3057
|
+
* - Conversational agents with multi-turn interactions
|
|
3058
|
+
* - Agents requiring persistent context across turns
|
|
3059
|
+
* - Agents that need human-in-the-loop communication
|
|
3030
3060
|
*/
|
|
3031
|
-
|
|
3061
|
+
sessionCapable?: boolean;
|
|
3032
3062
|
/**
|
|
3033
|
-
*
|
|
3063
|
+
* Overrides the default `message` requiredness for a session-capable agent (ignored for
|
|
3064
|
+
* non-session agents, which always get `AgentCapabilities.message: 'off'`). Defaults to
|
|
3065
|
+
* `'required'` -- see `AgentCapabilities.message`'s doc comment for why. Set `'optional'` only
|
|
3066
|
+
* when the agent legitimately needs tool-only turns with no reply, and the deploy target can
|
|
3067
|
+
* tolerate the blind-retry risk `validateResponseSchema` carries on any path where the schema is
|
|
3068
|
+
* not compiled into a sampling grammar.
|
|
3034
3069
|
*/
|
|
3035
|
-
|
|
3070
|
+
messagePolicy?: 'optional' | 'required';
|
|
3036
3071
|
/**
|
|
3037
|
-
*
|
|
3072
|
+
* Explicit opt-in to skip the iteration loop and produce `contract.outputSchema`-shaped output in
|
|
3073
|
+
* a single LLM call (round 3 decision B6: explicit opt-in, never inferred from `kind`,
|
|
3074
|
+
* `sessionCapable`, or tool count -- so no existing agent changes shape by default). Structurally
|
|
3075
|
+
* the normal path pays two calls minimum: `iterate()` always runs at least one, and `complete()`
|
|
3076
|
+
* runs a second whose prompt re-derives the answer from history rather than reading what the
|
|
3077
|
+
* iteration already decided. A single-shot classifier -- one input in, one structured output out,
|
|
3078
|
+
* no multi-step reasoning needed -- does not need that second derivation; `complete()` already
|
|
3079
|
+
* makes exactly the one call it needs, from `currentInput` directly.
|
|
3080
|
+
*
|
|
3081
|
+
* Requires `sessionCapable` to be falsy and `contract.outputSchema` to be present. `Agent`
|
|
3082
|
+
* validates both during initialization and throws `AgentInitializationError` if either is missing,
|
|
3083
|
+
* rather than silently falling back to the normal two-call path on a misconfigured opt-in. Tools
|
|
3084
|
+
* registered on the agent are never invoked in this path -- there is no iteration loop to call
|
|
3085
|
+
* them from, so an agent that needs tool calls before it can answer is not eligible regardless of
|
|
3086
|
+
* this flag.
|
|
3038
3087
|
*/
|
|
3039
|
-
|
|
3088
|
+
singleShot?: boolean;
|
|
3089
|
+
/**
|
|
3090
|
+
* Security level for system prompt hardening (auto-derived if omitted)
|
|
3091
|
+
*
|
|
3092
|
+
* - 'standard': Lightweight defense (3 rules) - default for non-session agents
|
|
3093
|
+
* - 'hardened': Comprehensive defense (5 rules) - default for session-capable agents
|
|
3094
|
+
* - 'none': No security prompt - for pure internal agents with no external input
|
|
3095
|
+
*
|
|
3096
|
+
* If omitted, derived from sessionCapable:
|
|
3097
|
+
* sessionCapable: true -> 'hardened'
|
|
3098
|
+
* sessionCapable: false -> 'standard'
|
|
3099
|
+
*/
|
|
3100
|
+
securityLevel?: 'standard' | 'hardened' | 'none';
|
|
3101
|
+
/**
|
|
3102
|
+
* Memory management preferences (opt-in)
|
|
3103
|
+
* If provided, agent can use memoryOps to manage session memory
|
|
3104
|
+
* If omitted, agent has no memory management capabilities
|
|
3105
|
+
*
|
|
3106
|
+
* Agent-specific guidance on what to preserve, when to persist, and what to clean up.
|
|
3107
|
+
* This guidance is injected into the system prompt when memory management is enabled.
|
|
3108
|
+
*
|
|
3109
|
+
* Use for:
|
|
3110
|
+
* - Conversational agents needing cross-turn context
|
|
3111
|
+
* - Agents managing complex user preferences
|
|
3112
|
+
* - Agents tracking decisions over multiple iterations
|
|
3113
|
+
*/
|
|
3114
|
+
memoryPreferences?: string;
|
|
3115
|
+
}
|
|
3116
|
+
interface AgentConstraints {
|
|
3117
|
+
maxIterations?: number;
|
|
3118
|
+
timeout?: number;
|
|
3119
|
+
maxSessionMemoryKeys?: number;
|
|
3120
|
+
maxMemoryTokens?: number;
|
|
3121
|
+
}
|
|
3122
|
+
interface AgentDefinition {
|
|
3123
|
+
config: AgentConfig;
|
|
3124
|
+
contract: Contract;
|
|
3125
|
+
tools: Tool[];
|
|
3126
|
+
/**
|
|
3127
|
+
* Model configuration for LLM execution
|
|
3128
|
+
* Specifies provider, API key, and model-specific options
|
|
3129
|
+
*/
|
|
3130
|
+
modelConfig: ModelConfig;
|
|
3131
|
+
/**
|
|
3132
|
+
* Preload memory before execution starts
|
|
3133
|
+
* Handles BOTH context loading AND session restoration
|
|
3134
|
+
*
|
|
3135
|
+
* @param context - Execution context (includes sessionId if session turn)
|
|
3136
|
+
* @returns Initial AgentMemory state (sessionMemory entries + optionally history)
|
|
3137
|
+
*/
|
|
3138
|
+
preloadMemory?: (context: ExecutionContext) => Promise<AgentMemory> | AgentMemory;
|
|
3139
|
+
/**
|
|
3140
|
+
* Metrics configuration for ROI calculations
|
|
3141
|
+
* Optional: Only needed if tracking automation savings
|
|
3142
|
+
*/
|
|
3143
|
+
metricsConfig?: ResourceMetricsConfig;
|
|
3144
|
+
/**
|
|
3145
|
+
* Execution interface configuration (optional)
|
|
3146
|
+
* If provided, agent appears in Execution Runner UI
|
|
3147
|
+
*/
|
|
3148
|
+
interface?: ExecutionInterface;
|
|
3149
|
+
}
|
|
3150
|
+
/**
|
|
3151
|
+
* Agent execution context
|
|
3152
|
+
* Groups all state needed for agent execution phases
|
|
3153
|
+
*/
|
|
3154
|
+
interface IterationContext {
|
|
3155
|
+
config: AgentConfig;
|
|
3156
|
+
contract: Contract;
|
|
3157
|
+
toolRegistry: Map<string, Tool>;
|
|
3158
|
+
memoryManager: MemoryManager;
|
|
3159
|
+
executionContext: ExecutionContext;
|
|
3160
|
+
iteration: number;
|
|
3161
|
+
logger: AgentScopedLogger;
|
|
3162
|
+
modelConfig: ModelConfig;
|
|
3163
|
+
adapterFactory: LLMAdapterFactory;
|
|
3164
|
+
/**
|
|
3165
|
+
* The validated input for this execution, serialized. It travels here because the model gets
|
|
3166
|
+
* it as its own `role:'user'` message; nothing else in this context carried it, so the input
|
|
3167
|
+
* had to be read back out of memory history and shipped inside the memory block.
|
|
3168
|
+
*/
|
|
3169
|
+
currentInput: string;
|
|
3040
3170
|
}
|
|
3041
3171
|
|
|
3042
3172
|
/**
|
|
@@ -3184,6 +3314,19 @@ interface Tool {
|
|
|
3184
3314
|
outputSchema: z.ZodSchema;
|
|
3185
3315
|
execute: (options: ToolExecutionOptions) => Promise<unknown>;
|
|
3186
3316
|
timeout?: number;
|
|
3317
|
+
/**
|
|
3318
|
+
* Optional per-tool output size bound, in approximate tokens. Today the ONLY size bound on tool
|
|
3319
|
+
* output is a 4,000-token truncation applied post-hoc at memory insert -- after the payload is
|
|
3320
|
+
* already fully materialized, validated against `outputSchema`, emitted as a session message, and
|
|
3321
|
+
* logged. This field exists so a tool can declare its own bound up front instead.
|
|
3322
|
+
*
|
|
3323
|
+
* Enforcement is NOT here. `executor.ts:executeToolCall` is the single call site that produces the
|
|
3324
|
+
* value handed to all four sinks (memory, the `agent:tool_result` event, the session message, and
|
|
3325
|
+
* the log line) -- enforcing there, before that value is emitted, is what makes the four sinks agree
|
|
3326
|
+
* instead of three of them seeing the untruncated payload. See that file's own comment for the
|
|
3327
|
+
* exact insertion point.
|
|
3328
|
+
*/
|
|
3329
|
+
maxOutputTokens?: number;
|
|
3187
3330
|
}
|
|
3188
3331
|
|
|
3189
3332
|
/**
|