@valon-technologies/gestalt 0.0.1-alpha.13 → 0.0.1-alpha.16

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valon-technologies/gestalt",
3
- "version": "0.0.1-alpha.13",
3
+ "version": "0.0.1-alpha.16",
4
4
  "description": "TypeScript SDK for Gestalt executable providers",
5
5
  "type": "module",
6
6
  "repository": {
@@ -12,6 +12,7 @@
12
12
  "./build": "./src/build.ts",
13
13
  "./runtime": "./src/runtime.ts",
14
14
  "./schema": "./src/schema.ts",
15
+ "./telemetry": "./src/telemetry.ts",
15
16
  "./target": "./src/target.ts"
16
17
  },
17
18
  "bin": {
@@ -34,13 +35,14 @@
34
35
  "docs:build:deploy": "typedoc --options typedoc.json --out ../../docs/public/api/typescript",
35
36
  "docs:check": "bun run docs:lint && bun run docs:build",
36
37
  "typecheck": "tsc --noEmit",
37
- "test": "bun test",
38
- "check": "bun test && tsc --noEmit"
38
+ "test": "bun test --max-concurrency 1",
39
+ "check": "bun run test && tsc --noEmit"
39
40
  },
40
41
  "dependencies": {
41
42
  "@bufbuild/protobuf": "2.11.0",
42
43
  "@connectrpc/connect": "2.1.0",
43
44
  "@connectrpc/connect-node": "2.1.0",
45
+ "@opentelemetry/api": "1.9.0",
44
46
  "yaml": "2.8.1"
45
47
  },
46
48
  "devDependencies": {
package/src/agent.ts CHANGED
@@ -1,11 +1,17 @@
1
- import { connect } from "node:net";
2
-
3
- import { create, type MessageInitShape } from "@bufbuild/protobuf";
1
+ import {
2
+ create,
3
+ fromJson,
4
+ isMessage,
5
+ type JsonValue,
6
+ type MessageInitShape,
7
+ } from "@bufbuild/protobuf";
8
+ import { ValueSchema, type Value } from "@bufbuild/protobuf/wkt";
4
9
  import {
5
10
  Code,
6
11
  ConnectError,
7
12
  createClient,
8
13
  type Client,
14
+ type Interceptor,
9
15
  type ServiceImpl,
10
16
  } from "@connectrpc/connect";
11
17
  import { createGrpcTransport } from "@connectrpc/connect-node";
@@ -22,6 +28,7 @@ import {
22
28
  AgentSessionSchema,
23
29
  AgentSessionState,
24
30
  AgentToolSourceMode,
31
+ AgentTurnDisplaySchema,
25
32
  AgentTurnEventSchema,
26
33
  AgentTurnSchema,
27
34
  GetAgentProviderCapabilitiesRequestSchema,
@@ -40,8 +47,8 @@ import {
40
47
  type AgentSession,
41
48
  type AgentToolRef,
42
49
  type AgentTurn,
50
+ type AgentTurnDisplay,
43
51
  type AgentTurnEvent,
44
- type BoundAgentToolTarget,
45
52
  type CancelAgentProviderTurnRequest,
46
53
  type CreateAgentProviderSessionRequest,
47
54
  type CreateAgentProviderTurnRequest,
@@ -51,18 +58,25 @@ import {
51
58
  type GetAgentProviderInteractionRequest,
52
59
  type GetAgentProviderSessionRequest,
53
60
  type GetAgentProviderTurnRequest,
61
+ type ListAgentToolsRequest,
62
+ type ListAgentToolsResponse,
54
63
  type ListAgentProviderInteractionsRequest,
55
64
  type ListAgentProviderSessionsRequest,
56
65
  type ListAgentProviderTurnEventsRequest,
57
66
  type ListAgentProviderTurnsRequest,
67
+ type ListedAgentTool,
58
68
  type ResolveAgentProviderInteractionRequest,
59
69
  type ResolvedAgentTool,
70
+ type SearchAgentToolsRequest,
71
+ type SearchAgentToolsResponse,
60
72
  type UpdateAgentProviderSessionRequest,
61
73
  } from "../gen/v1/agent_pb.ts";
62
74
  import { errorMessage, type MaybePromise } from "./api.ts";
63
75
  import { RuntimeProvider, type RuntimeProviderOptions } from "./provider.ts";
64
76
 
65
77
  export const ENV_AGENT_HOST_SOCKET = "GESTALT_AGENT_HOST_SOCKET";
78
+ export const ENV_AGENT_HOST_SOCKET_TOKEN = `${ENV_AGENT_HOST_SOCKET}_TOKEN`;
79
+ const AGENT_HOST_RELAY_TOKEN_HEADER = "x-gestalt-host-service-relay-token";
66
80
 
67
81
  export type {
68
82
  AgentActor,
@@ -76,8 +90,8 @@ export type {
76
90
  AgentSession,
77
91
  AgentToolRef,
78
92
  AgentTurn,
93
+ AgentTurnDisplay,
79
94
  AgentTurnEvent,
80
- BoundAgentToolTarget,
81
95
  CancelAgentProviderTurnRequest,
82
96
  CreateAgentProviderSessionRequest,
83
97
  CreateAgentProviderTurnRequest,
@@ -87,12 +101,17 @@ export type {
87
101
  GetAgentProviderInteractionRequest,
88
102
  GetAgentProviderSessionRequest,
89
103
  GetAgentProviderTurnRequest,
104
+ ListAgentToolsRequest,
105
+ ListAgentToolsResponse,
90
106
  ListAgentProviderInteractionsRequest,
91
107
  ListAgentProviderSessionsRequest,
92
108
  ListAgentProviderTurnEventsRequest,
93
109
  ListAgentProviderTurnsRequest,
110
+ ListedAgentTool,
94
111
  ResolveAgentProviderInteractionRequest,
95
112
  ResolvedAgentTool,
113
+ SearchAgentToolsRequest,
114
+ SearchAgentToolsResponse,
96
115
  UpdateAgentProviderSessionRequest,
97
116
  };
98
117
  export {
@@ -104,6 +123,27 @@ export {
104
123
  AgentToolSourceMode,
105
124
  };
106
125
 
126
+ export type AgentTurnDisplayValue =
127
+ | JsonValue
128
+ | Value
129
+ | MessageInitShape<typeof ValueSchema>;
130
+
131
+ export type AgentTurnDisplayInit = Omit<
132
+ MessageInitShape<typeof AgentTurnDisplaySchema>,
133
+ "$typeName" | "input" | "output" | "error"
134
+ > & {
135
+ input?: AgentTurnDisplayValue | undefined;
136
+ output?: AgentTurnDisplayValue | undefined;
137
+ error?: AgentTurnDisplayValue | undefined;
138
+ };
139
+
140
+ export type AgentTurnEventInit = Omit<
141
+ MessageInitShape<typeof AgentTurnEventSchema>,
142
+ "$typeName" | "display"
143
+ > & {
144
+ display?: AgentTurnDisplayInit | undefined;
145
+ };
146
+
107
147
  export interface AgentProviderOptions extends RuntimeProviderOptions {
108
148
  createSession?: (
109
149
  request: CreateAgentProviderSessionRequest,
@@ -131,7 +171,7 @@ export interface AgentProviderOptions extends RuntimeProviderOptions {
131
171
  ) => MaybePromise<MessageInitShape<typeof AgentTurnSchema>>;
132
172
  listTurnEvents?: (
133
173
  request: ListAgentProviderTurnEventsRequest,
134
- ) => MaybePromise<MessageInitShape<typeof AgentTurnEventSchema>[]>;
174
+ ) => MaybePromise<AgentTurnEventInit[]>;
135
175
  getInteraction?: (
136
176
  request: GetAgentProviderInteractionRequest,
137
177
  ) => MaybePromise<MessageInitShape<typeof AgentInteractionSchema>>;
@@ -262,7 +302,7 @@ export class AgentProvider extends RuntimeProvider {
262
302
 
263
303
  async listTurnEvents(
264
304
  request: ListAgentProviderTurnEventsRequest,
265
- ): Promise<MessageInitShape<typeof AgentTurnEventSchema>[]> {
305
+ ): Promise<AgentTurnEventInit[]> {
266
306
  return await requireAgentProviderHandler(
267
307
  "list turn events",
268
308
  this.listTurnEventsHandler,
@@ -318,6 +358,56 @@ export function defineAgentProvider(options: AgentProviderOptions): AgentProvide
318
358
  return new AgentProvider(options);
319
359
  }
320
360
 
361
+ function normalizeAgentTurnEvents(
362
+ events: AgentTurnEventInit[],
363
+ ): MessageInitShape<typeof AgentTurnEventSchema>[] {
364
+ return events.map((event) => normalizeAgentTurnEvent(event));
365
+ }
366
+
367
+ function normalizeAgentTurnEvent(
368
+ event: AgentTurnEventInit,
369
+ ): MessageInitShape<typeof AgentTurnEventSchema> {
370
+ const display = event.display;
371
+ if (!display) {
372
+ return event as MessageInitShape<typeof AgentTurnEventSchema>;
373
+ }
374
+ return {
375
+ ...event,
376
+ display: {
377
+ ...display,
378
+ input: normalizeAgentTurnDisplayValue(display.input),
379
+ output: normalizeAgentTurnDisplayValue(display.output),
380
+ error: normalizeAgentTurnDisplayValue(display.error),
381
+ },
382
+ } as MessageInitShape<typeof AgentTurnEventSchema>;
383
+ }
384
+
385
+ function normalizeAgentTurnDisplayValue(value: unknown): Value | undefined {
386
+ if (value === undefined) {
387
+ return undefined;
388
+ }
389
+ if (isMessage(value, ValueSchema)) {
390
+ return value;
391
+ }
392
+ if (isValueInit(value)) {
393
+ return create(ValueSchema, value);
394
+ }
395
+ return fromJson(ValueSchema, value as JsonValue);
396
+ }
397
+
398
+ function isValueInit(value: unknown): value is MessageInitShape<typeof ValueSchema> {
399
+ if (value === null || typeof value !== "object") {
400
+ return false;
401
+ }
402
+ const kind = (value as { kind?: unknown }).kind;
403
+ return (
404
+ kind !== null &&
405
+ typeof kind === "object" &&
406
+ typeof (kind as { case?: unknown }).case === "string" &&
407
+ "value" in kind
408
+ );
409
+ }
410
+
321
411
  export function isAgentProvider(value: unknown): value is AgentProvider {
322
412
  return (
323
413
  value instanceof AgentProvider ||
@@ -334,15 +424,14 @@ export class AgentHost {
334
424
  private readonly client: Client<typeof AgentHostService>;
335
425
 
336
426
  constructor() {
337
- const socketPath = process.env[ENV_AGENT_HOST_SOCKET];
338
- if (!socketPath) {
427
+ const target = process.env[ENV_AGENT_HOST_SOCKET];
428
+ if (!target) {
339
429
  throw new Error(`agent host: ${ENV_AGENT_HOST_SOCKET} is not set`);
340
430
  }
431
+ const relayToken = process.env[ENV_AGENT_HOST_SOCKET_TOKEN]?.trim() ?? "";
341
432
  const transport = createGrpcTransport({
342
- baseUrl: "http://localhost",
343
- nodeOptions: {
344
- createConnection: () => connect(socketPath),
345
- },
433
+ ...agentHostTransportOptions(target),
434
+ interceptors: relayToken ? [agentHostRelayTokenInterceptor(relayToken)] : [],
346
435
  });
347
436
  this.client = createClient(AgentHostService, transport);
348
437
  }
@@ -353,6 +442,68 @@ export class AgentHost {
353
442
  return await this.client.executeTool(request);
354
443
  }
355
444
 
445
+ async searchTools(
446
+ request: SearchAgentToolsRequest,
447
+ ): Promise<SearchAgentToolsResponse> {
448
+ return await this.client.searchTools(request);
449
+ }
450
+
451
+ async listTools(
452
+ request: ListAgentToolsRequest,
453
+ ): Promise<ListAgentToolsResponse> {
454
+ return await this.client.listTools(request);
455
+ }
456
+ }
457
+
458
+ function agentHostTransportOptions(rawTarget: string): {
459
+ baseUrl: string;
460
+ nodeOptions?: { path: string };
461
+ } {
462
+ const target = rawTarget.trim();
463
+ if (!target) {
464
+ throw new Error("agent host: transport target is required");
465
+ }
466
+ if (target.startsWith("tcp://")) {
467
+ const address = target.slice("tcp://".length).trim();
468
+ if (!address) {
469
+ throw new Error(
470
+ `agent host: tcp target ${JSON.stringify(rawTarget)} is missing host:port`,
471
+ );
472
+ }
473
+ return { baseUrl: `http://${address}` };
474
+ }
475
+ if (target.startsWith("tls://")) {
476
+ const address = target.slice("tls://".length).trim();
477
+ if (!address) {
478
+ throw new Error(
479
+ `agent host: tls target ${JSON.stringify(rawTarget)} is missing host:port`,
480
+ );
481
+ }
482
+ return { baseUrl: `https://${address}` };
483
+ }
484
+ if (target.startsWith("unix://")) {
485
+ const socketPath = target.slice("unix://".length).trim();
486
+ if (!socketPath) {
487
+ throw new Error(
488
+ `agent host: unix target ${JSON.stringify(rawTarget)} is missing a socket path`,
489
+ );
490
+ }
491
+ return { baseUrl: "http://localhost", nodeOptions: { path: socketPath } };
492
+ }
493
+ if (target.includes("://")) {
494
+ const parsed = new URL(target);
495
+ throw new Error(
496
+ `agent host: unsupported target scheme ${JSON.stringify(parsed.protocol.replace(/:$/, ""))}`,
497
+ );
498
+ }
499
+ return { baseUrl: "http://localhost", nodeOptions: { path: target } };
500
+ }
501
+
502
+ function agentHostRelayTokenInterceptor(token: string): Interceptor {
503
+ return (next) => async (req) => {
504
+ req.header.set(AGENT_HOST_RELAY_TOKEN_HEADER, token);
505
+ return next(req);
506
+ };
356
507
  }
357
508
 
358
509
  export function createAgentProviderService(
@@ -421,8 +572,10 @@ export function createAgentProviderService(
421
572
  },
422
573
  async listTurnEvents(request) {
423
574
  return create(ListAgentProviderTurnEventsResponseSchema, {
424
- events: await invokeAgentProvider("list turn events", () =>
425
- provider.listTurnEvents(request),
575
+ events: normalizeAgentTurnEvents(
576
+ await invokeAgentProvider("list turn events", () =>
577
+ provider.listTurnEvents(request),
578
+ ),
426
579
  ),
427
580
  });
428
581
  },
package/src/api.ts CHANGED
@@ -35,8 +35,9 @@ export interface Request {
35
35
  subject: Subject;
36
36
  credential: Credential;
37
37
  access: Access;
38
+ idempotencyKey: string;
38
39
  // Workflow callback metadata uses a JSON-style lowerCamelCase object such as
39
- // runId, target.pluginName, trigger.scheduleId, and trigger.event.specVersion.
40
+ // runId, target.plugin.pluginName, trigger.scheduleId, and trigger.event.specVersion.
40
41
  workflow: Record<string, unknown>;
41
42
  invocationToken: string;
42
43
  }
@@ -104,6 +105,7 @@ export function request(
104
105
  access: Partial<Access> = {},
105
106
  workflow: Record<string, unknown> = {},
106
107
  invocationToken = "",
108
+ idempotencyKey = "",
107
109
  ): Request {
108
110
  return {
109
111
  token,
@@ -130,6 +132,7 @@ export function request(
130
132
  ...workflow,
131
133
  },
132
134
  invocationToken,
135
+ idempotencyKey: idempotencyKey.trim(),
133
136
  };
134
137
  }
135
138
 
package/src/build.ts CHANGED
@@ -1,3 +1,5 @@
1
+ #!/usr/bin/env bun
2
+
1
3
  import { spawnSync } from "node:child_process";
2
4
  import { existsSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
3
5
  import { homedir, tmpdir } from "node:os";
package/src/index.ts CHANGED
@@ -77,21 +77,6 @@ export {
77
77
  type CatalogParameter,
78
78
  type CatalogSchema,
79
79
  } from "./catalog.ts";
80
- export {
81
- hasPluginManifestMetadata,
82
- manifestMetadataToYaml,
83
- writeManifestMetadataYaml,
84
- type HTTPAck,
85
- type HTTPAuthScheme,
86
- type HTTPBinding,
87
- type HTTPIn,
88
- type HTTPMediaType,
89
- type HTTPRequestBody,
90
- type HTTPSecretRef,
91
- type HTTPSecurityScheme,
92
- type HTTPSecuritySchemeType,
93
- type PluginManifestMetadata,
94
- } from "./manifest-metadata.ts";
95
80
  export {
96
81
  buildProviderBinary,
97
82
  bunBuildCommand,
@@ -143,6 +128,18 @@ export {
143
128
  type WorkflowManagerUpdateTriggerInput,
144
129
  type WorkflowManagerUpdateScheduleInput,
145
130
  } from "./workflow-manager.ts";
131
+ export {
132
+ ENV_RUNTIME_LOG_HOST_SOCKET,
133
+ ENV_RUNTIME_LOG_HOST_SOCKET_TOKEN,
134
+ ENV_RUNTIME_SESSION_ID,
135
+ RuntimeLogHost,
136
+ type RuntimeLogAppendInput,
137
+ type RuntimeLogAppendLogsInput,
138
+ type RuntimeLogAppendResponseMessage,
139
+ type RuntimeLogStreamInput,
140
+ type RuntimeLogStreamName,
141
+ type RuntimeLogWriterOptions,
142
+ } from "./runtime-log-host.ts";
146
143
  export {
147
144
  AuthenticationProvider,
148
145
  defineAuthenticationProvider,
@@ -199,8 +196,28 @@ export {
199
196
  type ProviderKind,
200
197
  type ProviderMetadata,
201
198
  type RuntimeProviderOptions,
199
+ type StartHandler,
202
200
  type WarningsHandler,
203
201
  } from "./provider.ts";
202
+ export {
203
+ PluginRuntimeEgressMode,
204
+ PluginRuntimeHostServiceAccess,
205
+ PluginRuntimeProvider,
206
+ createPluginRuntimeProviderService,
207
+ definePluginRuntimeProvider,
208
+ isPluginRuntimeProvider,
209
+ type BindPluginRuntimeHostServiceRequest,
210
+ type GetPluginRuntimeSessionRequest,
211
+ type HostedPlugin,
212
+ type ListPluginRuntimeSessionsRequest,
213
+ type PluginRuntimeHostServiceBinding,
214
+ type PluginRuntimeProviderOptions,
215
+ type PluginRuntimeSession,
216
+ type PluginRuntimeSupport,
217
+ type StartHostedPluginRequest,
218
+ type StartPluginRuntimeSessionRequest,
219
+ type StopPluginRuntimeSessionRequest,
220
+ } from "./pluginruntime.ts";
204
221
  export {
205
222
  array,
206
223
  boolean,
@@ -219,7 +236,6 @@ export {
219
236
  ENV_PROVIDER_PARENT_PID,
220
237
  ENV_PROVIDER_SOCKET,
221
238
  ENV_WRITE_CATALOG,
222
- ENV_WRITE_MANIFEST_METADATA,
223
239
  createAuthenticationService,
224
240
  createCacheService,
225
241
  createSecretsService,
@@ -250,15 +266,22 @@ export {
250
266
  IndexedDB,
251
267
  ObjectStore,
252
268
  Index,
269
+ Transaction,
270
+ TransactionObjectStore,
271
+ TransactionIndex,
253
272
  Cursor,
254
273
  CursorDirection,
255
274
  NotFoundError,
256
275
  AlreadyExistsError,
276
+ TransactionError,
257
277
  ColumnType,
258
278
  indexedDBSocketEnv,
259
279
  indexedDBSocketTokenEnv,
260
280
  type Record,
261
281
  type KeyRange,
282
+ type TransactionMode,
283
+ type TransactionDurabilityHint,
284
+ type TransactionOptions,
262
285
  type ColumnSchema,
263
286
  type IndexSchema,
264
287
  type ObjectStoreSchema,
@@ -283,6 +306,8 @@ export {
283
306
  type CopyOptions,
284
307
  type ListOptions,
285
308
  type ListPage,
309
+ type ObjectAccessURL,
310
+ type ObjectAccessURLOptions,
286
311
  type ObjectMeta,
287
312
  type ObjectRef,
288
313
  type PresignOptions,
@@ -296,6 +321,7 @@ export {
296
321
  } from "./s3.ts";
297
322
  export {
298
323
  ENV_AGENT_HOST_SOCKET,
324
+ ENV_AGENT_HOST_SOCKET_TOKEN,
299
325
  AgentHost,
300
326
  AgentExecutionStatus,
301
327
  AgentInteractionState,
@@ -319,8 +345,11 @@ export {
319
345
  type AgentSession,
320
346
  type AgentToolRef,
321
347
  type AgentTurn,
348
+ type AgentTurnDisplay,
349
+ type AgentTurnDisplayInit,
350
+ type AgentTurnDisplayValue,
322
351
  type AgentTurnEvent,
323
- type BoundAgentToolTarget,
352
+ type AgentTurnEventInit,
324
353
  type CancelAgentProviderTurnRequest,
325
354
  type CreateAgentProviderSessionRequest,
326
355
  type CreateAgentProviderTurnRequest,
@@ -330,12 +359,17 @@ export {
330
359
  type GetAgentProviderInteractionRequest,
331
360
  type GetAgentProviderSessionRequest,
332
361
  type GetAgentProviderTurnRequest,
362
+ type ListAgentToolsRequest,
363
+ type ListAgentToolsResponse,
333
364
  type ListAgentProviderInteractionsRequest,
334
365
  type ListAgentProviderSessionsRequest,
335
366
  type ListAgentProviderTurnEventsRequest,
336
367
  type ListAgentProviderTurnsRequest,
337
- type ResolvedAgentTool,
368
+ type ListedAgentTool,
338
369
  type ResolveAgentProviderInteractionRequest,
370
+ type ResolvedAgentTool,
371
+ type SearchAgentToolsRequest,
372
+ type SearchAgentToolsResponse,
339
373
  type UpdateAgentProviderSessionRequest,
340
374
  } from "./agent.ts";
341
375
  export {
@@ -371,3 +405,20 @@ export {
371
405
  type WorkflowEvent,
372
406
  type WorkflowProviderOptions,
373
407
  } from "./workflow.ts";
408
+ export {
409
+ GENAI_OPERATION_CHAT,
410
+ GENAI_OPERATION_EXECUTE_TOOL,
411
+ GENAI_OPERATION_INVOKE_AGENT,
412
+ GENAI_PROVIDER_NAME,
413
+ GENAI_TOOL_TYPE_DATASTORE,
414
+ GENAI_TOOL_TYPE_EXTENSION,
415
+ GenAIOperation,
416
+ TELEMETRY_INSTRUMENTATION_NAME,
417
+ withAgentInvocation,
418
+ withModelOperation,
419
+ withToolExecution,
420
+ type AgentInvocationOptions,
421
+ type ModelOperationOptions,
422
+ type TokenUsage,
423
+ type ToolExecutionOptions,
424
+ } from "./telemetry.ts";