@codeworksh/harness 0.9.0-canary.167.1.g6ddcc8db → 0.9.0-canary.168.1.ge6d0f923

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/effect.d.mts CHANGED
@@ -1,6 +1,8 @@
1
1
  import { s as index_d_exports$1 } from "./index-Bh-JSvU4.mjs";
2
2
  import { s as index_d_exports$2 } from "./index-NOtBwGrV.mjs";
3
3
  import { Actor } from "@codeworksh/schema/actor";
4
+ import * as Connector from "@codeworksh/plugin/connector";
5
+ import { BrokerInterface } from "@codeworksh/plugin/connector";
4
6
  import { Config as Config$1, Daemon, Events, Plugin, PluginOptions, PluginRef, PluginRegistry, PromptResolver, SharedPluginContext } from "@codeworksh/plugin/plugin";
5
7
  import { Cause, Config, Context, DateTime, Duration, Effect, JsonSchema, Layer, Option, PubSub, Ref, Schema, Scope, Stream } from "effect";
6
8
  import { Delivery, InterruptReason, PromptConflictError, RelinkError, RelinkReason, SessionLinkedSpaceNotFoundError, SessionNotFoundError } from "@codeworksh/schema/session";
@@ -31532,6 +31534,8 @@ declare const layer$7: (options: {
31532
31534
  readonly home: string;
31533
31535
  /** Where provider logins are read for `auth.provider`; see {@link ModelCatalog.Credentials}. */
31534
31536
  readonly authFile?: string | undefined;
31537
+ /** Optional host connector broker for `auth.connection` and broker-backed provider tokens. */
31538
+ readonly broker?: BrokerInterface | undefined;
31535
31539
  /** How long an instance no drain holds stays open. Default: 10 minutes. */
31536
31540
  readonly idleTimeout?: Duration.Input | undefined;
31537
31541
  }) => Layer.Layer<Service$8, never, ChildProcessSpawner.ChildProcessSpawner | Service$20>;
@@ -31667,6 +31671,7 @@ declare const models: Effect.Effect<Partial<Record<string, Record<string, {
31667
31671
  declare const providers: Effect.Effect<string[], ModelCatalogError, never>;
31668
31672
  declare const Credentials_base: Context.ServiceClass<Credentials, "@codeworksh/harness/model/catalog/Credentials", {
31669
31673
  readonly authFile: string | undefined;
31674
+ readonly broker?: BrokerInterface | undefined;
31670
31675
  }>;
31671
31676
  /**
31672
31677
  * Where this process reads OAuth logins: `<home>/aikit/auth.json` when a home was chosen,
@@ -31692,7 +31697,7 @@ declare const oauthCredentials: (protocol: string, authFile: string | undefined)
31692
31697
  * The credential a model call to `provider` sends: its OAuth login token, else its API key from
31693
31698
  * the environment. Undefined when it has neither, or the catalog does not know the provider.
31694
31699
  */
31695
- declare const providerToken: (provider: string, authFile: string | undefined) => Effect.Effect<string | undefined, ModelCatalogError, never>;
31700
+ declare const providerToken: (provider: string, authFile: string | undefined, broker?: BrokerInterface | undefined) => Effect.Effect<string | undefined, ModelCatalogError, never>;
31696
31701
  /**
31697
31702
  * A settings entry as the catalog reads it. Settings entries are read exactly like generated ones;
31698
31703
  * the one difference is `provider.key`, written `"${NAME}"`, which becomes the variable name aikit
@@ -32449,12 +32454,25 @@ declare const systemMessage: <T>(messageId: string, created: number, changes: {
32449
32454
  };
32450
32455
  /** A message's parts; a system message has none. */
32451
32456
  declare const parts: (message: Message.Message) => ({
32457
+ type: "text";
32458
+ text: string;
32459
+ textSignature?: string;
32460
+ } | {
32461
+ type: "image";
32462
+ data: string;
32463
+ mimeType: string;
32464
+ } | {
32465
+ type: "thinking";
32466
+ thinking: string;
32467
+ thinkingSignature?: string;
32468
+ redacted?: boolean;
32469
+ } | {
32452
32470
  arguments: Record<string, any>;
32453
32471
  callID: string;
32454
32472
  name: string;
32455
32473
  namespace?: string;
32456
- result: {
32457
- content: ({
32474
+ partial?: {
32475
+ content?: ({
32458
32476
  type: "text";
32459
32477
  text: string;
32460
32478
  textSignature?: string;
@@ -32464,9 +32482,8 @@ declare const parts: (message: Message.Message) => ({
32464
32482
  mimeType: string;
32465
32483
  })[];
32466
32484
  details?: any;
32467
- isError: false;
32468
32485
  };
32469
- status: "completed";
32486
+ status: "running";
32470
32487
  thoughtSignature?: string;
32471
32488
  time: {
32472
32489
  start: number;
@@ -32489,9 +32506,9 @@ declare const parts: (message: Message.Message) => ({
32489
32506
  mimeType: string;
32490
32507
  })[];
32491
32508
  details?: any;
32492
- isError: true;
32509
+ isError: false;
32493
32510
  };
32494
- status: "error";
32511
+ status: "completed";
32495
32512
  thoughtSignature?: string;
32496
32513
  time: {
32497
32514
  start: number;
@@ -32516,7 +32533,7 @@ declare const parts: (message: Message.Message) => ({
32516
32533
  details?: any;
32517
32534
  isError: true;
32518
32535
  };
32519
- status: "skipped";
32536
+ status: "error";
32520
32537
  thoughtSignature?: string;
32521
32538
  time: {
32522
32539
  start: number;
@@ -32541,33 +32558,20 @@ declare const parts: (message: Message.Message) => ({
32541
32558
  details?: any;
32542
32559
  isError: true;
32543
32560
  };
32544
- status: "aborted";
32561
+ status: "skipped";
32545
32562
  thoughtSignature?: string;
32546
32563
  time: {
32547
32564
  start: number;
32548
32565
  end: number;
32549
32566
  };
32550
32567
  type: "toolCall";
32551
- } | {
32552
- type: "text";
32553
- text: string;
32554
- textSignature?: string;
32555
- } | {
32556
- type: "image";
32557
- data: string;
32558
- mimeType: string;
32559
- } | {
32560
- type: "thinking";
32561
- thinking: string;
32562
- thinkingSignature?: string;
32563
- redacted?: boolean;
32564
32568
  } | {
32565
32569
  arguments: Record<string, any>;
32566
32570
  callID: string;
32567
32571
  name: string;
32568
32572
  namespace?: string;
32569
- partial?: {
32570
- content?: ({
32573
+ result: {
32574
+ content: ({
32571
32575
  type: "text";
32572
32576
  text: string;
32573
32577
  textSignature?: string;
@@ -32577,8 +32581,9 @@ declare const parts: (message: Message.Message) => ({
32577
32581
  mimeType: string;
32578
32582
  })[];
32579
32583
  details?: any;
32584
+ isError: true;
32580
32585
  };
32581
- status: "running";
32586
+ status: "aborted";
32582
32587
  thoughtSignature?: string;
32583
32588
  time: {
32584
32589
  start: number;
@@ -32601,6 +32606,48 @@ declare const parts: (message: Message.Message) => ({
32601
32606
  }))[];
32602
32607
  /** The aikit message a `user`, `assistant` or `system` entry stores. */
32603
32608
  declare const decodeMessage: (hydrated: HydratedEntry) => Effect.Effect<{
32609
+ messageId: string;
32610
+ role: "system";
32611
+ time: {
32612
+ created: number;
32613
+ };
32614
+ content?: string;
32615
+ sections?: Record<string, string | null>;
32616
+ toolsAdded?: {
32617
+ name: string;
32618
+ description: string;
32619
+ parameters: import("@codeworksh/aikit").TSchema;
32620
+ constrainedSampling?: false | {
32621
+ type: "json_schema";
32622
+ strict: "prefer" | "require";
32623
+ } | {
32624
+ type: "grammar";
32625
+ variants: {
32626
+ openai_lark?: string;
32627
+ openai_regex?: string;
32628
+ };
32629
+ };
32630
+ }[];
32631
+ toolsRemoved?: {
32632
+ name: string;
32633
+ }[];
32634
+ metadata?: Record<string, unknown>;
32635
+ } | {
32636
+ messageId: string;
32637
+ role: "user";
32638
+ time: {
32639
+ created: number;
32640
+ };
32641
+ parts: ({
32642
+ type: "text";
32643
+ text: string;
32644
+ textSignature?: string;
32645
+ } | {
32646
+ type: "image";
32647
+ data: string;
32648
+ mimeType: string;
32649
+ })[];
32650
+ } | {
32604
32651
  role: "assistant";
32605
32652
  protocol: "anthropic" | "github-copilot" | "google" | "google-vertex" | "google-vertex-anthropic" | "openai" | "openai-codex" | "openai-compatible" | "openrouter" | "xai";
32606
32653
  provider: {
@@ -32754,12 +32801,25 @@ declare const decodeMessage: (hydrated: HydratedEntry) => Effect.Effect<{
32754
32801
  completed: number;
32755
32802
  };
32756
32803
  parts: ({
32804
+ type: "text";
32805
+ text: string;
32806
+ textSignature?: string;
32807
+ } | {
32808
+ type: "image";
32809
+ data: string;
32810
+ mimeType: string;
32811
+ } | {
32812
+ type: "thinking";
32813
+ thinking: string;
32814
+ thinkingSignature?: string;
32815
+ redacted?: boolean;
32816
+ } | {
32757
32817
  arguments: Record<string, any>;
32758
32818
  callID: string;
32759
32819
  name: string;
32760
32820
  namespace?: string;
32761
- result: {
32762
- content: ({
32821
+ partial?: {
32822
+ content?: ({
32763
32823
  type: "text";
32764
32824
  text: string;
32765
32825
  textSignature?: string;
@@ -32769,9 +32829,8 @@ declare const decodeMessage: (hydrated: HydratedEntry) => Effect.Effect<{
32769
32829
  mimeType: string;
32770
32830
  })[];
32771
32831
  details?: any;
32772
- isError: false;
32773
32832
  };
32774
- status: "completed";
32833
+ status: "running";
32775
32834
  thoughtSignature?: string;
32776
32835
  time: {
32777
32836
  start: number;
@@ -32794,9 +32853,9 @@ declare const decodeMessage: (hydrated: HydratedEntry) => Effect.Effect<{
32794
32853
  mimeType: string;
32795
32854
  })[];
32796
32855
  details?: any;
32797
- isError: true;
32856
+ isError: false;
32798
32857
  };
32799
- status: "error";
32858
+ status: "completed";
32800
32859
  thoughtSignature?: string;
32801
32860
  time: {
32802
32861
  start: number;
@@ -32821,7 +32880,7 @@ declare const decodeMessage: (hydrated: HydratedEntry) => Effect.Effect<{
32821
32880
  details?: any;
32822
32881
  isError: true;
32823
32882
  };
32824
- status: "skipped";
32883
+ status: "error";
32825
32884
  thoughtSignature?: string;
32826
32885
  time: {
32827
32886
  start: number;
@@ -32846,33 +32905,20 @@ declare const decodeMessage: (hydrated: HydratedEntry) => Effect.Effect<{
32846
32905
  details?: any;
32847
32906
  isError: true;
32848
32907
  };
32849
- status: "aborted";
32908
+ status: "skipped";
32850
32909
  thoughtSignature?: string;
32851
32910
  time: {
32852
32911
  start: number;
32853
32912
  end: number;
32854
32913
  };
32855
32914
  type: "toolCall";
32856
- } | {
32857
- type: "text";
32858
- text: string;
32859
- textSignature?: string;
32860
- } | {
32861
- type: "image";
32862
- data: string;
32863
- mimeType: string;
32864
- } | {
32865
- type: "thinking";
32866
- thinking: string;
32867
- thinkingSignature?: string;
32868
- redacted?: boolean;
32869
32915
  } | {
32870
32916
  arguments: Record<string, any>;
32871
32917
  callID: string;
32872
32918
  name: string;
32873
32919
  namespace?: string;
32874
- partial?: {
32875
- content?: ({
32920
+ result: {
32921
+ content: ({
32876
32922
  type: "text";
32877
32923
  text: string;
32878
32924
  textSignature?: string;
@@ -32882,8 +32928,9 @@ declare const decodeMessage: (hydrated: HydratedEntry) => Effect.Effect<{
32882
32928
  mimeType: string;
32883
32929
  })[];
32884
32930
  details?: any;
32931
+ isError: true;
32885
32932
  };
32886
- status: "running";
32933
+ status: "aborted";
32887
32934
  thoughtSignature?: string;
32888
32935
  time: {
32889
32936
  start: number;
@@ -32907,48 +32954,6 @@ declare const decodeMessage: (hydrated: HydratedEntry) => Effect.Effect<{
32907
32954
  responseId?: string;
32908
32955
  responseModel?: string;
32909
32956
  messageId: string;
32910
- } | {
32911
- messageId: string;
32912
- role: "system";
32913
- time: {
32914
- created: number;
32915
- };
32916
- content?: string;
32917
- sections?: Record<string, string | null>;
32918
- toolsAdded?: {
32919
- name: string;
32920
- description: string;
32921
- parameters: import("@codeworksh/aikit").TSchema;
32922
- constrainedSampling?: false | {
32923
- type: "json_schema";
32924
- strict: "prefer" | "require";
32925
- } | {
32926
- type: "grammar";
32927
- variants: {
32928
- openai_lark?: string;
32929
- openai_regex?: string;
32930
- };
32931
- };
32932
- }[];
32933
- toolsRemoved?: {
32934
- name: string;
32935
- }[];
32936
- metadata?: Record<string, unknown>;
32937
- } | {
32938
- messageId: string;
32939
- role: "user";
32940
- time: {
32941
- created: number;
32942
- };
32943
- parts: ({
32944
- type: "text";
32945
- text: string;
32946
- textSignature?: string;
32947
- } | {
32948
- type: "image";
32949
- data: string;
32950
- mimeType: string;
32951
- })[];
32952
32957
  }, ContextDecodeError, never>;
32953
32958
  declare namespace context_d_exports {
32954
32959
  export { ContextDecodeError, ContextEncodeError, ContextMessage, ContextReadError, EncodedMessage, Interface$2 as Interface, Service$2 as Service, Snapshot, assembleLine, decodeMessage, decodeSyntheticMessage, encodeMessage, encodePart, layer$2 as layer, parts, systemMessage };
@@ -33584,6 +33589,8 @@ interface OpenOptions {
33584
33589
  * environment variable. Omitted, aikit resolves its own default location.
33585
33590
  */
33586
33591
  readonly authFile?: string;
33592
+ /** Optional host connector broker; when present, resolves workspace/actor provider credentials first. */
33593
+ readonly broker?: BrokerInterface;
33587
33594
  }
33588
33595
  type Request = (input: RequestInput) => Effect.Effect<Terminal, ModelCatalogError | ModelNotFoundError | ProviderError | LLMStreamError>;
33589
33596
  declare const runtimeOptions: (input: Input, model: Model$1.Info, signal: AbortSignal) => {
@@ -33699,6 +33706,8 @@ interface Options$1 {
33699
33706
  readonly mcpIdleTimeout?: Duration.Input;
33700
33707
  /** Space daemon timings: the handover after a space's last drain, and the idle stop. */
33701
33708
  readonly daemons?: Pick<Options$3, "handover" | "idleTimeout">;
33709
+ /** Optional host connector broker for workspace/actor provider and MCP credential resolution. */
33710
+ readonly broker?: BrokerInterface;
33702
33711
  }
33703
33712
  declare const layer: (options?: Options$1) => Layer.Layer<Controller | Credentials | Registry | Service$23 | Service$20 | Service$11 | Service$22 | Service$10 | Service$21 | Service$19 | Service$18 | Service$9 | Service$7 | Service$6 | Service$8 | Service$4 | Service$1 | Service$3 | Service$2 | SqlClient$1.SqlClient | import("@effect/sql-sqlite-node/SqliteClient").SqliteClient, import("effect/Config").ConfigError | EventRegistrationError | InstallError | LoadError | OutdatedError | import("@codeworksh/schema/sandbox/errors").SandboxDriverLoadError | import("@codeworksh/schema/sandbox/errors").SandboxDriverRegistrationError | SettingsError | SourceError | StoreError, never>;
33704
33713
  declare namespace sandbox_d_exports {
@@ -35078,8 +35087,8 @@ declare const update: <A>(target: Fetchable, cache: string, options: {
35078
35087
  readonly probe: Probe;
35079
35088
  readonly from: string;
35080
35089
  }) => Effect.Effect<{
35081
- readonly _tag: "not-installed";
35082
35090
  readonly entry?: never;
35091
+ readonly _tag: "not-installed";
35083
35092
  } | {
35084
35093
  readonly _tag: "unchanged";
35085
35094
  readonly entry: Entry;
@@ -35118,5 +35127,5 @@ type DateTimeUtcFromMillis = import__codeworksh_plugin_schema.DateTimeUtcFromMil
35118
35127
  type EventSchema = import__codeworksh_plugin_event.EventSchema;
35119
35128
  type SandboxError = import__codeworksh_schema_sandbox_errors.SandboxError;
35120
35129
  type optional = import__codeworksh_plugin_schema.optional;
35121
- export { Actor, control_d_exports as Control, host_d_exports as DaemonHost, db_d_exports as Database, DateTimeUtcFromMillis, schema_d_exports as DocumentSchema, event_d_exports as Event, list_d_exports as EventList, registry_d_exports as EventRegistry, EventSchema, git_d_exports as Git, git_d_exports$1 as GitDaemon, global_d_exports as Global, harness_d_exports as Harness, location_d_exports as Location, mcp_d_exports as Mcp, config_d_exports as McpConfig, error_d_exports as McpError, oauth_d_exports as McpOAuth, catalog_d_exports as ModelCatalog, index_d_exports as Plugin, project_d_exports as Project, schema_d_exports$1 as PromptSchema, run_d_exports as Runner, sandbox_d_exports as Sandbox, SandboxError, session_d_exports as Session, session_d_exports$1 as SessionStore, settings_d_exports as Settings, file_d_exports as SettingsFile, skills_d_exports as SkillsDaemon, state_d_exports as State, store_d_exports as Store, sync_d_exports as Sync, schema_d_exports$2 as ThreadSchema, thread_d_exports as ThreadStore, tool_d_exports as Tool, usage_d_exports as Usage, schema_d_exports$3 as UsageSchema, optional };
35130
+ export { Actor, Connector, control_d_exports as Control, host_d_exports as DaemonHost, db_d_exports as Database, DateTimeUtcFromMillis, schema_d_exports as DocumentSchema, event_d_exports as Event, list_d_exports as EventList, registry_d_exports as EventRegistry, EventSchema, git_d_exports as Git, git_d_exports$1 as GitDaemon, global_d_exports as Global, harness_d_exports as Harness, location_d_exports as Location, mcp_d_exports as Mcp, config_d_exports as McpConfig, error_d_exports as McpError, oauth_d_exports as McpOAuth, catalog_d_exports as ModelCatalog, index_d_exports as Plugin, project_d_exports as Project, schema_d_exports$1 as PromptSchema, run_d_exports as Runner, sandbox_d_exports as Sandbox, SandboxError, session_d_exports as Session, session_d_exports$1 as SessionStore, settings_d_exports as Settings, file_d_exports as SettingsFile, skills_d_exports as SkillsDaemon, state_d_exports as State, store_d_exports as Store, sync_d_exports as Sync, schema_d_exports$2 as ThreadSchema, thread_d_exports as ThreadStore, tool_d_exports as Tool, usage_d_exports as Usage, schema_d_exports$3 as UsageSchema, optional };
35122
35131
  //# sourceMappingURL=effect.d.mts.map
package/effect.mjs CHANGED
@@ -5,9 +5,11 @@ import "./daytona-20WBBhAP.mjs";
5
5
  import "./vercel-CBQ-y-SG.mjs";
6
6
  import { createRequire } from "node:module";
7
7
  import { Actor, Actor as Actor$1 } from "@codeworksh/schema/actor";
8
+ import * as Connector from "@codeworksh/plugin/connector";
9
+ import { Broker } from "@codeworksh/plugin/connector";
8
10
  import { Daemon } from "@codeworksh/plugin/plugin";
9
11
  import { quote } from "@codeworksh/plugin/sandbox/shell";
10
- import { Cause, Clock, Config, Context, Crypto, Data, DateTime, Deferred, Duration, Effect, Exit, Fiber, FiberSet, FileSystem, Layer, LayerMap, Metric, Option, Path, Predicate, PubSub, Queue, Random, RcMap, Ref, References, Result, Schedule, Schema, SchemaIssue, Scope, Semaphore, Stream, String as String$1 } from "effect";
12
+ import { Cause, Clock, Config, Context, Crypto, Data, DateTime, Deferred, Duration, Effect, Exit, Fiber, FiberSet, FileSystem, Layer, LayerMap, Metric, Option, Path, Predicate, PubSub, Queue, Random, RcMap, Redacted, Ref, References, Result, Schedule, Schema, SchemaIssue, Scope, Semaphore, Stream, String as String$1 } from "effect";
11
13
  import { Delivery, Failure as Error$1, InterruptReason, PromptConflictError, RelinkError, SessionLinkedSpaceNotFoundError, SessionNotFoundError } from "@codeworksh/schema/session";
12
14
  import { MessageID as ID$3, SessionID as ID$2, ThreadID as ID } from "@codeworksh/schema/ids";
13
15
  import { ModelCatalogError, ThinkingLevel } from "@codeworksh/schema/model";
@@ -6577,7 +6579,9 @@ const validate$1 = (name, raw) => {
6577
6579
  const oauth = validateOAuth(value.oauth);
6578
6580
  if (oauth !== void 0) return `server "${name}": ${oauth}`;
6579
6581
  if (value.auth !== void 0) {
6580
- if (!isRecord$3(value.auth) || !Predicate.isString(value.auth.provider) || !value.auth.provider) return `server "${name}": auth.provider must be a provider name`;
6582
+ const hasProvider = isRecord$3(value.auth) && Predicate.isString(value.auth.provider) && value.auth.provider.length > 0;
6583
+ const hasConnection = isRecord$3(value.auth) && Predicate.isString(value.auth.connection) && value.auth.connection.length > 0;
6584
+ if (!hasProvider && !hasConnection) return `server "${name}": auth must specify a non-empty "provider" or "connection"`;
6581
6585
  if (!isSecure(new URL(value.url))) return `server "${name}": auth requires an https URL, or http on localhost, 127.0.0.1 or [::1]`;
6582
6586
  }
6583
6587
  return value;
@@ -10574,7 +10578,11 @@ const oauthCredentials = async (protocol, authFile) => {
10574
10578
  * The credential a model call to `provider` sends: its OAuth login token, else its API key from
10575
10579
  * the environment. Undefined when it has neither, or the catalog does not know the provider.
10576
10580
  */
10577
- const providerToken = Effect.fn("ModelCatalog.providerToken")(function* (provider, authFile) {
10581
+ const providerToken = Effect.fn("ModelCatalog.providerToken")(function* (provider, authFile, broker) {
10582
+ if (broker !== void 0) {
10583
+ const resolved = yield* broker.resolveProvider(provider).pipe(Effect.orElseSucceed(() => void 0));
10584
+ if (resolved !== void 0) return Redacted.value(resolved.token);
10585
+ }
10578
10586
  const [model] = yield* Effect.tryPromise({
10579
10587
  try: () => Model$1.getModels(provider),
10580
10588
  catch: catalogError
@@ -10638,13 +10646,27 @@ const oauthProtocols = /* @__PURE__ */ new Set(["openai-codex", "github-copilot"
10638
10646
  * client showing a model picker should still add the session's current model.
10639
10647
  */
10640
10648
  const available$1 = Effect.fn("ModelCatalog.available")(function* (filter = {}) {
10641
- const { authFile } = yield* Credentials;
10649
+ const { authFile, broker } = yield* Credentials;
10642
10650
  const settings = yield* Service$9;
10643
10651
  const catalog = yield* effective((yield* settings.load(filter.hostDir)).models);
10652
+ const brokerStates = broker === void 0 ? /* @__PURE__ */ new Map() : new Map((yield* broker.listProviderStates().pipe(Effect.orElseSucceed(() => []))).map((s) => [s.providerId, s]));
10644
10653
  const usable = [];
10645
10654
  for (const [id, entries] of Object.entries(catalog)) {
10646
10655
  const first = entries === void 0 ? void 0 : Object.values(entries)[0];
10647
10656
  if (entries === void 0 || first === void 0) continue;
10657
+ const brokerState = brokerStates.get(id);
10658
+ if (brokerState !== void 0) {
10659
+ if (brokerState.status !== "active") continue;
10660
+ const credential = brokerState.authType === "oauth" ? "oauth" : "apiKey";
10661
+ if (filter.credential !== void 0 && filter.credential !== credential) continue;
10662
+ const models = credential === "oauth" && first.protocol === "github-copilot" && brokerState.availableModelIds !== void 0 ? filterGitHubCopilotModels(entries, { availableModelIds: [...brokerState.availableModelIds] }) : entries;
10663
+ usable.push({
10664
+ id,
10665
+ credential,
10666
+ models
10667
+ });
10668
+ continue;
10669
+ }
10648
10670
  const keyless = first.provider.key === void 0 && first.provider.env.length === 0 && !oauthProtocols.has(first.protocol);
10649
10671
  const login = getEnvApiKey(first.provider) === void 0 ? yield* storedLogin(first.protocol, authFile) : void 0;
10650
10672
  const credential = getEnvApiKey(first.provider) !== void 0 ? "apiKey" : login !== void 0 ? "oauth" : keyless ? "none" : void 0;
@@ -10748,7 +10770,7 @@ const exposureOf = (config) => config.exposure ?? "direct";
10748
10770
  /** An `Authorization` header is the user's own credential; OAuth stays out of its way. */
10749
10771
  const usesOAuth = (config) => "url" in config && config.auth === void 0 && !Object.keys(config.headers ?? {}).some((header) => header.toLowerCase() === "authorization");
10750
10772
  /** What the model reads about a server that needs sign-in: how the user signs in. */
10751
- const signInHint = (name, config) => "url" in config && config.auth !== void 0 ? `MCP server "${name}" refused the credential of provider "${config.auth.provider}". Sign in to it with "codework auth login", or set its API key.` : `MCP server "${name}" requires sign-in. Run "codework mcp login ${name}".`;
10773
+ const signInHint = (name, config) => "url" in config && config.auth !== void 0 ? "connection" in config.auth ? `MCP server "${name}" requires sign-in for connection "${config.auth.connection}". Run "codework connect login ${config.auth.connection}" or reconnect it in Connectors.` : `MCP server "${name}" refused the credential of provider "${config.auth.provider}". Sign in to it with "codework auth login", or set its API key.` : `MCP server "${name}" requires sign-in. Run "codework mcp login ${name}".`;
10752
10774
  const hasTools = (config, exposure) => exposureOf(config) === exposure || Object.values(config.toolExposure ?? {}).some((one) => one === exposure);
10753
10775
  /** Whether a loaded tool name could belong to the server; its tools are not known before it connects. */
10754
10776
  const loadsFrom = (server, loaded) => loaded.some((name) => name.startsWith(`${namespace$1(server)}__`));
@@ -10896,7 +10918,17 @@ const layer$11 = (options) => Layer.effect(Service$8, Effect.gen(function* () {
10896
10918
  /** The credential a request to the server carries, if the harness supplies one. */
10897
10919
  const credential = Effect.fnUntraced(function* (server) {
10898
10920
  const config = server.config;
10899
- if ("url" in config && config.auth !== void 0) return yield* providerToken(config.auth.provider, options.authFile).pipe(Effect.orElseSucceed(() => void 0));
10921
+ if ("url" in config && config.auth !== void 0) {
10922
+ if ("connection" in config.auth) {
10923
+ if (options.broker === void 0) return void 0;
10924
+ const host = new URL(config.url).hostname;
10925
+ return yield* options.broker.resolve({
10926
+ ref: config.auth.connection,
10927
+ targetHost: host
10928
+ }).pipe(Effect.map((resolved) => Redacted.value(resolved.token)), Effect.orElseSucceed(() => void 0));
10929
+ }
10930
+ return yield* providerToken(config.auth.provider, options.authFile, options.broker).pipe(Effect.orElseSucceed(() => void 0));
10931
+ }
10900
10932
  const target = oauthServer(server);
10901
10933
  if (target === void 0 || !usesOAuth(config)) return void 0;
10902
10934
  return yield* accessToken(oauth, target);
@@ -16014,9 +16046,26 @@ const resolve$1 = Effect.fn("LLM.resolve")(function* (input) {
16014
16046
  const openWith = (options = {}) => Effect.fn("LLM.open")(function* (input, signal) {
16015
16047
  const model = withAttribution(input.resolvedModel);
16016
16048
  const configured = runtimeOptions(input, model, signal);
16017
- const resolved = configured.apiKey === void 0 ? yield* Effect.tryPromise({
16018
- try: () => oauthCredentials(model.protocol, options.authFile),
16019
- catch: (cause) => providerErrorFromUnknown(input, cause)
16049
+ const resolved = configured.apiKey === void 0 ? yield* Effect.gen(function* () {
16050
+ if (options.broker !== void 0) {
16051
+ const fromBroker = yield* options.broker.resolveProvider(model.provider.id).pipe(Effect.mapError((error) => new ProviderError({
16052
+ provider: input.provider,
16053
+ model: input.model,
16054
+ reason: new ProviderAuthenticationError({
16055
+ authentication: error._tag === "Connector.AuthRequiredError" && error.reason === "expired" ? "expired" : "missing",
16056
+ message: error.message,
16057
+ isRetryable: false
16058
+ })
16059
+ })));
16060
+ if (fromBroker !== void 0) return {
16061
+ apiKey: Redacted.value(fromBroker.token),
16062
+ ...fromBroker.baseUrl === void 0 ? {} : { baseURL: fromBroker.baseUrl }
16063
+ };
16064
+ }
16065
+ return yield* Effect.tryPromise({
16066
+ try: () => oauthCredentials(model.protocol, options.authFile),
16067
+ catch: (cause) => providerErrorFromUnknown(input, cause)
16068
+ });
16020
16069
  }) : {};
16021
16070
  const request = {
16022
16071
  ...configured,
@@ -16942,6 +16991,44 @@ var state_exports = /* @__PURE__ */ __exportAll({
16942
16991
  SnapshotError: () => SnapshotError,
16943
16992
  layer: () => layer$4
16944
16993
  });
16994
+ const mcpServerNameForConnection = (conn) => {
16995
+ const slash = conn.uid.indexOf("/");
16996
+ const connectorPart = slash === -1 ? conn.connectorId : conn.uid.slice(0, slash);
16997
+ const slugPart = slash === -1 ? "default" : conn.uid.slice(slash + 1);
16998
+ const shortBase = (connectorPart.split(".").pop() ?? connectorPart).replace(/[^A-Za-z0-9_-]/g, "_");
16999
+ if (slugPart === "default" || slugPart === "env") return shortBase;
17000
+ return `${shortBase}_${slugPart.replace(/[^A-Za-z0-9_-]/g, "_")}`;
17001
+ };
17002
+ const withConnectorMcpServers = (loaded, connections) => {
17003
+ if (connections.length === 0) return loaded;
17004
+ const existingNames = new Set(loaded.mcp.servers.map((s) => s.name.replace(/-/g, "_").toLowerCase()));
17005
+ const injected = [];
17006
+ for (const conn of connections) {
17007
+ const name = mcpServerNameForConnection(conn);
17008
+ if (existingNames.has(name.replace(/-/g, "_").toLowerCase())) continue;
17009
+ existingNames.add(name.replace(/-/g, "_").toLowerCase());
17010
+ injected.push({
17011
+ name,
17012
+ file: `connector:${conn.uid}`,
17013
+ config: {
17014
+ type: "http",
17015
+ url: conn.url,
17016
+ exposure: conn.exposure === "deferred" ? "deferred" : "direct",
17017
+ enabled: true,
17018
+ description: conn.name,
17019
+ auth: { connection: conn.uid }
17020
+ }
17021
+ });
17022
+ }
17023
+ if (injected.length === 0) return loaded;
17024
+ return {
17025
+ ...loaded,
17026
+ mcp: {
17027
+ ...loaded.mcp,
17028
+ servers: [...loaded.mcp.servers, ...injected]
17029
+ }
17030
+ };
17031
+ };
16945
17032
  /**
16946
17033
  * A plugin's setup failed while capturing a turn's snapshot.
16947
17034
  *
@@ -17151,13 +17238,15 @@ const layer$4 = (options, pool, references, follow, rebuild, viewOf = () => Effe
17151
17238
  ...owner
17152
17239
  });
17153
17240
  }
17241
+ const mcpConnections = credentials.broker === void 0 ? [] : yield* credentials.broker.listMcpConnections().pipe(Effect.orElseSucceed(() => []));
17242
+ const effectiveSettings = withConnectorMcpServers(loadedSettings, mcpConnections);
17154
17243
  const contributions = yield* run(chosen.selection, {
17155
17244
  sessionId,
17156
17245
  threadId,
17157
17246
  sandbox,
17158
17247
  paths: global,
17159
17248
  location,
17160
- settings: loadedSettings,
17249
+ settings: effectiveSettings,
17161
17250
  model: resolvedModel,
17162
17251
  events,
17163
17252
  config: {
@@ -18052,7 +18141,11 @@ const layer = (options = {}) => Layer.unwrap(Effect.gen(function* () {
18052
18141
  const drivers = layer$28(driver_exports.SandboxDriver.withSource(make$11().driver, "core"), driver_exports.SandboxDriver.withSource(make$9().driver, "core"), ...configured);
18053
18142
  const sandboxes = layer$26({ hostCwd }).pipe(Layer.provideMerge(drivers), Layer.provideMerge(database));
18054
18143
  const authFile$1 = authFile(options.home === void 0 ? void 0 : paths.home);
18055
- const open = options.llm ?? openWith(authFile$1 === void 0 ? {} : { authFile: authFile$1 });
18144
+ const broker = options.broker ?? Option.getOrUndefined(yield* Effect.serviceOption(Broker));
18145
+ const open = options.llm ?? openWith({
18146
+ ...authFile$1 === void 0 ? {} : { authFile: authFile$1 },
18147
+ ...broker === void 0 ? {} : { broker }
18148
+ });
18056
18149
  const loop = layer$3({ request: make$6(open) }).pipe(Layer.provide(layer$6));
18057
18150
  return layer$9.pipe(Layer.provideMerge(layer$7.pipe(Layer.provide(loop))), Layer.provideMerge(layer$4({}, pool, references, followStore, rebuild, viewOf)), Layer.provideMerge(layer$25({
18058
18151
  ...options.daemons,
@@ -18061,11 +18154,15 @@ const layer = (options = {}) => Layer.unwrap(Effect.gen(function* () {
18061
18154
  hostCwd,
18062
18155
  home: paths.home,
18063
18156
  authFile: authFile$1,
18157
+ broker,
18064
18158
  idleTimeout: options.mcpIdleTimeout
18065
18159
  }).pipe(Layer.provide(host))), Layer.provideMerge(layer$13(settingsOptions)), Layer.provideMerge(layer$5), Layer.provideMerge(sandboxes), Layer.provideMerge(layer$21), Layer.provideMerge(layer$1), Layer.provideMerge(layer$32), Layer.provideMerge(layer$8(definitions)), Layer.provideMerge(database), Layer.provideMerge(global), Layer.provideMerge(layer$12({
18066
18160
  home: paths.home,
18067
18161
  watch: options.watchModels ?? false
18068
- })), Layer.provideMerge(Layer.succeed(Credentials, { authFile: authFile$1 })));
18162
+ })), Layer.provideMerge(Layer.succeed(Credentials, {
18163
+ authFile: authFile$1,
18164
+ broker
18165
+ })));
18069
18166
  }));
18070
18167
  //#endregion
18071
18168
  //#region src/effect/sandbox.ts
@@ -18893,6 +18990,6 @@ var DateTimeUtcFromMillis = schema_exports$12.DateTimeUtcFromMillis;
18893
18990
  var EventSchema = schema_exports$9.EventSchema;
18894
18991
  var SandboxError = errors_exports.SandboxError;
18895
18992
  var optional = schema_exports$12.optional;
18896
- export { Actor, control_exports as Control, host_exports as DaemonHost, db_exports as Database, DateTimeUtcFromMillis, schema_exports as DocumentSchema, event_exports as Event, list_exports as EventList, registry_exports as EventRegistry, EventSchema, git_exports as Git, git_exports$1 as GitDaemon, global_exports as Global, harness_exports as Harness, location_exports as Location, mcp_exports as Mcp, config_exports as McpConfig, error_exports as McpError, oauth_exports as McpOAuth, catalog_exports as ModelCatalog, plugin_exports as Plugin, project_exports as Project, schema_exports$1 as PromptSchema, run_exports as Runner, sandbox_exports as Sandbox, SandboxError, session_exports as Session, session_exports$1 as SessionStore, settings_exports as Settings, file_exports as SettingsFile, skills_exports as SkillsDaemon, state_exports as State, store_exports as Store, sync_exports as Sync, schema_exports$2 as ThreadSchema, thread_exports as ThreadStore, tool_exports as Tool, usage_exports as Usage, schema_exports$3 as UsageSchema, expandTilde, optional };
18993
+ export { Actor, Connector, control_exports as Control, host_exports as DaemonHost, db_exports as Database, DateTimeUtcFromMillis, schema_exports as DocumentSchema, event_exports as Event, list_exports as EventList, registry_exports as EventRegistry, EventSchema, git_exports as Git, git_exports$1 as GitDaemon, global_exports as Global, harness_exports as Harness, location_exports as Location, mcp_exports as Mcp, config_exports as McpConfig, error_exports as McpError, oauth_exports as McpOAuth, catalog_exports as ModelCatalog, plugin_exports as Plugin, project_exports as Project, schema_exports$1 as PromptSchema, run_exports as Runner, sandbox_exports as Sandbox, SandboxError, session_exports as Session, session_exports$1 as SessionStore, settings_exports as Settings, file_exports as SettingsFile, skills_exports as SkillsDaemon, state_exports as State, store_exports as Store, sync_exports as Sync, schema_exports$2 as ThreadSchema, thread_exports as ThreadStore, tool_exports as Tool, usage_exports as Usage, schema_exports$3 as UsageSchema, expandTilde, optional };
18897
18994
 
18898
18995
  //# sourceMappingURL=effect.mjs.map