@nylorun/agents 0.9.0-beta → 0.11.0-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.
Files changed (52) hide show
  1. package/CHANGELOG.md +165 -0
  2. package/README.md +296 -77
  3. package/dist/a2a/handler.d.ts +59 -0
  4. package/dist/a2a/handler.js +178 -0
  5. package/dist/a2a/index.d.ts +8 -0
  6. package/dist/a2a/index.js +7 -0
  7. package/dist/access.d.ts +101 -0
  8. package/dist/access.js +111 -0
  9. package/dist/action-handler.d.ts +63 -0
  10. package/dist/action-handler.js +279 -0
  11. package/dist/ag-ui/handler.d.ts +12 -4
  12. package/dist/ag-ui/handler.js +87 -281
  13. package/dist/ag-ui/index.d.ts +2 -1
  14. package/dist/ag-ui/index.js +2 -1
  15. package/dist/browser.d.ts +97 -0
  16. package/dist/browser.js +277 -0
  17. package/dist/client.d.ts +3 -230
  18. package/dist/client.js +3 -361
  19. package/dist/connection.d.ts +4 -4
  20. package/dist/connection.js +16 -25
  21. package/dist/delivery-token.d.ts +62 -0
  22. package/dist/delivery-token.js +159 -0
  23. package/dist/execute-action.d.ts +6 -0
  24. package/dist/execute-action.js +24 -0
  25. package/dist/http.d.ts +34 -3
  26. package/dist/http.js +68 -16
  27. package/dist/index.d.ts +10 -8
  28. package/dist/index.js +4 -4
  29. package/dist/sandbox/client.d.ts +4 -5
  30. package/dist/sandbox/client.js +4 -8
  31. package/dist/sandbox/index.d.ts +0 -2
  32. package/dist/sandbox/index.js +0 -1
  33. package/dist/served-definitions.d.ts +20 -0
  34. package/dist/served-definitions.js +100 -0
  35. package/dist/session-client.d.ts +282 -0
  36. package/dist/session-client.js +375 -0
  37. package/dist/sse.js +12 -0
  38. package/dist/studio-embed.d.ts +9 -0
  39. package/dist/studio-embed.js +8 -0
  40. package/dist/token-endpoint.d.ts +23 -0
  41. package/dist/token-endpoint.js +30 -0
  42. package/package.json +15 -8
  43. package/dist/ag-ui/history.d.ts +0 -7
  44. package/dist/ag-ui/history.js +0 -60
  45. package/dist/ag-ui/sse.d.ts +0 -9
  46. package/dist/ag-ui/sse.js +0 -7
  47. package/dist/ag-ui/translate.d.ts +0 -38
  48. package/dist/ag-ui/translate.js +0 -222
  49. package/dist/derived-credentials.d.ts +0 -5
  50. package/dist/derived-credentials.js +0 -17
  51. package/dist/executor.d.ts +0 -20
  52. package/dist/executor.js +0 -417
@@ -0,0 +1,100 @@
1
+ /** The definitions an application serves Actions for (`createActionHandler`). */
2
+ import { AgentManifestSchema } from "@nylorun/core/contracts";
3
+ import { agentFrom, delegateOf, hashManifest, isFlowDelegate, isBuiltWorkflow, } from "@nylorun/core/define";
4
+ import { assertNoMiddlewareClosures } from "./client.js";
5
+ import { env } from "./http.js";
6
+ /** The implementation version to register: the option, `NYLORUN_IMPLEMENTATION_VERSION`, or `dev`. */
7
+ export function implementationVersionOf(options) {
8
+ return (options.implementationVersion ??
9
+ env("NYLORUN_IMPLEMENTATION_VERSION") ??
10
+ "dev");
11
+ }
12
+ /** Agents embedded in a v2 workflow: served here, but saved only as part of the workflow. */
13
+ const embeddedAgents = new WeakMap();
14
+ /** The ids among `agents` that are saved only as part of another definition. */
15
+ export function embeddedIn(agents) {
16
+ return embeddedAgents.get(agents) ?? new Set();
17
+ }
18
+ /**
19
+ * Every definition `sources` serves, by id: the agents and workflows passed in, the agents
20
+ * a v2 workflow embeds, and flow agents used as tools. `owner` names the caller in errors.
21
+ */
22
+ export function buildAgents(sources, owner) {
23
+ const agents = new Map();
24
+ const embedded = new Set();
25
+ /**
26
+ * Agents embedded in another definition (a v2 flow's agents, a flow agent used as a
27
+ * tool) may be reached from more than one place; the same definition is served once.
28
+ */
29
+ const sameAsServed = (id, manifest) => {
30
+ const served = agents.get(id);
31
+ if (!served)
32
+ return false;
33
+ if (hashManifest(served.manifest) === hashManifest(manifest))
34
+ return true;
35
+ throw new Error(`Duplicate connected agent ${id}`);
36
+ };
37
+ const addAgent = (built, shared = false) => {
38
+ assertNoMiddlewareClosures(built);
39
+ AgentManifestSchema.parse(built.manifest);
40
+ if (shared ? sameAsServed(built.id, built.manifest) : agents.has(built.id)) {
41
+ if (!shared)
42
+ throw new Error(`Duplicate connected agent ${built.id}`);
43
+ return;
44
+ }
45
+ agents.set(built.id, built);
46
+ for (const tool of built.getBinding().tools) {
47
+ const delegate = delegateOf(tool);
48
+ if (!delegate || !isFlowDelegate(delegate))
49
+ continue;
50
+ // A flow agent used as a tool runs in its own linked session: serve its code too.
51
+ if (!delegate.workflow)
52
+ throw new Error(`Flow agent '${delegate.manifest.id}' is used as a tool by '${built.id}' but has no local implementation`);
53
+ addWorkflow(delegate.workflow, true);
54
+ embedded.add(delegate.workflow.id);
55
+ }
56
+ };
57
+ const addWorkflow = (workflow, shared = false) => {
58
+ if (shared ? sameAsServed(workflow.id, workflow.manifest) : agents.has(workflow.id)) {
59
+ if (!shared)
60
+ throw new Error(`Duplicate connected agent ${workflow.id}`);
61
+ return;
62
+ }
63
+ agents.set(workflow.id, workflow);
64
+ const v2 = workflow.manifest.workflowSchemaVersion === 2;
65
+ for (const binding of Object.values(workflow.getBinding().agents)) {
66
+ addAgent(agentFrom(binding.manifest, binding.implementations), v2);
67
+ if (v2)
68
+ embedded.add(binding.manifest.id);
69
+ }
70
+ };
71
+ for (const source of sources) {
72
+ if (isBuiltWorkflow(source)) {
73
+ addWorkflow(source);
74
+ continue;
75
+ }
76
+ const built = source.build?.() ?? source;
77
+ if (isBuiltWorkflow(built)) {
78
+ addWorkflow(built);
79
+ continue;
80
+ }
81
+ addAgent(built);
82
+ }
83
+ if (!agents.size)
84
+ throw new Error(`${owner} requires at least one agent`);
85
+ // A definition passed in directly is saved on its own, even if another one embeds it.
86
+ for (const source of sources)
87
+ embedded.delete(source.id);
88
+ embeddedAgents.set(agents, embedded);
89
+ return agents;
90
+ }
91
+ /**
92
+ * The manifest hash served for a workflow's flow actions. A run is pinned to one workflow
93
+ * manifest, and its stage keys may shift between deploys, so flow actions for another hash
94
+ * are left for whoever serves it.
95
+ */
96
+ export function flowManifestHash(agent) {
97
+ return isBuiltWorkflow(agent) && agent.manifest.workflowSchemaVersion === 2
98
+ ? hashManifest(agent.manifest)
99
+ : undefined;
100
+ }
@@ -0,0 +1,282 @@
1
+ /**
2
+ * The Tenant API client classes, with no Node-only imports so a browser bundle can load them
3
+ * (`@nylorun/agents/browser`). `client.ts` adds `createClient`, which resolves the
4
+ * connection from the environment or the Project link.
5
+ */
6
+ import type { AgentManifest, BuiltAgent, BuiltWorkflow, JsonValue, SandboxToolName, WorkflowManifest } from "@nylorun/core/define";
7
+ import { type SubjectScope, type CredentialInfo, type CredentialSelection, type SandboxRequest, type SessionCommand, type VaultInfo } from "@nylorun/core/contracts";
8
+ import { AccessClient, TokensClient } from "./access.js";
9
+ import { Transport, type Destination } from "./http.js";
10
+ /** Application-principal access to a session's sandbox built-ins (workflows.md §8). */
11
+ export type SessionSandbox = {
12
+ readonly [K in SandboxToolName]: (args: Record<string, unknown>) => Promise<unknown>;
13
+ };
14
+ export interface AgentSource {
15
+ readonly id: string;
16
+ readonly manifest: AgentManifest | WorkflowManifest;
17
+ build?(): BuiltAgent | BuiltWorkflow;
18
+ getBinding?: BuiltAgent["getBinding"] | BuiltWorkflow["getBinding"];
19
+ }
20
+ /** Closures stay on the live binding. The published manifest cannot name them. */
21
+ export declare function assertNoMiddlewareClosures(agent: AgentSource): void;
22
+ export interface SessionView {
23
+ id: string;
24
+ agentId: string;
25
+ ownerUserId: string;
26
+ status: string;
27
+ activeTurnId: string | null;
28
+ waits?: unknown;
29
+ [key: string]: unknown;
30
+ }
31
+ export interface ActAsOptions {
32
+ /** What the subject may do; the Runtime grants nothing else. Default `["sessions:own"]`. */
33
+ scopes?: readonly SubjectScope[];
34
+ }
35
+ export declare class AgentsClient {
36
+ readonly transport: Transport;
37
+ /** The subject this client acts for (`as`), or `undefined` for the principal itself. */
38
+ readonly subject: string | undefined;
39
+ constructor(destination?: Destination);
40
+ /**
41
+ * A client that acts for `subject`: every call sends `Nylorun-Subject` and
42
+ * `Nylorun-Scopes`, and the Runtime limits it to the scopes and to the subject's own sessions
43
+ * and vaults (Host feature `subject-headers`). For app servers, which authenticate the person
44
+ * themselves and hold the key; nothing is minted, cached or refreshed.
45
+ */
46
+ as(subject: string, options?: ActAsOptions): AgentsClient;
47
+ /**
48
+ * Mints subject tokens for signed-in people (Host feature `subject-tokens`), so their
49
+ * browser or app calls the Runtime directly. Application key only.
50
+ */
51
+ get tokens(): TokensClient;
52
+ /** The access policy, signing keys and revocations (Host feature `subject-tokens`). */
53
+ get access(): AccessClient;
54
+ /** The Runtime's protocol features, including optional ones such as `transcript-events`. */
55
+ hostFeatures(options?: {
56
+ signal?: AbortSignal;
57
+ }): Promise<readonly string[]>;
58
+ listAgents(options?: {
59
+ signal?: AbortSignal;
60
+ }): Promise<{
61
+ agents: {
62
+ manifest: AgentManifest;
63
+ }[];
64
+ }>;
65
+ listSessions(options?: {
66
+ agentId?: string;
67
+ signal?: AbortSignal;
68
+ }): Promise<{
69
+ sessions: SessionView[];
70
+ }>;
71
+ saveAgent(agent: AgentSource | BuiltWorkflow, options: {
72
+ implementationVersion: string;
73
+ requestId?: string;
74
+ }): Promise<unknown>;
75
+ createSession(options: {
76
+ id?: string;
77
+ agentId: string;
78
+ ownerUserId: string;
79
+ info?: Record<string, unknown>;
80
+ requestId?: string;
81
+ vaultIds?: readonly string[];
82
+ credentialSelections?: readonly CredentialSelection[];
83
+ /**
84
+ * The session's sandbox: omit for the Tenant default, `false` for none, `{ session }` to share
85
+ * another session's, or an inline sandbox (`image`, `network.allow`, `resources`) checked
86
+ * against the Tenant's limits. Fixed once the session exists.
87
+ */
88
+ sandbox?: SandboxRequest;
89
+ }): Promise<SessionClient>;
90
+ createVault(options: {
91
+ name: string;
92
+ ownerUserId: string;
93
+ metadata?: Record<string, string>;
94
+ idempotencyKey: string;
95
+ requestId?: string;
96
+ }): Promise<VaultInfo>;
97
+ listVaults(ownerUserId: string, signal?: AbortSignal): Promise<{
98
+ vaults: VaultInfo[];
99
+ }>;
100
+ getVault(vaultId: string, signal?: AbortSignal): Promise<VaultInfo>;
101
+ deleteVault(vaultId: string): Promise<{
102
+ id: string;
103
+ }>;
104
+ createCredential(vaultId: string, options: {
105
+ name: string;
106
+ idempotencyKey: string;
107
+ requestId?: string;
108
+ auth: {
109
+ type: "bearer";
110
+ url: string;
111
+ token: string;
112
+ } | {
113
+ type: "oauth";
114
+ url: string;
115
+ accessToken: string;
116
+ expiresAt?: string | null;
117
+ refresh?: {
118
+ tokenEndpoint: string;
119
+ clientId: string;
120
+ refreshToken: string;
121
+ tokenEndpointAuth: {
122
+ type: "none";
123
+ } | {
124
+ type: "client_secret_basic";
125
+ clientSecret: string;
126
+ } | {
127
+ type: "client_secret_post";
128
+ clientSecret: string;
129
+ };
130
+ };
131
+ };
132
+ }): Promise<CredentialInfo>;
133
+ listCredentials(vaultId: string, signal?: AbortSignal): Promise<{
134
+ credentials: CredentialInfo[];
135
+ }>;
136
+ getCredential(vaultId: string, credentialId: string, signal?: AbortSignal): Promise<CredentialInfo>;
137
+ rotateCredential(vaultId: string, credentialId: string, options: {
138
+ idempotencyKey: string;
139
+ requestId?: string;
140
+ auth: {
141
+ type: "bearer";
142
+ token: string;
143
+ } | {
144
+ type: "oauth";
145
+ accessToken: string;
146
+ expiresAt?: string | null;
147
+ };
148
+ }): Promise<CredentialInfo>;
149
+ deleteCredential(vaultId: string, credentialId: string): Promise<{
150
+ id: string;
151
+ }>;
152
+ session(sessionId: string): SessionClient;
153
+ }
154
+ export type CommandOptions = {
155
+ idempotencyKey: string;
156
+ requestId?: string;
157
+ signal?: AbortSignal;
158
+ };
159
+ export declare class SessionClient {
160
+ private readonly transport;
161
+ readonly id: string;
162
+ readonly sandbox: SessionSandbox;
163
+ constructor(transport: Transport, id: string);
164
+ private get path();
165
+ inspect(signal?: AbortSignal): Promise<SessionView>;
166
+ /** Pending waits / interactions from the session inspect view. */
167
+ pending(signal?: AbortSignal): Promise<{}>;
168
+ command(command: SessionCommand, signal?: AbortSignal): Promise<{
169
+ status: "accepted";
170
+ turnId: string | null;
171
+ cursor: string | null;
172
+ requestId: string;
173
+ }>;
174
+ /**
175
+ * Start a turn. Strings become `message.content`; any other JSON value becomes
176
+ * `message.data` (workflows.md §5).
177
+ */
178
+ input(value: string | JsonValue, options: CommandOptions): Promise<{
179
+ status: "accepted";
180
+ turnId: string | null;
181
+ cursor: string | null;
182
+ requestId: string;
183
+ }>;
184
+ approve(interactionId: string, approved: boolean, options: CommandOptions): Promise<{
185
+ status: "accepted";
186
+ turnId: string | null;
187
+ cursor: string | null;
188
+ requestId: string;
189
+ }>;
190
+ respond(interactionId: string, value: JsonValue, options: CommandOptions): Promise<{
191
+ status: "accepted";
192
+ turnId: string | null;
193
+ cursor: string | null;
194
+ requestId: string;
195
+ }>;
196
+ cancel(options: CommandOptions & {
197
+ reason?: string;
198
+ }): Promise<{
199
+ status: "accepted";
200
+ turnId: string | null;
201
+ cursor: string | null;
202
+ requestId: string;
203
+ }>;
204
+ /** `agent` narrows to one agent used as a tool: its delegationId or its path. */
205
+ history(options?: {
206
+ cursor?: string;
207
+ agent?: string;
208
+ signal?: AbortSignal;
209
+ }): Promise<{
210
+ items: ({
211
+ schema: "nylorun.event/2";
212
+ eventId: string;
213
+ tenantId: string;
214
+ sessionId: string;
215
+ runId: string | null;
216
+ turnId: string | null;
217
+ incarnation: number;
218
+ epoch: number;
219
+ seq: number;
220
+ cursor: string;
221
+ time: string;
222
+ schemaVersion: number;
223
+ source: {
224
+ kind: "api" | "controller" | "edge" | "egress-gate" | "evidence" | "harness" | "human" | "init" | "loop" | "model-gate" | "operator" | "sandboxd" | "supervisor" | "tool-gate";
225
+ id: string;
226
+ };
227
+ evidence: "asserted" | "attested" | "claimed" | "measured" | "observed";
228
+ trace?: {
229
+ traceId: string;
230
+ spanId: string;
231
+ parentSpanId?: string | undefined;
232
+ } | undefined;
233
+ visibility: "internal" | "public" | "restricted";
234
+ retention: "full" | "metadata";
235
+ type: string;
236
+ payload: unknown;
237
+ } | import("@nylorun/core/contracts").SessionEvent)[];
238
+ cursor: string | null;
239
+ }>;
240
+ observe(options?: {
241
+ cursor?: string;
242
+ signal?: AbortSignal;
243
+ follow?: boolean;
244
+ }): AsyncGenerator<{
245
+ schema: "nylorun.event/2";
246
+ eventId: string;
247
+ tenantId: string;
248
+ sessionId: string;
249
+ runId: string | null;
250
+ turnId: string | null;
251
+ incarnation: number;
252
+ epoch: number;
253
+ seq: number;
254
+ cursor: string;
255
+ time: string;
256
+ schemaVersion: number;
257
+ source: {
258
+ kind: "api" | "controller" | "edge" | "egress-gate" | "evidence" | "harness" | "human" | "init" | "loop" | "model-gate" | "operator" | "sandboxd" | "supervisor" | "tool-gate";
259
+ id: string;
260
+ };
261
+ evidence: "asserted" | "attested" | "claimed" | "measured" | "observed";
262
+ trace?: {
263
+ traceId: string;
264
+ spanId: string;
265
+ parentSpanId?: string | undefined;
266
+ } | undefined;
267
+ visibility: "internal" | "public" | "restricted";
268
+ retention: "full" | "metadata";
269
+ type: string;
270
+ payload: unknown;
271
+ }, void, unknown>;
272
+ private observeOne;
273
+ /**
274
+ * Own session stream plus linked agent sessions announced in `node.agent`
275
+ * events, merged by `time` then arrival order (workflows.md §11).
276
+ */
277
+ private observeFollowing;
278
+ }
279
+ export { RuntimeError, IncompatibleRuntimeError } from "./http.js";
280
+ export type { Destination, IncompatibleReason } from "./http.js";
281
+ export type { LiveEvent } from "@nylorun/core/contracts";
282
+ export { AccessClient, PublishableKeysClient, SigningKeysClient, TokensClient, } from "./access.js";