@nylorun/core 0.0.0-bootstrap → 0.1.1-beta
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/CHANGELOG.md +15 -0
- package/LICENSE +192 -0
- package/README.md +16 -0
- package/dist/compatibility.d.ts +3 -0
- package/dist/compatibility.js +3 -0
- package/dist/contracts.d.ts +246 -0
- package/dist/contracts.js +204 -0
- package/dist/define.d.ts +31 -0
- package/dist/define.js +15 -0
- package/dist/definition/assemble.d.ts +26 -0
- package/dist/definition/assemble.js +50 -0
- package/dist/definition/bind-agent.d.ts +8 -0
- package/dist/definition/bind-agent.js +61 -0
- package/dist/definition/bind-tool.d.ts +4 -0
- package/dist/definition/bind-tool.js +25 -0
- package/dist/definition/binding.d.ts +15 -0
- package/dist/definition/binding.js +9 -0
- package/dist/definition/bound.d.ts +20 -0
- package/dist/definition/bound.js +1 -0
- package/dist/definition/builder.d.ts +63 -0
- package/dist/definition/builder.js +215 -0
- package/dist/definition/declaration.d.ts +10 -0
- package/dist/definition/declaration.js +70 -0
- package/dist/definition/from.d.ts +6 -0
- package/dist/definition/from.js +135 -0
- package/dist/definition/helpers.d.ts +21 -0
- package/dist/definition/helpers.js +29 -0
- package/dist/definition/implementations.d.ts +16 -0
- package/dist/definition/implementations.js +3 -0
- package/dist/definition/manifest.d.ts +9 -0
- package/dist/definition/manifest.js +57 -0
- package/dist/definition/output-contract.d.ts +6 -0
- package/dist/definition/output-contract.js +12 -0
- package/dist/definition/schema-json.d.ts +3 -0
- package/dist/definition/schema-json.js +22 -0
- package/dist/definition/schema.d.ts +16 -0
- package/dist/definition/schema.js +281 -0
- package/dist/definition/tool-error.d.ts +9 -0
- package/dist/definition/tool-error.js +20 -0
- package/dist/errors.d.ts +17 -0
- package/dist/errors.js +22 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +1 -0
- package/dist/types/agent.d.ts +12 -0
- package/dist/types/agent.js +1 -0
- package/dist/types/dynamics.d.ts +53 -0
- package/dist/types/dynamics.js +1 -0
- package/dist/types/manifest.d.ts +34 -0
- package/dist/types/manifest.js +1 -0
- package/dist/types/middleware.d.ts +74 -0
- package/dist/types/middleware.js +1 -0
- package/dist/types/model.d.ts +184 -0
- package/dist/types/model.js +1 -0
- package/dist/types/observe.d.ts +180 -0
- package/dist/types/observe.js +1 -0
- package/dist/types/shared.d.ts +25 -0
- package/dist/types/shared.js +1 -0
- package/dist/types/tool.d.ts +187 -0
- package/dist/types/tool.js +1 -0
- package/dist/types/transcript.d.ts +65 -0
- package/dist/types/transcript.js +1 -0
- package/dist/utils/canonical.d.ts +1 -0
- package/dist/utils/canonical.js +10 -0
- package/dist/utils/hash.d.ts +3 -0
- package/dist/utils/hash.js +7 -0
- package/dist/utils/immutable.d.ts +6 -0
- package/dist/utils/immutable.js +76 -0
- package/package.json +57 -7
- package/index.js +0 -1
- package/publish.out +0 -0
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Machine-readable error raised by Harness-owned code. */
|
|
2
|
+
export type HarnessErrorCode = "execution.invalid-state" | "execution.invalid-input" | "execution.incompatible" | "execution.record-failed" | "tool.unregistered" | "tool.invalid-binding" | "agent.build-failed" | "agent.lifecycle-sealed" | "context.invalid-item" | "context.invalid-item-type" | "context.invalid-order" | "context.invalid-reason" | "context.invalid-slot" | "interaction.invalid" | "interaction.missing-resume" | "interaction.uncorrelated-resume" | "input.invalid-content" | "output.invalid" | "output.invalid-schema" | "json.invalid-data" | "json.invalid-object" | "middleware.next-after-return" | "middleware.next-called-twice" | "middleware.request-mutators-revoked" | "model.candidate-missing" | "model.adapter-invalid-options" | "model.adapter-invalid-response" | "model.invalid-candidate" | "model.invalid-directive" | "model.unsupported-content" | "model.unsupported-output-schema" | "configuration.duplicate-tool-name" | "configuration.invalid" | "configuration.invalid-instructions" | "configuration.invalid-order" | "configuration.invalid-reason" | "configuration.invalid-slot" | "configuration.invalid-tools" | "configuration.model-selection-conflict" | "response.invalid-replacement" | "tool.invalid" | "tool.invalid-arguments" | "tool.invalid-output" | "tool.invalid-name" | "tool.invalid-schema" | "tool.invalid-tool-result";
|
|
3
|
+
export type HarnessErrorDetails = Readonly<Record<string, string | number | boolean>>;
|
|
4
|
+
export interface HarnessErrorOptions {
|
|
5
|
+
readonly cause?: unknown;
|
|
6
|
+
readonly details?: HarnessErrorDetails;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The sole error shape produced by Harness itself. Message text is explanatory;
|
|
10
|
+
* callers must branch on `code`.
|
|
11
|
+
*/
|
|
12
|
+
export declare class HarnessError extends Error {
|
|
13
|
+
readonly code: HarnessErrorCode;
|
|
14
|
+
readonly details: HarnessErrorDetails;
|
|
15
|
+
constructor(code: HarnessErrorCode, message: string, options?: HarnessErrorOptions);
|
|
16
|
+
}
|
|
17
|
+
export declare function isHarnessError(error: unknown): error is HarnessError;
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const errorBrand = Symbol.for("@nylorun/core/HarnessError");
|
|
2
|
+
/**
|
|
3
|
+
* The sole error shape produced by Harness itself. Message text is explanatory;
|
|
4
|
+
* callers must branch on `code`.
|
|
5
|
+
*/
|
|
6
|
+
export class HarnessError extends Error {
|
|
7
|
+
code;
|
|
8
|
+
details;
|
|
9
|
+
constructor(code, message, options = {}) {
|
|
10
|
+
super(message, options.cause === undefined ? undefined : { cause: options.cause });
|
|
11
|
+
this.name = "HarnessError";
|
|
12
|
+
Object.defineProperty(this, errorBrand, { value: true });
|
|
13
|
+
this.code = code;
|
|
14
|
+
this.details = Object.freeze({ ...(options.details ?? {}) });
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export function isHarnessError(error) {
|
|
18
|
+
return (error instanceof HarnessError ||
|
|
19
|
+
(typeof error === "object" &&
|
|
20
|
+
error !== null &&
|
|
21
|
+
error[errorBrand] === true));
|
|
22
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./contracts.js";
|
|
2
|
+
export type * from "./types/dynamics.js";
|
|
3
|
+
export type * from "./types/middleware.js";
|
|
4
|
+
export type * from "./types/tool.js";
|
|
5
|
+
export type * from "./types/agent.js";
|
|
6
|
+
export type * from "./types/observe.js";
|
|
7
|
+
export type * from "./types/model.js";
|
|
8
|
+
export type * from "./types/shared.js";
|
|
9
|
+
export type * from "./types/manifest.js";
|
|
10
|
+
export type * from "./types/transcript.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./contracts.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AgentBinding } from "../definition/binding.js";
|
|
2
|
+
import type { AgentManifest } from "./manifest.js";
|
|
3
|
+
/** An agent definition composed with Agent(...).use(...). Optional `.build()` is a no-op facade. */
|
|
4
|
+
export interface BuiltAgent<Info = unknown, Output = string> {
|
|
5
|
+
readonly id: string;
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly manifest: AgentManifest;
|
|
8
|
+
/** Canonical SHA-256 of `manifest` — durable definition identity. */
|
|
9
|
+
readonly hash: string;
|
|
10
|
+
toJSON(): AgentManifest;
|
|
11
|
+
getBinding(): AgentBinding;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { JsonValue } from "./shared.js";
|
|
2
|
+
import type { PromptItem } from "./model.js";
|
|
3
|
+
import type { MessageInput } from "./transcript.js";
|
|
4
|
+
/** Closed-world patch applied before a model call. No `model` — Runtime owns resolution. */
|
|
5
|
+
export type Patch = {
|
|
6
|
+
/** Switch capabilities declared in the manifest. */
|
|
7
|
+
readonly capabilities?: Readonly<Record<string, boolean>>;
|
|
8
|
+
/** Switch tools by name. */
|
|
9
|
+
readonly tools?: Readonly<Record<string, boolean>>;
|
|
10
|
+
/** Extra instructions for this model call only. */
|
|
11
|
+
readonly instructions?: readonly string[];
|
|
12
|
+
/** Write session state keys (merged into durable session state). */
|
|
13
|
+
readonly state?: Readonly<Record<string, JsonValue>>;
|
|
14
|
+
/** Refuse this model call; message returned to the host. */
|
|
15
|
+
readonly block?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Capability-level shorthand: toggle only this capability.
|
|
18
|
+
* Normalized to `capabilities: { [id]: active }` at bind time.
|
|
19
|
+
*/
|
|
20
|
+
readonly active?: boolean;
|
|
21
|
+
};
|
|
22
|
+
/** Decision applied after a model response, before tools/text take effect. */
|
|
23
|
+
export type Decision = {
|
|
24
|
+
readonly text?: string;
|
|
25
|
+
readonly deny?: readonly {
|
|
26
|
+
readonly id: string;
|
|
27
|
+
readonly reason: string;
|
|
28
|
+
}[];
|
|
29
|
+
readonly approve?: readonly {
|
|
30
|
+
readonly id: string;
|
|
31
|
+
readonly prompt: string;
|
|
32
|
+
}[];
|
|
33
|
+
readonly retry?: string;
|
|
34
|
+
readonly block?: string;
|
|
35
|
+
};
|
|
36
|
+
export type BeforeModelCallFn<Info = unknown> = (args: {
|
|
37
|
+
readonly input?: MessageInput | string;
|
|
38
|
+
readonly info?: Info;
|
|
39
|
+
readonly state: Readonly<Record<string, JsonValue>>;
|
|
40
|
+
readonly messages: readonly PromptItem[];
|
|
41
|
+
readonly step: number;
|
|
42
|
+
}) => Patch | Promise<Patch>;
|
|
43
|
+
export type AfterModelCallFn<Info = unknown> = (args: {
|
|
44
|
+
readonly text?: string;
|
|
45
|
+
readonly toolCalls: readonly {
|
|
46
|
+
readonly id: string;
|
|
47
|
+
readonly name: string;
|
|
48
|
+
readonly args: JsonValue;
|
|
49
|
+
}[];
|
|
50
|
+
}, ctx: {
|
|
51
|
+
readonly info?: Info;
|
|
52
|
+
readonly state: Readonly<Record<string, JsonValue>>;
|
|
53
|
+
}) => Decision | Promise<Decision>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ModelDirective } from "./model.js";
|
|
2
|
+
import type { JsonObject } from "./shared.js";
|
|
3
|
+
/** Published manifest schema version (no top-level model — Runtime-owned). */
|
|
4
|
+
export type ManifestSchemaVersion = 2;
|
|
5
|
+
export interface ManifestTool {
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly description?: string;
|
|
8
|
+
readonly inputSchema: JsonObject;
|
|
9
|
+
readonly outputSchema?: JsonObject;
|
|
10
|
+
}
|
|
11
|
+
export interface CapabilityManifest {
|
|
12
|
+
readonly id: string;
|
|
13
|
+
readonly kind: "agent" | "capability" | "middleware";
|
|
14
|
+
/** @deprecated Prefer beforeModelCall / afterModelCall flags. */
|
|
15
|
+
readonly hasMiddleware: boolean;
|
|
16
|
+
readonly instructions?: readonly string[];
|
|
17
|
+
readonly tools?: readonly ManifestTool[];
|
|
18
|
+
/** True when an implementations entry provides beforeModelCall for this capability. */
|
|
19
|
+
readonly beforeModelCall?: boolean;
|
|
20
|
+
/** True when an implementations entry provides afterModelCall for this capability. */
|
|
21
|
+
readonly afterModelCall?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated Model resolution is Runtime-owned. Legacy local snapshots may still carry this;
|
|
24
|
+
* new manifests omit it.
|
|
25
|
+
*/
|
|
26
|
+
readonly model?: Pick<ModelDirective, "id" | "controls">;
|
|
27
|
+
}
|
|
28
|
+
export interface AgentManifest {
|
|
29
|
+
readonly schemaVersion: ManifestSchemaVersion;
|
|
30
|
+
readonly id: string;
|
|
31
|
+
readonly name: string;
|
|
32
|
+
readonly outputSchema?: JsonObject;
|
|
33
|
+
readonly capabilities: readonly CapabilityManifest[];
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { ContextMutationOptions, ModelCandidate, ModelDirective, ModelToolCall, ModelConfigurationMutationOptions } from "./model.js";
|
|
2
|
+
import type { InputEvent, TranscriptEntry } from "./transcript.js";
|
|
3
|
+
import type { ContextItem, Tripwire } from "./shared.js";
|
|
4
|
+
import type { AfterModelCallFn, BeforeModelCallFn } from "./dynamics.js";
|
|
5
|
+
import type { Interaction, ToolDefinition, ToolResult } from "./tool.js";
|
|
6
|
+
interface StepRequestBase {
|
|
7
|
+
/** Opaque identity of the execution that owns this Step. */
|
|
8
|
+
readonly executionId: string;
|
|
9
|
+
/** Opaque identity of the Turn that owns this Step. */
|
|
10
|
+
readonly turnId: string;
|
|
11
|
+
/** Opaque identity of this Model Step. */
|
|
12
|
+
readonly stepId: string;
|
|
13
|
+
readonly turnNumber: number;
|
|
14
|
+
readonly stepNumber: number;
|
|
15
|
+
readonly arrivals: readonly InputEvent[];
|
|
16
|
+
readonly toolResults: readonly ToolResult[];
|
|
17
|
+
readonly transcript: readonly TranscriptEntry[];
|
|
18
|
+
readonly context: {
|
|
19
|
+
set(slot: string, items: readonly ContextItem[], options?: ContextMutationOptions): void;
|
|
20
|
+
};
|
|
21
|
+
readonly configuration: {
|
|
22
|
+
readonly instructions: {
|
|
23
|
+
set(slot: string, items: readonly string[], options?: ModelConfigurationMutationOptions): void;
|
|
24
|
+
};
|
|
25
|
+
readonly tools: {
|
|
26
|
+
set(slot: string, tools: readonly ToolDefinition[], options?: ModelConfigurationMutationOptions): void;
|
|
27
|
+
};
|
|
28
|
+
readonly model: {
|
|
29
|
+
select(directive: ModelDirective, options?: Omit<ModelConfigurationMutationOptions, "order">): void;
|
|
30
|
+
replace(directive: ModelDirective, options?: Omit<ModelConfigurationMutationOptions, "order">): void;
|
|
31
|
+
clear(options?: Omit<ModelConfigurationMutationOptions, "order">): void;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
tripwire(error: Tripwire): StepResponse;
|
|
35
|
+
}
|
|
36
|
+
export type StepRequest<Info = unknown> = StepRequestBase & {
|
|
37
|
+
readonly info?: Info;
|
|
38
|
+
};
|
|
39
|
+
export interface StepResponse {
|
|
40
|
+
candidate(): Readonly<ModelCandidate> | undefined;
|
|
41
|
+
toolCalls(): readonly ModelToolCall[];
|
|
42
|
+
replace(candidate: ModelCandidate): void;
|
|
43
|
+
deny(callId: string, reason: string): void;
|
|
44
|
+
requireInteraction(callId: string, interaction: Interaction): void;
|
|
45
|
+
tripwire(error: Tripwire): StepResponse;
|
|
46
|
+
}
|
|
47
|
+
export type StepMiddleware<Info = unknown> = (request: StepRequest<Info>, next: () => Promise<StepResponse>) => Promise<StepResponse>;
|
|
48
|
+
export type CapabilityItems<Item> = readonly Item[] | Readonly<{
|
|
49
|
+
readonly slot: string;
|
|
50
|
+
readonly items: readonly Item[];
|
|
51
|
+
}>;
|
|
52
|
+
export interface CapabilityDeclaration<Info = unknown> {
|
|
53
|
+
readonly id: string;
|
|
54
|
+
readonly tools?: CapabilityItems<ToolDefinition<any, Info, any>>;
|
|
55
|
+
readonly instructions?: CapabilityItems<string>;
|
|
56
|
+
/**
|
|
57
|
+
* @deprecated Model resolution is Runtime-owned. Not projected into the harness manifest.
|
|
58
|
+
* Kept for local middleware composition through 1.0.
|
|
59
|
+
*/
|
|
60
|
+
readonly model?: ModelDirective;
|
|
61
|
+
/** @deprecated Prefer beforeModelCall / afterModelCall. Kept through 1.0. */
|
|
62
|
+
readonly middleware?: StepMiddleware<Info>;
|
|
63
|
+
readonly beforeModelCall?: BeforeModelCallFn<Info>;
|
|
64
|
+
readonly afterModelCall?: AfterModelCallFn<Info>;
|
|
65
|
+
}
|
|
66
|
+
export interface MiddlewareContributions {
|
|
67
|
+
readonly instructions?: readonly string[];
|
|
68
|
+
readonly tools?: readonly {
|
|
69
|
+
readonly name: string;
|
|
70
|
+
readonly description?: string;
|
|
71
|
+
}[];
|
|
72
|
+
readonly model?: Pick<ModelDirective, "id" | "controls">;
|
|
73
|
+
}
|
|
74
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import type { ContextItem, JsonObject, JsonValue } from "./shared.js";
|
|
2
|
+
import type { InputEvent, TranscriptEntry } from "./transcript.js";
|
|
3
|
+
import type { ToolDescriptor, ToolResult } from "./tool.js";
|
|
4
|
+
export interface ModelToolCall {
|
|
5
|
+
readonly id: string;
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly args: JsonObject;
|
|
8
|
+
}
|
|
9
|
+
export type ModelOutputBlock = {
|
|
10
|
+
readonly type: "text";
|
|
11
|
+
readonly text: string;
|
|
12
|
+
readonly providerMetadata?: JsonObject;
|
|
13
|
+
} | {
|
|
14
|
+
readonly type: "reasoning";
|
|
15
|
+
readonly text: string;
|
|
16
|
+
readonly providerMetadata?: JsonObject;
|
|
17
|
+
} | {
|
|
18
|
+
readonly type: "json";
|
|
19
|
+
readonly value: JsonValue;
|
|
20
|
+
} | {
|
|
21
|
+
readonly type: "tool-call";
|
|
22
|
+
readonly providerMetadata?: JsonObject;
|
|
23
|
+
readonly id: string;
|
|
24
|
+
readonly name: string;
|
|
25
|
+
readonly args: JsonObject;
|
|
26
|
+
readonly raw?: string;
|
|
27
|
+
};
|
|
28
|
+
export interface ModelUsage {
|
|
29
|
+
readonly inputTokens?: number;
|
|
30
|
+
readonly outputTokens?: number;
|
|
31
|
+
readonly totalTokens?: number;
|
|
32
|
+
readonly cachedTokens?: number;
|
|
33
|
+
readonly reasoningTokens?: number;
|
|
34
|
+
readonly costUsd?: number;
|
|
35
|
+
}
|
|
36
|
+
export type ModelFinishReason = "stop" | "length" | "tool-calls" | "content-filter" | "other";
|
|
37
|
+
export interface ModelEvidence {
|
|
38
|
+
readonly requestId?: string;
|
|
39
|
+
readonly resolvedModel?: string;
|
|
40
|
+
readonly warnings?: readonly string[];
|
|
41
|
+
readonly extras?: JsonObject;
|
|
42
|
+
}
|
|
43
|
+
export interface ModelCandidate {
|
|
44
|
+
readonly output: readonly ModelOutputBlock[];
|
|
45
|
+
readonly finishReason?: ModelFinishReason;
|
|
46
|
+
readonly usage?: ModelUsage;
|
|
47
|
+
readonly evidence?: ModelEvidence;
|
|
48
|
+
}
|
|
49
|
+
export interface ModelControls {
|
|
50
|
+
readonly temperature?: number;
|
|
51
|
+
readonly maxOutputTokens?: number;
|
|
52
|
+
}
|
|
53
|
+
export interface ModelDirective {
|
|
54
|
+
readonly id?: string;
|
|
55
|
+
readonly controls?: ModelControls;
|
|
56
|
+
readonly config?: JsonObject;
|
|
57
|
+
}
|
|
58
|
+
/** A middleware-owned declaration for the model-visible configuration. */
|
|
59
|
+
export interface ModelConfigurationMutationOptions {
|
|
60
|
+
readonly order?: number;
|
|
61
|
+
readonly reason?: string;
|
|
62
|
+
}
|
|
63
|
+
export interface ModelConfigurationContributor {
|
|
64
|
+
readonly middlewareId: string;
|
|
65
|
+
readonly slot: string;
|
|
66
|
+
readonly order: number;
|
|
67
|
+
readonly reason?: string;
|
|
68
|
+
}
|
|
69
|
+
export interface ModelConfigurationTool {
|
|
70
|
+
readonly name: string;
|
|
71
|
+
readonly description?: string;
|
|
72
|
+
readonly inputSchema: JsonObject;
|
|
73
|
+
readonly outputSchema?: JsonObject;
|
|
74
|
+
readonly contributor: ModelConfigurationContributor;
|
|
75
|
+
}
|
|
76
|
+
export interface ModelConfigurationInstruction {
|
|
77
|
+
readonly text: string;
|
|
78
|
+
readonly contributor: ModelConfigurationContributor;
|
|
79
|
+
}
|
|
80
|
+
export interface ModelConfigurationSnapshot {
|
|
81
|
+
readonly version: 1;
|
|
82
|
+
readonly model?: ModelDirective;
|
|
83
|
+
readonly instructions: readonly ModelConfigurationInstruction[];
|
|
84
|
+
/** Data-only descriptions of the selected tools. */
|
|
85
|
+
readonly tools: readonly ToolDescriptor[];
|
|
86
|
+
readonly toolContracts: readonly ModelConfigurationTool[];
|
|
87
|
+
readonly contributors: readonly ModelConfigurationContributor[];
|
|
88
|
+
}
|
|
89
|
+
/** A middleware-owned declaration for this model call's runtime context. */
|
|
90
|
+
export interface ContextMutationOptions {
|
|
91
|
+
readonly order?: number;
|
|
92
|
+
readonly reason?: string;
|
|
93
|
+
}
|
|
94
|
+
export interface ContextContributor {
|
|
95
|
+
readonly middlewareId: string;
|
|
96
|
+
readonly slot: string;
|
|
97
|
+
readonly order: number;
|
|
98
|
+
readonly reason?: string;
|
|
99
|
+
}
|
|
100
|
+
/** Canonical runtime context for one model call. */
|
|
101
|
+
export interface ContextSnapshot {
|
|
102
|
+
readonly items: readonly ContextItem[];
|
|
103
|
+
readonly contributors: readonly ContextContributor[];
|
|
104
|
+
}
|
|
105
|
+
export interface ModelRequest {
|
|
106
|
+
readonly executionId: string;
|
|
107
|
+
readonly turnId: string;
|
|
108
|
+
readonly stepId: string;
|
|
109
|
+
readonly model?: ModelDirective;
|
|
110
|
+
/** Canonical, immutable Harness-owned model configuration for this call. */
|
|
111
|
+
readonly configuration: ModelConfigurationSnapshot;
|
|
112
|
+
readonly instructions: readonly string[];
|
|
113
|
+
readonly context: ContextSnapshot;
|
|
114
|
+
readonly transcript: readonly TranscriptEntry[];
|
|
115
|
+
readonly arrivals: readonly InputEvent[];
|
|
116
|
+
readonly toolResults: readonly ToolResult[];
|
|
117
|
+
/** Immutable tool descriptions; executable definitions stay inside Harness. */
|
|
118
|
+
readonly tools: readonly ToolDescriptor[];
|
|
119
|
+
/** Optional portable contract for this turn's terminal JSON result. */
|
|
120
|
+
readonly outputSchema?: JsonObject;
|
|
121
|
+
}
|
|
122
|
+
export type PromptContentPart = {
|
|
123
|
+
readonly type: "reasoning";
|
|
124
|
+
readonly text: string;
|
|
125
|
+
readonly providerMetadata?: JsonObject;
|
|
126
|
+
} | {
|
|
127
|
+
readonly type: "text";
|
|
128
|
+
readonly text: string;
|
|
129
|
+
readonly providerMetadata?: JsonObject;
|
|
130
|
+
} | {
|
|
131
|
+
readonly type: "media";
|
|
132
|
+
readonly mediaType: string;
|
|
133
|
+
readonly reference: JsonValue;
|
|
134
|
+
} | {
|
|
135
|
+
readonly type: "tool-call";
|
|
136
|
+
readonly providerMetadata?: JsonObject;
|
|
137
|
+
readonly id: string;
|
|
138
|
+
readonly name: string;
|
|
139
|
+
readonly args: JsonObject;
|
|
140
|
+
};
|
|
141
|
+
export type PromptItem = {
|
|
142
|
+
readonly kind: "instructions";
|
|
143
|
+
readonly role: "system";
|
|
144
|
+
readonly content: readonly PromptContentPart[];
|
|
145
|
+
} | {
|
|
146
|
+
readonly kind: "message";
|
|
147
|
+
readonly role: "user" | "assistant";
|
|
148
|
+
readonly content: readonly PromptContentPart[];
|
|
149
|
+
} | {
|
|
150
|
+
readonly kind: "tool-result";
|
|
151
|
+
readonly toolCallId: string;
|
|
152
|
+
readonly toolName: string;
|
|
153
|
+
readonly status: "completed" | "denied" | "failed";
|
|
154
|
+
readonly content: readonly PromptContentPart[];
|
|
155
|
+
} | {
|
|
156
|
+
readonly kind: "context";
|
|
157
|
+
readonly role: "user";
|
|
158
|
+
readonly content: readonly PromptContentPart[];
|
|
159
|
+
};
|
|
160
|
+
export interface ModelCallTool {
|
|
161
|
+
readonly name: string;
|
|
162
|
+
readonly description?: string;
|
|
163
|
+
readonly inputSchema: JsonObject;
|
|
164
|
+
}
|
|
165
|
+
export interface ModelCall {
|
|
166
|
+
readonly model?: ModelDirective;
|
|
167
|
+
readonly prompt: readonly PromptItem[];
|
|
168
|
+
readonly tools: readonly ModelCallTool[];
|
|
169
|
+
/** Optional portable contract for this turn's terminal JSON result. */
|
|
170
|
+
readonly outputSchema?: JsonObject;
|
|
171
|
+
readonly executionId: string;
|
|
172
|
+
}
|
|
173
|
+
export interface ModelAdapterContext {
|
|
174
|
+
readonly request: ModelRequest;
|
|
175
|
+
readonly invocationId: string;
|
|
176
|
+
readonly signal: AbortSignal;
|
|
177
|
+
/** Publishes one JSON-safe provider request derived from the canonical ModelCall. */
|
|
178
|
+
reportPreparedCall(prepared: ModelPreparedCall): void;
|
|
179
|
+
}
|
|
180
|
+
export interface ModelPreparedCall {
|
|
181
|
+
readonly adapter: string;
|
|
182
|
+
readonly call: JsonValue;
|
|
183
|
+
}
|
|
184
|
+
export type ModelAdapter = (call: ModelCall, context: ModelAdapterContext) => Promise<ModelCandidate | string>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import type { ContextSnapshot, ModelCandidate, ModelCall, ModelConfigurationSnapshot } from "./model.js";
|
|
2
|
+
import type { JsonObject, JsonValue } from "./shared.js";
|
|
3
|
+
import type { InputEvent, TranscriptEntry } from "./transcript.js";
|
|
4
|
+
import type { RequiredInteraction, ToolDescriptor, ToolResult } from "./tool.js";
|
|
5
|
+
export type ObserveToolSnapshot = ToolDescriptor;
|
|
6
|
+
/** JSON-only model-configuration view suitable for an observation stream. */
|
|
7
|
+
export interface ObserveModelConfigurationSnapshot extends Omit<ModelConfigurationSnapshot, "tools"> {
|
|
8
|
+
readonly tools: readonly ObserveToolSnapshot[];
|
|
9
|
+
}
|
|
10
|
+
export interface ObserveSealedCall {
|
|
11
|
+
readonly callId: string;
|
|
12
|
+
readonly toolName: string;
|
|
13
|
+
readonly args: JsonValue;
|
|
14
|
+
readonly invocationId: string;
|
|
15
|
+
readonly owner: {
|
|
16
|
+
readonly middlewareId: string;
|
|
17
|
+
readonly slot: string;
|
|
18
|
+
};
|
|
19
|
+
readonly interaction?: RequiredInteraction;
|
|
20
|
+
}
|
|
21
|
+
export interface ObserveModelRequested {
|
|
22
|
+
/** The exact immutable logical input supplied to the ModelAdapter. */
|
|
23
|
+
readonly call: ModelCall;
|
|
24
|
+
/** Canonical configuration facts and attribution. */
|
|
25
|
+
readonly configuration: ObserveModelConfigurationSnapshot;
|
|
26
|
+
/** Current-step runtime context and attribution. */
|
|
27
|
+
readonly context: ContextSnapshot;
|
|
28
|
+
}
|
|
29
|
+
export type ObserveEvent = {
|
|
30
|
+
readonly type: "model.requested";
|
|
31
|
+
readonly invocationId: string;
|
|
32
|
+
readonly turnId: string;
|
|
33
|
+
readonly stepId: string;
|
|
34
|
+
readonly inputId?: string;
|
|
35
|
+
readonly requestedModelId?: string;
|
|
36
|
+
readonly attributes: ObserveModelRequested;
|
|
37
|
+
} | {
|
|
38
|
+
readonly type: "model.prepared";
|
|
39
|
+
readonly invocationId: string;
|
|
40
|
+
readonly turnId: string;
|
|
41
|
+
readonly stepId: string;
|
|
42
|
+
readonly inputId?: string;
|
|
43
|
+
readonly requestedModelId?: string;
|
|
44
|
+
readonly attributes: {
|
|
45
|
+
readonly adapter: string;
|
|
46
|
+
readonly call: JsonValue;
|
|
47
|
+
};
|
|
48
|
+
} | {
|
|
49
|
+
readonly type: "model.completed";
|
|
50
|
+
readonly invocationId?: string;
|
|
51
|
+
readonly turnId: string;
|
|
52
|
+
readonly stepId: string;
|
|
53
|
+
readonly inputId?: string;
|
|
54
|
+
readonly requestedModelId?: string;
|
|
55
|
+
readonly attributes: ModelCandidate;
|
|
56
|
+
} | {
|
|
57
|
+
readonly type: "step.started";
|
|
58
|
+
readonly turnId: string;
|
|
59
|
+
readonly stepId: string;
|
|
60
|
+
readonly inputId?: string;
|
|
61
|
+
readonly turnNumber: number;
|
|
62
|
+
readonly stepNumber: number;
|
|
63
|
+
readonly attributes: {
|
|
64
|
+
readonly arrivals: readonly InputEvent[];
|
|
65
|
+
readonly toolResults: readonly ToolResult[];
|
|
66
|
+
readonly transcript: readonly TranscriptEntry[];
|
|
67
|
+
};
|
|
68
|
+
} | {
|
|
69
|
+
readonly type: "middleware.entered" | "middleware.completed";
|
|
70
|
+
readonly turnId: string;
|
|
71
|
+
readonly stepId: string;
|
|
72
|
+
readonly inputId?: string;
|
|
73
|
+
readonly middlewareId: string;
|
|
74
|
+
} | {
|
|
75
|
+
readonly type: "middleware.lease-violation";
|
|
76
|
+
readonly turnId: string;
|
|
77
|
+
readonly stepId: string;
|
|
78
|
+
readonly inputId?: string;
|
|
79
|
+
readonly middlewareId: string;
|
|
80
|
+
readonly reason: string;
|
|
81
|
+
} | {
|
|
82
|
+
readonly type: "tool.sealed";
|
|
83
|
+
readonly turnId: string;
|
|
84
|
+
readonly stepId: string;
|
|
85
|
+
readonly inputId?: string;
|
|
86
|
+
readonly attributes: {
|
|
87
|
+
readonly executable: readonly ObserveSealedCall[];
|
|
88
|
+
readonly immediate: readonly ToolResult[];
|
|
89
|
+
};
|
|
90
|
+
} | {
|
|
91
|
+
readonly type: "tool.started";
|
|
92
|
+
readonly executionId: string;
|
|
93
|
+
readonly turnId: string;
|
|
94
|
+
readonly stepId: string;
|
|
95
|
+
readonly inputId?: string;
|
|
96
|
+
readonly toolName: string;
|
|
97
|
+
readonly callId: string;
|
|
98
|
+
readonly invocationId: string;
|
|
99
|
+
readonly middlewareId: string;
|
|
100
|
+
readonly slot: string;
|
|
101
|
+
readonly attributes: {
|
|
102
|
+
readonly args: JsonValue;
|
|
103
|
+
};
|
|
104
|
+
} | {
|
|
105
|
+
readonly type: "tool.progress";
|
|
106
|
+
readonly executionId: string;
|
|
107
|
+
readonly turnId: string;
|
|
108
|
+
readonly stepId: string;
|
|
109
|
+
readonly inputId?: string;
|
|
110
|
+
readonly toolName: string;
|
|
111
|
+
readonly callId: string;
|
|
112
|
+
readonly invocationId: string;
|
|
113
|
+
readonly middlewareId: string;
|
|
114
|
+
readonly slot: string;
|
|
115
|
+
readonly attributes: {
|
|
116
|
+
readonly message: string;
|
|
117
|
+
readonly data?: JsonObject;
|
|
118
|
+
};
|
|
119
|
+
} | {
|
|
120
|
+
readonly type: "tool.completed";
|
|
121
|
+
readonly executionId: string;
|
|
122
|
+
readonly turnId: string;
|
|
123
|
+
readonly stepId: string;
|
|
124
|
+
readonly inputId?: string;
|
|
125
|
+
readonly toolName: string;
|
|
126
|
+
readonly callId: string;
|
|
127
|
+
readonly invocationId: string;
|
|
128
|
+
readonly middlewareId: string;
|
|
129
|
+
readonly slot: string;
|
|
130
|
+
readonly outcome: string;
|
|
131
|
+
readonly code?: string;
|
|
132
|
+
readonly attributes?: ToolResult;
|
|
133
|
+
} | {
|
|
134
|
+
readonly type: "tool.deferred";
|
|
135
|
+
readonly executionId: string;
|
|
136
|
+
readonly turnId: string;
|
|
137
|
+
readonly stepId: string;
|
|
138
|
+
readonly inputId?: string;
|
|
139
|
+
readonly toolName: string;
|
|
140
|
+
readonly callId: string;
|
|
141
|
+
readonly invocationId: string;
|
|
142
|
+
readonly middlewareId: string;
|
|
143
|
+
readonly slot: string;
|
|
144
|
+
readonly attributes: {
|
|
145
|
+
readonly token?: JsonValue;
|
|
146
|
+
};
|
|
147
|
+
} | {
|
|
148
|
+
readonly type: "turn.completed";
|
|
149
|
+
readonly turnId: string;
|
|
150
|
+
readonly stepId: string;
|
|
151
|
+
readonly inputId?: string;
|
|
152
|
+
readonly attributes: {
|
|
153
|
+
readonly output: JsonValue;
|
|
154
|
+
};
|
|
155
|
+
} | {
|
|
156
|
+
readonly type: "interaction.required";
|
|
157
|
+
readonly turnId: string;
|
|
158
|
+
readonly stepId: string;
|
|
159
|
+
readonly inputId?: string;
|
|
160
|
+
readonly interactionId: string;
|
|
161
|
+
readonly kind: string;
|
|
162
|
+
readonly callId?: string;
|
|
163
|
+
readonly toolName?: string;
|
|
164
|
+
readonly phase?: "interaction" | "execute";
|
|
165
|
+
readonly attributes: {
|
|
166
|
+
readonly prompt: string;
|
|
167
|
+
readonly metadata?: JsonObject;
|
|
168
|
+
};
|
|
169
|
+
} | {
|
|
170
|
+
readonly type: "tripwire";
|
|
171
|
+
readonly turnId: string;
|
|
172
|
+
readonly stepId?: string;
|
|
173
|
+
readonly inputId?: string;
|
|
174
|
+
readonly code: string;
|
|
175
|
+
readonly scope: string;
|
|
176
|
+
readonly attributes: {
|
|
177
|
+
readonly message: string;
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
export type Observer = (event: ObserveEvent) => void | Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type JsonPrimitive = string | number | boolean | null;
|
|
2
|
+
export type JsonValue = JsonPrimitive | JsonObject | readonly JsonValue[];
|
|
3
|
+
export type JsonObject = {
|
|
4
|
+
readonly [key: string]: JsonValue;
|
|
5
|
+
};
|
|
6
|
+
export interface DeferredOutcome {
|
|
7
|
+
readonly kind: "deferred";
|
|
8
|
+
readonly token?: JsonValue;
|
|
9
|
+
}
|
|
10
|
+
export interface BuildDiagnostic {
|
|
11
|
+
readonly code: string;
|
|
12
|
+
readonly message: string;
|
|
13
|
+
readonly toolName?: string;
|
|
14
|
+
readonly details?: Readonly<Record<string, string | number | boolean>>;
|
|
15
|
+
readonly cause?: unknown;
|
|
16
|
+
}
|
|
17
|
+
export interface ContextItem {
|
|
18
|
+
readonly type?: string;
|
|
19
|
+
readonly value: JsonValue;
|
|
20
|
+
}
|
|
21
|
+
export interface Tripwire {
|
|
22
|
+
readonly code: string;
|
|
23
|
+
readonly message: string;
|
|
24
|
+
readonly scope?: "step" | "execution";
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|