@corbat-tech/coco 2.38.0 → 2.40.0

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.
@@ -1,4 +1,4 @@
1
- import { T as ToolRegistry, a as ToolDefinition$1 } from './registry-CEpl9Jq0.js';
1
+ import { z } from 'zod';
2
2
 
3
3
  /**
4
4
  * Unified thinking/reasoning mode support for all LLM providers.
@@ -87,7 +87,7 @@ interface Message {
87
87
  /**
88
88
  * Tool definition for LLM
89
89
  */
90
- interface ToolDefinition {
90
+ interface ToolDefinition$1 {
91
91
  name: string;
92
92
  description: string;
93
93
  input_schema: {
@@ -138,7 +138,7 @@ interface ChatResponse {
138
138
  * Chat with tools options
139
139
  */
140
140
  interface ChatWithToolsOptions extends ChatOptions {
141
- tools: ToolDefinition[];
141
+ tools: ToolDefinition$1[];
142
142
  toolChoice?: "auto" | "any" | {
143
143
  type: "tool";
144
144
  name: string;
@@ -302,19 +302,117 @@ type ProviderType = "anthropic" | "openai" | "codex" | "copilot" | "gemini" | "v
302
302
  */
303
303
  declare function createProvider(type: ProviderType, config?: ProviderConfig): Promise<LLMProvider>;
304
304
 
305
- /** Catalog-backed provider/model registry used by runtime consumers. */
306
- declare class ProviderRegistry {
307
- listProviders(): ProviderCatalogEntry[];
308
- getProvider(provider: ProviderType): ProviderCatalogEntry;
309
- listModels(provider: ProviderType): ModelCatalogEntry[];
310
- getModel(provider: ProviderType, model: string): ModelCatalogEntry | undefined;
311
- getDefaultModel(provider: ProviderType): string;
312
- getRecommendedModel(provider: ProviderType): ModelCatalogEntry;
313
- getCapability(provider: ProviderType, model?: string): ProviderRuntimeCapability;
314
- createProvider(provider: ProviderType, config?: ProviderConfig): Promise<LLMProvider>;
315
- probe(provider: ProviderType, model: string | undefined, checkAvailability?: () => Promise<boolean>): Promise<ProviderProbeResult>;
316
- }
317
- declare function createProviderRegistry(): ProviderRegistry;
305
+ /**
306
+ * Tool Registry for Corbat-Coco
307
+ * Central management of all available tools
308
+ */
309
+
310
+ /**
311
+ * Tool definition
312
+ */
313
+ interface ToolDefinition<TInput = unknown, TOutput = unknown> {
314
+ name: string;
315
+ description: string;
316
+ category: ToolCategory;
317
+ parameters: z.ZodType<TInput, any, any>;
318
+ execute: (params: TInput) => Promise<TOutput>;
319
+ }
320
+ /**
321
+ * Tool categories
322
+ */
323
+ type ToolCategory = "file" | "bash" | "git" | "test" | "quality" | "build" | "deploy" | "config" | "web" | "search" | "memory" | "document";
324
+ /**
325
+ * Tool execution result
326
+ */
327
+ interface ToolResult<T = unknown> {
328
+ success: boolean;
329
+ data?: T;
330
+ error?: string;
331
+ duration: number;
332
+ }
333
+ /**
334
+ * Progress callback for long-running operations
335
+ */
336
+ type ProgressCallback = (progress: ProgressInfo) => void;
337
+ /**
338
+ * Progress information
339
+ */
340
+ interface ProgressInfo {
341
+ /** Current step or phase name */
342
+ phase: string;
343
+ /** Progress percentage (0-100), null if indeterminate */
344
+ percent: number | null;
345
+ /** Human-readable message */
346
+ message?: string;
347
+ /** Estimated time remaining in ms, null if unknown */
348
+ estimatedTimeRemaining?: number | null;
349
+ /** Additional metadata */
350
+ metadata?: Record<string, unknown>;
351
+ }
352
+ /**
353
+ * Options for tool execution
354
+ */
355
+ interface ExecuteOptions {
356
+ /** Progress callback for long operations */
357
+ onProgress?: ProgressCallback;
358
+ /** Abort signal for cancellation */
359
+ signal?: AbortSignal;
360
+ }
361
+ /**
362
+ * Tool registry
363
+ */
364
+ declare class ToolRegistry {
365
+ private tools;
366
+ private logger;
367
+ /**
368
+ * Register a tool
369
+ */
370
+ register<TInput, TOutput>(tool: ToolDefinition<TInput, TOutput>): void;
371
+ /**
372
+ * Unregister a tool
373
+ */
374
+ unregister(name: string): boolean;
375
+ /**
376
+ * Get a tool by name
377
+ */
378
+ get<TInput = unknown, TOutput = unknown>(name: string): ToolDefinition<TInput, TOutput> | undefined;
379
+ /**
380
+ * Check if a tool exists
381
+ */
382
+ has(name: string): boolean;
383
+ /**
384
+ * Get all tools
385
+ */
386
+ getAll(): ToolDefinition[];
387
+ /**
388
+ * Get tools by category
389
+ */
390
+ getByCategory(category: ToolCategory): ToolDefinition[];
391
+ /**
392
+ * Execute a tool
393
+ */
394
+ execute<TInput, TOutput>(name: string, params: TInput, options?: ExecuteOptions): Promise<ToolResult<TOutput>>;
395
+ /**
396
+ * Get tool definitions for LLM (simplified format)
397
+ */
398
+ getToolDefinitionsForLLM(): Array<{
399
+ name: string;
400
+ description: string;
401
+ input_schema: Record<string, unknown>;
402
+ }>;
403
+ }
404
+ /**
405
+ * Get the global tool registry
406
+ */
407
+ declare function getToolRegistry(): ToolRegistry;
408
+ /**
409
+ * Create a new tool registry
410
+ */
411
+ declare function createToolRegistry(): ToolRegistry;
412
+ /**
413
+ * Helper to create a tool definition with type safety
414
+ */
415
+ declare function defineTool<TInput, TOutput>(definition: ToolDefinition<TInput, TOutput>): ToolDefinition<TInput, TOutput>;
318
416
 
319
417
  /**
320
418
  * Agent mode registry.
@@ -336,155 +434,6 @@ declare function getAgentMode(mode: AgentModeId): AgentModeDefinition;
336
434
  declare function listAgentModes(): AgentModeDefinition[];
337
435
  declare function isAgentMode(value: string): value is AgentModeId;
338
436
 
339
- type ReasoningEffort = "auto" | "low" | "medium" | "high" | "max";
340
- type RuntimeMode = AgentModeId;
341
- interface AgentRuntimeOptions {
342
- providerType: ProviderType;
343
- model?: string;
344
- providerConfig?: ProviderConfig;
345
- provider?: LLMProvider;
346
- toolRegistry?: ToolRegistry;
347
- /** Legacy CLI session store passthrough. Runtime APIs use runtimeSessionStore. */
348
- sessionStore?: unknown;
349
- runtimeSessionStore?: RuntimeSessionStore;
350
- workflowEngine?: WorkflowEngine;
351
- permissionPolicy?: PermissionPolicy;
352
- eventLog?: EventLog;
353
- eventLogPath?: string;
354
- turnRunner?: RuntimeTurnRunner;
355
- /**
356
- * Publish provider/tools into Coco's legacy process-global subagent bridge.
357
- * CLI/headless use this for compatibility; embedders should leave it false.
358
- */
359
- publishToGlobalBridge?: boolean;
360
- }
361
- interface AgentRuntimeSnapshot {
362
- provider: {
363
- type: ProviderType;
364
- model: string;
365
- capability: ProviderRuntimeCapability;
366
- };
367
- tools: {
368
- count: number;
369
- names: string[];
370
- };
371
- modes: AgentModeDefinition[];
372
- }
373
- type RuntimeEventType = "runtime.initialized" | "provider.attached" | "provider.created" | "provider.updated" | "turn.started" | "turn.completed" | "turn.cancelled" | "turn.failed" | "tool.started" | "tool.completed" | "tool.allowed" | "tool.blocked" | "tool.skipped" | "agent.started" | "agent.tool.called" | "agent.artifact.created" | "agent.completed" | "agent.failed" | "guardrail.input" | "guardrail.output" | "guardrail.tool" | "workflow.planned" | "workflow.started" | "workflow.completed" | "workflow.failed" | "workflow.gate.failed" | "session.created" | "session.updated" | "checkpoint.created" | "error";
374
- interface RuntimeEvent {
375
- id: string;
376
- type: RuntimeEventType;
377
- timestamp: string;
378
- data: Record<string, unknown>;
379
- }
380
- interface EventLog {
381
- record(type: RuntimeEventType, data?: Record<string, unknown>): RuntimeEvent;
382
- list(): RuntimeEvent[];
383
- count(): number;
384
- clear(): void;
385
- }
386
- interface PermissionDecision {
387
- allowed: boolean;
388
- reason?: string;
389
- requiresConfirmation?: boolean;
390
- risk: "read-only" | "write" | "network" | "destructive" | "secrets-sensitive";
391
- }
392
- interface PermissionPolicy {
393
- canExecuteTool(mode: RuntimeMode, tool: ToolDefinition$1): PermissionDecision;
394
- canExecuteToolInput?(mode: RuntimeMode, tool: ToolDefinition$1, input: Record<string, unknown>): PermissionDecision;
395
- }
396
- interface ProviderRuntimeSelection {
397
- provider: ProviderType;
398
- model: string;
399
- thinking?: ThinkingMode;
400
- }
401
- interface RuntimeSession {
402
- id: string;
403
- createdAt: string;
404
- updatedAt: string;
405
- mode: RuntimeMode;
406
- messages: Message[];
407
- instructions?: string;
408
- metadata: Record<string, unknown>;
409
- }
410
- interface RuntimeSessionCreateOptions {
411
- id?: string;
412
- mode?: RuntimeMode;
413
- instructions?: string;
414
- metadata?: Record<string, unknown>;
415
- messages?: Message[];
416
- }
417
- interface RuntimeSessionStore {
418
- create(options?: RuntimeSessionCreateOptions): RuntimeSession;
419
- get(id: string): RuntimeSession | undefined;
420
- update(session: RuntimeSession): RuntimeSession;
421
- list(): RuntimeSession[];
422
- delete(id: string): boolean;
423
- }
424
- interface RuntimeTurnInput {
425
- content: string;
426
- sessionId?: string;
427
- mode?: RuntimeMode;
428
- options?: ChatOptions;
429
- metadata?: Record<string, unknown>;
430
- /**
431
- * Tool names that the embedding product has explicitly confirmed for this
432
- * turn. Destructive tools are still blocked unless listed here.
433
- */
434
- confirmedTools?: string[];
435
- }
436
- interface RuntimeTurnResult {
437
- sessionId: string;
438
- content: string;
439
- usage: {
440
- inputTokens: number;
441
- outputTokens: number;
442
- estimated?: boolean;
443
- };
444
- model: string;
445
- mode: RuntimeMode;
446
- }
447
- type RuntimeTurnStreamEvent = {
448
- type: "text";
449
- sessionId: string;
450
- text: string;
451
- } | {
452
- type: "done";
453
- sessionId: string;
454
- result: RuntimeTurnResult;
455
- } | {
456
- type: "error";
457
- sessionId: string;
458
- error: string;
459
- };
460
- interface RuntimeTurnContext {
461
- runtime: unknown;
462
- session: RuntimeSession;
463
- provider: LLMProvider;
464
- toolRegistry: ToolRegistry;
465
- permissionPolicy: PermissionPolicy;
466
- eventLog: EventLog;
467
- }
468
- interface RuntimeTurnRunner {
469
- run(input: RuntimeTurnInput, context: RuntimeTurnContext): Promise<RuntimeTurnResult>;
470
- }
471
- interface RuntimeToolExecutionInput {
472
- sessionId?: string;
473
- mode?: RuntimeMode;
474
- toolName: string;
475
- input: Record<string, unknown>;
476
- confirmed?: boolean;
477
- metadata?: Record<string, unknown>;
478
- }
479
- interface RuntimeToolExecutionResult {
480
- toolName: string;
481
- success: boolean;
482
- output?: unknown;
483
- error?: string;
484
- duration: number;
485
- decision: PermissionDecision;
486
- }
487
-
488
437
  type AgentRole = "researcher" | "planner" | "architect" | "editor" | "coder" | "tester" | "reviewer" | "optimizer" | "security" | "qa" | "integrator" | "pm" | "docs" | "database";
489
438
  interface AgentBudget {
490
439
  maxTurns?: number;
@@ -492,6 +441,7 @@ interface AgentBudget {
492
441
  maxInputTokens?: number;
493
442
  maxOutputTokens?: number;
494
443
  maxEstimatedCostUsd?: number;
444
+ maxConcurrentRuns?: number;
495
445
  }
496
446
  interface AgentCapability {
497
447
  role: AgentRole;
@@ -500,7 +450,31 @@ interface AgentCapability {
500
450
  model?: string;
501
451
  temperature?: number;
502
452
  budget?: AgentBudget;
453
+ guardrails?: AgentGuardrailPolicy;
454
+ }
455
+ interface AgentGuardrailPolicy {
456
+ input?: boolean;
457
+ output?: boolean;
458
+ toolUse?: boolean;
459
+ redactSecrets?: boolean;
460
+ blockPromptInjection?: boolean;
461
+ }
462
+ interface AgentDefinition {
463
+ id: string;
464
+ role: AgentRole;
465
+ name: string;
466
+ instructions: string;
467
+ capability: AgentCapability;
468
+ outputSchema?: Record<string, unknown>;
469
+ metadata?: Record<string, unknown>;
503
470
  }
471
+ interface LegacyAgentRoleMapping {
472
+ legacy: string;
473
+ role: AgentRole;
474
+ reason: string;
475
+ }
476
+ declare function mapLegacyAgentRole(legacyRole: string, fallback?: AgentRole): AgentRole;
477
+ declare function listLegacyAgentRoleMappings(): LegacyAgentRoleMapping[];
504
478
  interface AgentTask {
505
479
  id: string;
506
480
  role: AgentRole;
@@ -543,6 +517,35 @@ interface AgentRunResult {
543
517
  completedAt: string;
544
518
  metadata?: Record<string, unknown>;
545
519
  }
520
+ type AgentMessageRole = "user" | "agent" | "system" | "tool";
521
+ interface AgentMessage {
522
+ id: string;
523
+ role: AgentMessageRole;
524
+ content: string;
525
+ taskId?: string;
526
+ agentRunId?: string;
527
+ createdAt: string;
528
+ metadata?: Record<string, unknown>;
529
+ }
530
+ interface AgentHandoff {
531
+ id: string;
532
+ fromAgentRunId: string;
533
+ toRole: AgentRole;
534
+ task: AgentTask;
535
+ artifacts: AgentArtifact[];
536
+ createdAt: string;
537
+ metadata?: Record<string, unknown>;
538
+ }
539
+ interface AgentCard {
540
+ id: string;
541
+ role: AgentRole;
542
+ name: string;
543
+ description: string;
544
+ skills: string[];
545
+ inputSchema?: Record<string, unknown>;
546
+ outputSchema?: Record<string, unknown>;
547
+ capability: AgentCapability;
548
+ }
546
549
  type AgentGateKind = "tests" | "coverage" | "review" | "security" | "quality-score" | "human-approval";
547
550
  interface AgentGateDefinition {
548
551
  id: string;
@@ -563,6 +566,7 @@ interface AgentGraphNode {
563
566
  maxAttempts: number;
564
567
  backoffMs?: number;
565
568
  };
569
+ timeoutMs?: number;
566
570
  condition?: string;
567
571
  }
568
572
  interface AgentGraphEdge {
@@ -595,7 +599,62 @@ interface SharedWorkspaceStateSnapshot {
595
599
  testResults: Record<string, unknown>;
596
600
  artifacts: AgentArtifact[];
597
601
  }
602
+ type SharedWorkspaceRecordKind = "fact" | "decision" | "risk" | "file" | "testResult" | "artifact";
603
+ interface SharedWorkspaceProvenance {
604
+ workflowRunId: string;
605
+ agentRunId?: string;
606
+ nodeId?: string;
607
+ taskId?: string;
608
+ eventId?: string;
609
+ confidence?: number;
610
+ risk?: WorkflowRisk;
611
+ }
612
+ interface SharedWorkspaceRecord {
613
+ id: string;
614
+ kind: SharedWorkspaceRecordKind;
615
+ key: string;
616
+ value: unknown;
617
+ provenance: SharedWorkspaceProvenance;
618
+ createdAt: string;
619
+ }
620
+ interface SharedWorkspaceWriteInput {
621
+ id?: string;
622
+ kind: SharedWorkspaceRecordKind;
623
+ key: string;
624
+ value: unknown;
625
+ provenance: SharedWorkspaceProvenance;
626
+ createdAt?: string;
627
+ }
628
+ interface SharedWorkspaceStore {
629
+ write(input: SharedWorkspaceWriteInput): SharedWorkspaceRecord;
630
+ list(): SharedWorkspaceRecord[];
631
+ snapshot(): SharedWorkspaceStateSnapshot;
632
+ readForRole(role: AgentRole): SharedWorkspaceStateSnapshot;
633
+ clear(): void;
634
+ }
635
+ declare class InMemorySharedWorkspaceStore implements SharedWorkspaceStore {
636
+ private records;
637
+ write(input: SharedWorkspaceWriteInput): SharedWorkspaceRecord;
638
+ list(): SharedWorkspaceRecord[];
639
+ snapshot(): SharedWorkspaceStateSnapshot;
640
+ readForRole(role: AgentRole): SharedWorkspaceStateSnapshot;
641
+ clear(): void;
642
+ }
643
+ declare class FileSharedWorkspaceStore implements SharedWorkspaceStore {
644
+ private readonly filePath;
645
+ private readonly memory;
646
+ private writable;
647
+ constructor(filePath: string);
648
+ write(input: SharedWorkspaceWriteInput): SharedWorkspaceRecord;
649
+ list(): SharedWorkspaceRecord[];
650
+ snapshot(): SharedWorkspaceStateSnapshot;
651
+ readForRole(role: AgentRole): SharedWorkspaceStateSnapshot;
652
+ clear(): void;
653
+ private readRecordsFromDisk;
654
+ }
598
655
  declare class SharedWorkspaceState {
656
+ private readonly workflowRunId;
657
+ private readonly store;
599
658
  private facts;
600
659
  private decisions;
601
660
  private risks;
@@ -610,7 +669,102 @@ declare class SharedWorkspaceState {
610
669
  addArtifact(artifact: AgentArtifact): void;
611
670
  readForRole(role: AgentRole): SharedWorkspaceStateSnapshot;
612
671
  snapshot(): SharedWorkspaceStateSnapshot;
672
+ records(): SharedWorkspaceRecord[];
673
+ }
674
+ type ToolRiskLevel = "low" | "medium" | "high" | "critical";
675
+ interface ToolRiskManifestEntry {
676
+ toolName: string;
677
+ risk: WorkflowRisk;
678
+ level: ToolRiskLevel;
679
+ requiredCapability?: AgentRole | AgentRole[];
680
+ requiresConsent?: boolean;
681
+ destructive?: boolean;
682
+ secretsSensitive?: boolean;
683
+ network?: boolean;
684
+ filesystem?: boolean;
613
685
  }
686
+ type ToolRiskManifest = Record<string, ToolRiskManifestEntry>;
687
+ interface AgentToolPolicyDecision {
688
+ allowed: boolean;
689
+ risk: WorkflowRisk;
690
+ reason?: string;
691
+ requiresConsent?: boolean;
692
+ }
693
+ declare function evaluateAgentToolPolicy(input: {
694
+ capability: AgentCapability;
695
+ toolName: string;
696
+ manifest?: ToolRiskManifest;
697
+ }): AgentToolPolicyDecision;
698
+ interface AgentTraceContext {
699
+ traceId: string;
700
+ spanId: string;
701
+ parentSpanId?: string;
702
+ workflowRunId?: string;
703
+ agentRunId?: string;
704
+ taskId?: string;
705
+ toolCallId?: string;
706
+ }
707
+ declare function createAgentTraceContext(input?: Partial<AgentTraceContext>): AgentTraceContext;
708
+ interface AgentGraphNodeExecution {
709
+ node: AgentGraphNode;
710
+ task: AgentTask;
711
+ attempt: number;
712
+ workflowRunId: string;
713
+ trace: AgentTraceContext;
714
+ dependencyResults: Map<string, AgentRunResult>;
715
+ sharedState: SharedWorkspaceStore;
716
+ eventLog: EventLog;
717
+ }
718
+ type AgentGraphNodeExecutor = (execution: AgentGraphNodeExecution) => Promise<AgentRunResult>;
719
+ type AgentGateEvaluator = (input: {
720
+ gate: AgentGateDefinition;
721
+ node: AgentGraphNode;
722
+ result: AgentRunResult;
723
+ workflowRunId: string;
724
+ trace: AgentTraceContext;
725
+ sharedState: SharedWorkspaceStore;
726
+ eventLog: EventLog;
727
+ }) => Promise<{
728
+ passed: boolean;
729
+ reason?: string;
730
+ }>;
731
+ interface AgentGraphEngineOptions {
732
+ eventLog?: EventLog;
733
+ sharedState?: SharedWorkspaceStore;
734
+ nodeExecutor?: AgentGraphNodeExecutor;
735
+ gateEvaluator?: AgentGateEvaluator;
736
+ trace?: AgentTraceContext;
737
+ allowSimulated?: boolean;
738
+ }
739
+ interface AgentGraphRunInput {
740
+ workflowRunId: string;
741
+ graph: AgentGraphDefinition;
742
+ input: Record<string, unknown>;
743
+ }
744
+ type AgentGraphRunStatus = "completed" | "failed";
745
+ interface AgentGraphRunResult {
746
+ id: string;
747
+ status: AgentGraphRunStatus;
748
+ nodeResults: Record<string, AgentRunResult>;
749
+ artifacts: AgentArtifact[];
750
+ stateSnapshot: SharedWorkspaceStateSnapshot;
751
+ trace: AgentTraceContext;
752
+ startedAt: string;
753
+ completedAt: string;
754
+ error?: string;
755
+ }
756
+ declare class AgentGraphEngine {
757
+ private readonly eventLog?;
758
+ private readonly sharedState;
759
+ private readonly nodeExecutor;
760
+ private readonly gateEvaluator;
761
+ private readonly trace;
762
+ constructor(options?: AgentGraphEngineOptions);
763
+ run(input: AgentGraphRunInput): Promise<AgentGraphRunResult>;
764
+ private executeNode;
765
+ private evaluateNodeGates;
766
+ }
767
+ declare function createAgentGraphEngine(options?: AgentGraphEngineOptions): AgentGraphEngine;
614
768
  declare function createAgentArtifact<T>(input: Omit<AgentArtifact<T>, "id" | "createdAt"> & {
615
769
  id?: string;
616
770
  createdAt?: string;
@@ -637,6 +791,7 @@ declare function normalizeAgentRunResult(input: {
637
791
  }): AgentRunResult;
638
792
  declare function validateAgentCapabilities(capability: AgentCapability, requiredTools?: string[]): AgentGraphValidationIssue[];
639
793
  declare function validateAgentGraph(graph: AgentGraphDefinition): AgentGraphValidationResult;
794
+ declare function dryRunAgentGraphNodeExecutor(execution: AgentGraphNodeExecution): Promise<AgentRunResult>;
640
795
 
641
796
  type WorkflowRisk = "read-only" | "write" | "network" | "destructive" | "secrets-sensitive";
642
797
  interface WorkflowStepDefinition {
@@ -687,6 +842,219 @@ declare const WorkflowRegistry: typeof WorkflowCatalog;
687
842
  declare function createWorkflowCatalog(workflows?: WorkflowDefinition[]): WorkflowCatalog;
688
843
  declare function createWorkflowRegistry(workflows?: WorkflowDefinition[]): WorkflowCatalog;
689
844
 
845
+ type RuntimeSurface = "cli" | "api" | "web" | "whatsapp" | "slack" | "teams" | "internal" | "mcp" | "worker";
846
+ interface TenantContext {
847
+ id: string;
848
+ name?: string;
849
+ environment?: "development" | "staging" | "production";
850
+ metadata?: Record<string, unknown>;
851
+ }
852
+ interface UserContext {
853
+ id?: string;
854
+ displayName?: string;
855
+ roles?: string[];
856
+ groups?: string[];
857
+ metadata?: Record<string, unknown>;
858
+ }
859
+ interface DataBoundary {
860
+ region?: string;
861
+ classification?: "public" | "internal" | "confidential" | "restricted";
862
+ allowCrossTenantMemory?: boolean;
863
+ redactSensitiveData?: boolean;
864
+ }
865
+ interface CostBudget {
866
+ maxInputTokens?: number;
867
+ maxOutputTokens?: number;
868
+ maxEstimatedCostUsd?: number;
869
+ maxTurns?: number;
870
+ }
871
+ interface RetentionPolicy {
872
+ conversationDays?: number;
873
+ eventDays?: number;
874
+ artifactDays?: number;
875
+ }
876
+ interface RuntimePolicy {
877
+ allowedTools?: string[];
878
+ maxToolRisk?: WorkflowRisk;
879
+ requireHumanApprovalFor?: WorkflowRisk[];
880
+ dataBoundary?: DataBoundary;
881
+ costBudget?: CostBudget;
882
+ retention?: RetentionPolicy;
883
+ rateLimit?: {
884
+ maxRequestsPerMinute?: number;
885
+ maxConcurrentRuns?: number;
886
+ };
887
+ }
888
+ interface RuntimeRequestContext {
889
+ tenant?: TenantContext;
890
+ user?: UserContext;
891
+ surface: RuntimeSurface;
892
+ channel?: string;
893
+ correlationId?: string;
894
+ policy?: RuntimePolicy;
895
+ metadata?: Record<string, unknown>;
896
+ }
897
+ declare function createRuntimeRequestContext(input?: Partial<RuntimeRequestContext>): RuntimeRequestContext;
898
+ declare function mergeRuntimePolicy(base: RuntimePolicy | undefined, override: RuntimePolicy | undefined): RuntimePolicy | undefined;
899
+ declare function runtimeContextToMetadata(context: RuntimeRequestContext | undefined): Record<string, unknown>;
900
+
901
+ type ReasoningEffort = "auto" | "low" | "medium" | "high" | "max";
902
+ type RuntimeMode = AgentModeId;
903
+ interface AgentRuntimeOptions {
904
+ providerType: ProviderType;
905
+ model?: string;
906
+ providerConfig?: ProviderConfig;
907
+ provider?: LLMProvider;
908
+ toolRegistry?: ToolRegistry;
909
+ /** Legacy CLI session store passthrough. Runtime APIs use runtimeSessionStore. */
910
+ sessionStore?: unknown;
911
+ runtimeSessionStore?: RuntimeSessionStore;
912
+ workflowEngine?: WorkflowEngine;
913
+ permissionPolicy?: PermissionPolicy;
914
+ eventLog?: EventLog;
915
+ eventLogPath?: string;
916
+ turnRunner?: RuntimeTurnRunner;
917
+ /**
918
+ * Publish provider/tools into Coco's legacy process-global subagent bridge.
919
+ * CLI/headless use this for compatibility; embedders should leave it false.
920
+ */
921
+ publishToGlobalBridge?: boolean;
922
+ legacyAgentBridge?: {
923
+ setAgentProvider(provider: LLMProvider): void;
924
+ setAgentToolRegistry(registry: ToolRegistry): void;
925
+ };
926
+ runtimeContext?: RuntimeRequestContext;
927
+ runtimePolicy?: RuntimePolicy;
928
+ }
929
+ interface AgentRuntimeSnapshot {
930
+ provider: {
931
+ type: ProviderType;
932
+ model: string;
933
+ capability: ProviderRuntimeCapability;
934
+ };
935
+ tools: {
936
+ count: number;
937
+ names: string[];
938
+ };
939
+ modes: AgentModeDefinition[];
940
+ context?: RuntimeRequestContext;
941
+ policy?: RuntimePolicy;
942
+ }
943
+ type RuntimeEventType = "runtime.initialized" | "provider.attached" | "provider.created" | "provider.updated" | "turn.started" | "turn.completed" | "turn.cancelled" | "turn.failed" | "tool.started" | "tool.completed" | "tool.allowed" | "tool.blocked" | "tool.skipped" | "agent.started" | "agent.graph.started" | "agent.graph.completed" | "agent.graph.failed" | "agent.tool.called" | "agent.handoff.created" | "agent.artifact.created" | "agent.completed" | "agent.failed" | "guardrail.input" | "guardrail.output" | "guardrail.tool" | "workflow.planned" | "workflow.started" | "workflow.completed" | "workflow.failed" | "workflow.gate.passed" | "workflow.gate.failed" | "shared_state.updated" | "session.created" | "session.updated" | "checkpoint.created" | "error";
944
+ interface RuntimeEvent {
945
+ id: string;
946
+ type: RuntimeEventType;
947
+ timestamp: string;
948
+ data: Record<string, unknown>;
949
+ }
950
+ interface EventLog {
951
+ record(type: RuntimeEventType, data?: Record<string, unknown>): RuntimeEvent;
952
+ list(): RuntimeEvent[];
953
+ count(): number;
954
+ clear(): void;
955
+ }
956
+ interface PermissionDecision {
957
+ allowed: boolean;
958
+ reason?: string;
959
+ requiresConfirmation?: boolean;
960
+ risk: "read-only" | "write" | "network" | "destructive" | "secrets-sensitive";
961
+ }
962
+ interface PermissionPolicy {
963
+ canExecuteTool(mode: RuntimeMode, tool: ToolDefinition): PermissionDecision;
964
+ canExecuteToolInput?(mode: RuntimeMode, tool: ToolDefinition, input: Record<string, unknown>): PermissionDecision;
965
+ }
966
+ interface ProviderRuntimeSelection {
967
+ provider: ProviderType;
968
+ model: string;
969
+ thinking?: ThinkingMode;
970
+ }
971
+ interface RuntimeSession {
972
+ id: string;
973
+ createdAt: string;
974
+ updatedAt: string;
975
+ mode: RuntimeMode;
976
+ messages: Message[];
977
+ instructions?: string;
978
+ metadata: Record<string, unknown>;
979
+ }
980
+ interface RuntimeSessionCreateOptions {
981
+ id?: string;
982
+ mode?: RuntimeMode;
983
+ instructions?: string;
984
+ metadata?: Record<string, unknown>;
985
+ messages?: Message[];
986
+ }
987
+ interface RuntimeSessionStore {
988
+ create(options?: RuntimeSessionCreateOptions): RuntimeSession;
989
+ get(id: string): RuntimeSession | undefined;
990
+ update(session: RuntimeSession): RuntimeSession;
991
+ list(): RuntimeSession[];
992
+ delete(id: string): boolean;
993
+ }
994
+ interface RuntimeTurnInput {
995
+ content: string;
996
+ sessionId?: string;
997
+ mode?: RuntimeMode;
998
+ options?: ChatOptions;
999
+ metadata?: Record<string, unknown>;
1000
+ /**
1001
+ * Tool names that the embedding product has explicitly confirmed for this
1002
+ * turn. Destructive tools are still blocked unless listed here.
1003
+ */
1004
+ confirmedTools?: string[];
1005
+ }
1006
+ interface RuntimeTurnResult {
1007
+ sessionId: string;
1008
+ content: string;
1009
+ usage: {
1010
+ inputTokens: number;
1011
+ outputTokens: number;
1012
+ estimated?: boolean;
1013
+ };
1014
+ model: string;
1015
+ mode: RuntimeMode;
1016
+ }
1017
+ type RuntimeTurnStreamEvent = {
1018
+ type: "text";
1019
+ sessionId: string;
1020
+ text: string;
1021
+ } | {
1022
+ type: "done";
1023
+ sessionId: string;
1024
+ result: RuntimeTurnResult;
1025
+ } | {
1026
+ type: "error";
1027
+ sessionId: string;
1028
+ error: string;
1029
+ };
1030
+ interface RuntimeTurnContext {
1031
+ runtime: unknown;
1032
+ session: RuntimeSession;
1033
+ provider: LLMProvider;
1034
+ toolRegistry: ToolRegistry;
1035
+ permissionPolicy: PermissionPolicy;
1036
+ eventLog: EventLog;
1037
+ }
1038
+ interface RuntimeTurnRunner {
1039
+ run(input: RuntimeTurnInput, context: RuntimeTurnContext): Promise<RuntimeTurnResult>;
1040
+ }
1041
+ interface RuntimeToolExecutionInput {
1042
+ sessionId?: string;
1043
+ mode?: RuntimeMode;
1044
+ toolName: string;
1045
+ input: Record<string, unknown>;
1046
+ confirmed?: boolean;
1047
+ metadata?: Record<string, unknown>;
1048
+ }
1049
+ interface RuntimeToolExecutionResult {
1050
+ toolName: string;
1051
+ success: boolean;
1052
+ output?: unknown;
1053
+ error?: string;
1054
+ duration: number;
1055
+ decision: PermissionDecision;
1056
+ }
1057
+
690
1058
  type WorkflowRunStatus = "completed" | "failed";
691
1059
  interface WorkflowRunInput {
692
1060
  workflowId: string;
@@ -701,6 +1069,8 @@ interface WorkflowRunResult {
701
1069
  startedAt: string;
702
1070
  completedAt: string;
703
1071
  error?: string;
1072
+ graphResult?: AgentGraphRunResult;
1073
+ trace?: AgentTraceContext;
704
1074
  }
705
1075
  interface WorkflowRunContext {
706
1076
  workflow: WorkflowDefinition;
@@ -708,49 +1078,26 @@ interface WorkflowRunContext {
708
1078
  eventLog: EventLog;
709
1079
  }
710
1080
  type WorkflowHandler = (input: Record<string, unknown>, context: WorkflowRunContext) => Promise<unknown>;
1081
+ interface WorkflowEngineOptions {
1082
+ catalog?: WorkflowCatalog;
1083
+ eventLog?: EventLog;
1084
+ sharedState?: SharedWorkspaceStore;
1085
+ nodeExecutor?: AgentGraphNodeExecutor;
1086
+ runtimePolicy?: RuntimePolicy;
1087
+ }
711
1088
  declare class WorkflowEngine {
712
1089
  private readonly catalog;
713
1090
  private readonly eventLog;
714
1091
  private handlers;
715
- constructor(catalog?: WorkflowCatalog, eventLog?: EventLog);
1092
+ private readonly sharedState;
1093
+ private readonly runtimePolicy?;
1094
+ private nodeExecutor?;
1095
+ constructor(catalog?: WorkflowCatalog, eventLog?: EventLog, options?: Omit<WorkflowEngineOptions, "catalog" | "eventLog">);
716
1096
  registerHandler(workflowId: string, handler: WorkflowHandler): void;
1097
+ registerNodeExecutor(executor: AgentGraphNodeExecutor): void;
717
1098
  createPlan(workflowId: string, input: Record<string, unknown>): WorkflowPlan;
718
1099
  run(request: WorkflowRunInput): Promise<WorkflowRunResult>;
719
1100
  }
720
- declare function createWorkflowEngine(catalog?: WorkflowCatalog, eventLog?: EventLog): WorkflowEngine;
721
-
722
- /**
723
- * Reusable runtime facade for wiring providers, tools, permissions, sessions,
724
- * and observability. It does not own the CLI loop; CLI/headless are adapters on
725
- * top of this boundary.
726
- */
727
- declare class AgentRuntime {
728
- private readonly options;
729
- readonly providerRegistry: ProviderRegistry;
730
- readonly toolRegistry: ToolRegistry;
731
- readonly sessionStore: unknown;
732
- readonly runtimeSessionStore: RuntimeSessionStore;
733
- readonly workflowEngine: WorkflowEngine;
734
- readonly permissionPolicy: PermissionPolicy;
735
- readonly eventLog: EventLog;
736
- readonly turnRunner: RuntimeTurnRunner;
737
- private providerType;
738
- private model;
739
- private provider?;
740
- constructor(options: AgentRuntimeOptions);
741
- initialize(): Promise<void>;
742
- getModel(): string;
743
- updateProvider(providerType: ProviderType, model: string | undefined, provider: LLMProvider): void;
744
- private publishToGlobalBridge;
745
- snapshot(): AgentRuntimeSnapshot;
746
- createSession(options?: RuntimeSessionCreateOptions): RuntimeSession;
747
- getSession(sessionId: string): RuntimeSession | undefined;
748
- listSessions(): RuntimeSession[];
749
- runTurn(input: RuntimeTurnInput): Promise<RuntimeTurnResult>;
750
- streamTurn(input: RuntimeTurnInput): AsyncIterable<RuntimeTurnStreamEvent>;
751
- executeTool(input: RuntimeToolExecutionInput): Promise<RuntimeToolExecutionResult>;
752
- assertToolAllowed(mode: RuntimeMode, toolName: string, input?: Record<string, unknown>): boolean;
753
- }
754
- declare function createAgentRuntime(options: AgentRuntimeOptions): Promise<AgentRuntime>;
1101
+ declare function createWorkflowEngine(catalog?: WorkflowCatalog, eventLog?: EventLog, options?: Omit<WorkflowEngineOptions, "catalog" | "eventLog">): WorkflowEngine;
755
1102
 
756
- export { WorkflowEngine as $, AGENT_MODES as A, type AgentTask as B, type ChatOptions as C, DEFAULT_WORKFLOWS as D, type EventLog as E, type RuntimeEvent as F, type RuntimeEventType as G, type RuntimeMode as H, type RuntimeSession as I, type RuntimeSessionCreateOptions as J, type RuntimeSessionStore as K, type LLMProvider as L, type Message as M, type RuntimeToolExecutionInput as N, type RuntimeToolExecutionResult as O, type ProviderConfig as P, type RuntimeTurnContext as Q, type ReasoningEffort as R, type StreamChunk as S, type RuntimeTurnInput as T, type RuntimeTurnResult as U, type RuntimeTurnRunner as V, type RuntimeTurnStreamEvent as W, SharedWorkspaceState as X, type SharedWorkspaceStateSnapshot as Y, WorkflowCatalog as Z, type WorkflowDefinition as _, type ChatResponse as a, type WorkflowHandler as a0, type WorkflowPlan as a1, WorkflowRegistry as a2, type WorkflowRetryPolicy as a3, type WorkflowRisk as a4, type WorkflowRunContext as a5, type WorkflowRunInput as a6, type WorkflowRunResult as a7, type WorkflowRunStatus as a8, type WorkflowStepDefinition as a9, createAgentArtifact as aa, createAgentRuntime as ab, createProvider as ac, createProviderRegistry as ad, createSummaryArtifact as ae, createWorkflowCatalog as af, createWorkflowEngine as ag, createWorkflowRegistry as ah, getAgentMode as ai, isAgentMode as aj, listAgentModes as ak, normalizeAgentRunResult as al, validateAgentCapabilities as am, validateAgentGraph as an, workflowToAgentGraph as ao, type ProviderType as ap, type ChatWithToolsOptions as b, type ChatWithToolsResponse as c, type AgentArtifact as d, type AgentArtifactKind as e, type AgentBudget as f, type AgentCapability as g, type AgentGateDefinition as h, type AgentGateKind as i, type AgentGraphDefinition as j, type AgentGraphEdge as k, type AgentGraphNode as l, type AgentGraphValidationIssue as m, type AgentGraphValidationResult as n, type AgentModeDefinition as o, type AgentModeId as p, type AgentRole as q, type AgentRunResult as r, type AgentRunStatus as s, AgentRuntime as t, type AgentRuntimeOptions as u, type AgentRuntimeSnapshot as v, type PermissionDecision as w, type PermissionPolicy as x, ProviderRegistry as y, type ProviderRuntimeSelection as z };
1103
+ export { type RetentionPolicy as $, AGENT_MODES as A, type AgentMessageRole as B, type ChatOptions as C, type AgentModeDefinition as D, type AgentModeId as E, type AgentRole as F, type AgentRunResult as G, type AgentRunStatus as H, type AgentRuntimeOptions as I, type AgentRuntimeSnapshot as J, type AgentToolPolicyDecision as K, type LLMProvider as L, type Message as M, type AgentTraceContext as N, type CostBudget as O, type ProviderConfig as P, DEFAULT_WORKFLOWS as Q, type DataBoundary as R, type StreamChunk as S, type EventLog as T, FileSharedWorkspaceStore as U, InMemorySharedWorkspaceStore as V, type LegacyAgentRoleMapping as W, type PermissionDecision as X, type PermissionPolicy as Y, type ProviderRuntimeSelection as Z, type ReasoningEffort as _, type ChatResponse as a, validateAgentCapabilities as a$, type AgentTask as a0, type RuntimeEvent as a1, type RuntimeEventType as a2, type RuntimeMode as a3, type RuntimePolicy as a4, type RuntimeRequestContext as a5, type RuntimeSession as a6, type RuntimeSessionCreateOptions as a7, type RuntimeSessionStore as a8, type RuntimeSurface as a9, type WorkflowRetryPolicy as aA, type WorkflowRisk as aB, type WorkflowRunContext as aC, type WorkflowRunInput as aD, type WorkflowRunResult as aE, type WorkflowRunStatus as aF, type WorkflowStepDefinition as aG, createAgentArtifact as aH, createAgentGraphEngine as aI, createAgentTraceContext as aJ, createProvider as aK, createRuntimeRequestContext as aL, createSummaryArtifact as aM, createToolRegistry as aN, createWorkflowCatalog as aO, createWorkflowEngine as aP, createWorkflowRegistry as aQ, dryRunAgentGraphNodeExecutor as aR, evaluateAgentToolPolicy as aS, getAgentMode as aT, isAgentMode as aU, listAgentModes as aV, listLegacyAgentRoleMappings as aW, mapLegacyAgentRole as aX, mergeRuntimePolicy as aY, normalizeAgentRunResult as aZ, runtimeContextToMetadata as a_, type RuntimeToolExecutionInput as aa, type RuntimeToolExecutionResult as ab, type RuntimeTurnContext as ac, type RuntimeTurnInput as ad, type RuntimeTurnResult as ae, type RuntimeTurnRunner as af, type RuntimeTurnStreamEvent as ag, type SharedWorkspaceProvenance as ah, type SharedWorkspaceRecord as ai, type SharedWorkspaceRecordKind as aj, SharedWorkspaceState as ak, type SharedWorkspaceStateSnapshot as al, type SharedWorkspaceStore as am, type SharedWorkspaceWriteInput as an, type TenantContext as ao, ToolRegistry as ap, type ToolRiskLevel as aq, type ToolRiskManifest as ar, type ToolRiskManifestEntry as as, type UserContext as at, WorkflowCatalog as au, type WorkflowDefinition as av, WorkflowEngine as aw, type WorkflowHandler as ax, type WorkflowPlan as ay, WorkflowRegistry as az, type ChatWithToolsOptions as b, validateAgentGraph as b0, workflowToAgentGraph as b1, type ToolDefinition as b2, type ToolCategory as b3, type ToolResult as b4, defineTool as b5, getToolRegistry as b6, type ProviderType as b7, type ProviderCatalogEntry as b8, type ModelCatalogEntry as b9, type ProviderRuntimeCapability as ba, type ProviderProbeResult as bb, type ChatWithToolsResponse as c, type AgentArtifact as d, type AgentArtifactKind as e, type AgentBudget as f, type AgentCapability as g, type AgentCard as h, type AgentDefinition as i, type AgentGateDefinition as j, type AgentGateKind as k, type AgentGraphDefinition as l, type AgentGraphEdge as m, AgentGraphEngine as n, type AgentGraphEngineOptions as o, type AgentGraphNode as p, type AgentGraphNodeExecution as q, type AgentGraphNodeExecutor as r, type AgentGraphRunInput as s, type AgentGraphRunResult as t, type AgentGraphRunStatus as u, type AgentGraphValidationIssue as v, type AgentGraphValidationResult as w, type AgentGuardrailPolicy as x, type AgentHandoff as y, type AgentMessage as z };