@introspection-sdk/introspection-node 0.19.1 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. package/README.md +28 -8
  2. package/dist/auth.d.ts +1 -1
  3. package/dist/client.d.ts +4 -3
  4. package/dist/client.d.ts.map +1 -1
  5. package/dist/client.js +16 -7
  6. package/dist/client.js.map +1 -1
  7. package/dist/dev-target.js +1 -1
  8. package/dist/index.d.ts +4 -7
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +3 -6
  11. package/dist/index.js.map +1 -1
  12. package/dist/otel/index.d.ts +1 -14
  13. package/dist/otel/index.d.ts.map +1 -1
  14. package/dist/otel/index.js +10 -18
  15. package/dist/otel/index.js.map +1 -1
  16. package/dist/otel/init.d.ts +19 -21
  17. package/dist/otel/init.d.ts.map +1 -1
  18. package/dist/otel/init.js +62 -48
  19. package/dist/otel/init.js.map +1 -1
  20. package/dist/otel/integrations/base.d.ts +17 -37
  21. package/dist/otel/integrations/base.d.ts.map +1 -1
  22. package/dist/otel/integrations/base.js +6 -13
  23. package/dist/otel/integrations/base.js.map +1 -1
  24. package/dist/otel/integrations/index.d.ts +3 -4
  25. package/dist/otel/integrations/index.d.ts.map +1 -1
  26. package/dist/otel/integrations/index.js +6 -25
  27. package/dist/otel/integrations/index.js.map +1 -1
  28. package/dist/otel/integrations/pi.d.ts.map +1 -1
  29. package/dist/otel/integrations/pi.js +9 -1
  30. package/dist/otel/integrations/pi.js.map +1 -1
  31. package/dist/otel/logs.d.ts +41 -8
  32. package/dist/otel/logs.d.ts.map +1 -1
  33. package/dist/otel/logs.js +95 -66
  34. package/dist/otel/logs.js.map +1 -1
  35. package/dist/otel/pi.d.ts +18 -5
  36. package/dist/otel/pi.d.ts.map +1 -1
  37. package/dist/otel/pi.js +38 -9
  38. package/dist/otel/pi.js.map +1 -1
  39. package/dist/otel/register.d.ts +2 -2
  40. package/dist/otel/register.d.ts.map +1 -1
  41. package/dist/otel/register.js +7 -9
  42. package/dist/otel/register.js.map +1 -1
  43. package/dist/otel/setup.d.ts +2 -2
  44. package/dist/otel/setup.d.ts.map +1 -1
  45. package/dist/otel/setup.js +16 -6
  46. package/dist/otel/setup.js.map +1 -1
  47. package/dist/otel/span-processor.d.ts +18 -5
  48. package/dist/otel/span-processor.d.ts.map +1 -1
  49. package/dist/otel/span-processor.js +50 -65
  50. package/dist/otel/span-processor.js.map +1 -1
  51. package/dist/resources/experiments.d.ts +10 -5
  52. package/dist/resources/experiments.d.ts.map +1 -1
  53. package/dist/resources/experiments.js +9 -25
  54. package/dist/resources/experiments.js.map +1 -1
  55. package/dist/resources/recipes.d.ts +6 -6
  56. package/dist/resources/recipes.d.ts.map +1 -1
  57. package/dist/resources/recipes.js +5 -23
  58. package/dist/resources/recipes.js.map +1 -1
  59. package/dist/resources/runtimes.d.ts +2 -2
  60. package/dist/resources/runtimes.d.ts.map +1 -1
  61. package/dist/resources/runtimes.js +2 -2
  62. package/dist/resources/runtimes.js.map +1 -1
  63. package/dist/runner.d.ts +8 -4
  64. package/dist/runner.d.ts.map +1 -1
  65. package/dist/runner.js +26 -18
  66. package/dist/runner.js.map +1 -1
  67. package/dist/types.d.ts +1 -1
  68. package/dist/types.d.ts.map +1 -1
  69. package/dist/types.js +1 -1
  70. package/dist/types.js.map +1 -1
  71. package/dist/utils.d.ts +45 -0
  72. package/dist/utils.d.ts.map +1 -1
  73. package/dist/utils.js +61 -2
  74. package/dist/utils.js.map +1 -1
  75. package/dist/version.d.ts +1 -1
  76. package/dist/version.d.ts.map +1 -1
  77. package/dist/version.js +1 -1
  78. package/dist/version.js.map +1 -1
  79. package/package.json +18 -60
  80. package/.turbo/turbo-build.log +0 -4
  81. package/dist/converters/claude.d.ts +0 -150
  82. package/dist/converters/claude.d.ts.map +0 -1
  83. package/dist/converters/claude.js +0 -211
  84. package/dist/converters/claude.js.map +0 -1
  85. package/dist/converters/gemini.d.ts +0 -90
  86. package/dist/converters/gemini.d.ts.map +0 -1
  87. package/dist/converters/gemini.js +0 -171
  88. package/dist/converters/gemini.js.map +0 -1
  89. package/dist/converters/index.d.ts +0 -9
  90. package/dist/converters/index.d.ts.map +0 -1
  91. package/dist/converters/index.js +0 -9
  92. package/dist/converters/index.js.map +0 -1
  93. package/dist/converters/openai.d.ts +0 -51
  94. package/dist/converters/openai.d.ts.map +0 -1
  95. package/dist/converters/openai.js +0 -269
  96. package/dist/converters/openai.js.map +0 -1
  97. package/dist/converters/openinference.d.ts +0 -107
  98. package/dist/converters/openinference.d.ts.map +0 -1
  99. package/dist/converters/openinference.js +0 -553
  100. package/dist/converters/openinference.js.map +0 -1
  101. package/dist/converters/vercel.d.ts +0 -21
  102. package/dist/converters/vercel.d.ts.map +0 -1
  103. package/dist/converters/vercel.js +0 -236
  104. package/dist/converters/vercel.js.map +0 -1
  105. package/dist/otel/anthropic.d.ts +0 -63
  106. package/dist/otel/anthropic.d.ts.map +0 -1
  107. package/dist/otel/anthropic.js +0 -475
  108. package/dist/otel/anthropic.js.map +0 -1
  109. package/dist/otel/claude-hooks.d.ts +0 -346
  110. package/dist/otel/claude-hooks.d.ts.map +0 -1
  111. package/dist/otel/claude-hooks.js +0 -647
  112. package/dist/otel/claude-hooks.js.map +0 -1
  113. package/dist/otel/claude-wrapper.d.ts +0 -93
  114. package/dist/otel/claude-wrapper.d.ts.map +0 -1
  115. package/dist/otel/claude-wrapper.js +0 -155
  116. package/dist/otel/claude-wrapper.js.map +0 -1
  117. package/dist/otel/gemini.d.ts +0 -56
  118. package/dist/otel/gemini.d.ts.map +0 -1
  119. package/dist/otel/gemini.js +0 -350
  120. package/dist/otel/gemini.js.map +0 -1
  121. package/dist/otel/integrations/anthropic.d.ts +0 -10
  122. package/dist/otel/integrations/anthropic.d.ts.map +0 -1
  123. package/dist/otel/integrations/anthropic.js +0 -26
  124. package/dist/otel/integrations/anthropic.js.map +0 -1
  125. package/dist/otel/integrations/claude-agent.d.ts +0 -12
  126. package/dist/otel/integrations/claude-agent.d.ts.map +0 -1
  127. package/dist/otel/integrations/claude-agent.js +0 -28
  128. package/dist/otel/integrations/claude-agent.js.map +0 -1
  129. package/dist/otel/integrations/gemini.d.ts +0 -11
  130. package/dist/otel/integrations/gemini.d.ts.map +0 -1
  131. package/dist/otel/integrations/gemini.js +0 -23
  132. package/dist/otel/integrations/gemini.js.map +0 -1
  133. package/dist/otel/integrations/langchain.d.ts +0 -15
  134. package/dist/otel/integrations/langchain.d.ts.map +0 -1
  135. package/dist/otel/integrations/langchain.js +0 -43
  136. package/dist/otel/integrations/langchain.js.map +0 -1
  137. package/dist/otel/integrations/mastra.d.ts +0 -14
  138. package/dist/otel/integrations/mastra.d.ts.map +0 -1
  139. package/dist/otel/integrations/mastra.js +0 -31
  140. package/dist/otel/integrations/mastra.js.map +0 -1
  141. package/dist/otel/integrations/openai-agents.d.ts +0 -11
  142. package/dist/otel/integrations/openai-agents.d.ts.map +0 -1
  143. package/dist/otel/integrations/openai-agents.js +0 -30
  144. package/dist/otel/integrations/openai-agents.js.map +0 -1
  145. package/dist/otel/integrations/vercel.d.ts +0 -14
  146. package/dist/otel/integrations/vercel.d.ts.map +0 -1
  147. package/dist/otel/integrations/vercel.js +0 -20
  148. package/dist/otel/integrations/vercel.js.map +0 -1
  149. package/dist/otel/langchain-handler.d.ts +0 -112
  150. package/dist/otel/langchain-handler.d.ts.map +0 -1
  151. package/dist/otel/langchain-handler.js +0 -561
  152. package/dist/otel/langchain-handler.js.map +0 -1
  153. package/dist/otel/mastra-exporter.d.ts +0 -87
  154. package/dist/otel/mastra-exporter.d.ts.map +0 -1
  155. package/dist/otel/mastra-exporter.js +0 -530
  156. package/dist/otel/mastra-exporter.js.map +0 -1
  157. package/dist/otel/openai.d.ts +0 -20
  158. package/dist/otel/openai.d.ts.map +0 -1
  159. package/dist/otel/openai.js +0 -55
  160. package/dist/otel/openai.js.map +0 -1
  161. package/dist/otel/tracing-processor.d.ts +0 -139
  162. package/dist/otel/tracing-processor.d.ts.map +0 -1
  163. package/dist/otel/tracing-processor.js +0 -434
  164. package/dist/otel/tracing-processor.js.map +0 -1
  165. package/eslint.config.mjs +0 -4
  166. package/src/auth.ts +0 -236
  167. package/src/client.ts +0 -163
  168. package/src/converters/claude.ts +0 -343
  169. package/src/converters/gemini.ts +0 -243
  170. package/src/converters/index.ts +0 -50
  171. package/src/converters/openai.ts +0 -300
  172. package/src/converters/openinference.ts +0 -665
  173. package/src/converters/vercel.ts +0 -302
  174. package/src/dev-target.ts +0 -79
  175. package/src/http.ts +0 -43
  176. package/src/index.ts +0 -266
  177. package/src/otel/anthropic.ts +0 -619
  178. package/src/otel/claude-hooks.ts +0 -1116
  179. package/src/otel/claude-wrapper.ts +0 -239
  180. package/src/otel/gemini.ts +0 -483
  181. package/src/otel/index.ts +0 -128
  182. package/src/otel/init.ts +0 -411
  183. package/src/otel/integrations/anthropic.ts +0 -36
  184. package/src/otel/integrations/base.ts +0 -158
  185. package/src/otel/integrations/claude-agent.ts +0 -36
  186. package/src/otel/integrations/gemini.ts +0 -30
  187. package/src/otel/integrations/index.ts +0 -152
  188. package/src/otel/integrations/langchain.ts +0 -60
  189. package/src/otel/integrations/mastra.ts +0 -48
  190. package/src/otel/integrations/openai-agents.ts +0 -47
  191. package/src/otel/integrations/pi.ts +0 -28
  192. package/src/otel/integrations/vercel.ts +0 -26
  193. package/src/otel/langchain-handler.ts +0 -804
  194. package/src/otel/logs.ts +0 -395
  195. package/src/otel/mastra-exporter.ts +0 -714
  196. package/src/otel/openai.ts +0 -93
  197. package/src/otel/pi.ts +0 -94
  198. package/src/otel/register.ts +0 -50
  199. package/src/otel/setup.ts +0 -215
  200. package/src/otel/span-processor.ts +0 -512
  201. package/src/otel/tracing-processor.ts +0 -637
  202. package/src/pagination.ts +0 -10
  203. package/src/proxy-from-env.d.ts +0 -7
  204. package/src/resources/experiments.ts +0 -176
  205. package/src/resources/recipes.ts +0 -74
  206. package/src/resources/runtimes.ts +0 -31
  207. package/src/runner.ts +0 -213
  208. package/src/types.ts +0 -13
  209. package/src/utils.ts +0 -95
  210. package/src/version.ts +0 -2
  211. package/tsconfig.json +0 -8
@@ -1,176 +0,0 @@
1
- import type {
2
- Experiment,
3
- ExperimentCreate,
4
- ExperimentListParams,
5
- ExperimentUpdate,
6
- Paginated,
7
- RunRequest,
8
- RunnerSpec,
9
- Uuid,
10
- } from "@introspection-sdk/types";
11
- import type { HttpClient } from "../http.js";
12
- import type { IntrospectionClient } from "../client.js";
13
- import { Paginator, cursorPaginate } from "../pagination.js";
14
- import { Runner, type RunnerSource } from "../runner.js";
15
-
16
- interface ExperimentRunRequestBody {
17
- identity?: {
18
- user_id?: string;
19
- anonymous_id?: string;
20
- conversation_id?: string;
21
- };
22
- caller?: RunRequest["caller"];
23
- agent_name?: string;
24
- ttl_seconds?: number;
25
- scope?: string;
26
- }
27
-
28
- function toRunBody(opts?: RunRequest): ExperimentRunRequestBody | undefined {
29
- if (!opts) return undefined;
30
- const out: ExperimentRunRequestBody = {};
31
- if (opts.identity) out.identity = opts.identity;
32
- if (opts.caller) out.caller = opts.caller;
33
- if (opts.agent_name !== undefined) out.agent_name = opts.agent_name;
34
- if (opts.ttl_seconds !== undefined) out.ttl_seconds = opts.ttl_seconds;
35
- if (opts.scope !== undefined) out.scope = opts.scope;
36
- return out;
37
- }
38
-
39
- export class ExperimentsApi {
40
- constructor(
41
- private readonly http: HttpClient,
42
- private readonly client: IntrospectionClient,
43
- ) {}
44
-
45
- /**
46
- * List experiments matching `params`. `await` the result for the first
47
- * page, or `for await` it to stream every experiment across pages
48
- * (fetched lazily — `limit` sets the page size, `next` the starting
49
- * cursor; stop early to stop fetching).
50
- */
51
- list(params: ExperimentListParams): Paginator<Experiment> {
52
- return cursorPaginate(
53
- (next) =>
54
- this.http.request<Paginated<Experiment>>({
55
- method: "GET",
56
- path: "/v1/experiments",
57
- query: { ...params, next } as unknown as Record<string, unknown>,
58
- }),
59
- params.next,
60
- );
61
- }
62
-
63
- get(id: Uuid): Promise<Experiment> {
64
- return this.http.request<Experiment>({
65
- method: "GET",
66
- path: `/v1/experiments/${encodeURIComponent(id)}`,
67
- });
68
- }
69
-
70
- create(input: ExperimentCreate): Promise<Experiment> {
71
- return this.http.request<Experiment>({
72
- method: "POST",
73
- path: "/v1/experiments",
74
- body: input,
75
- });
76
- }
77
-
78
- update(id: Uuid, input: ExperimentUpdate): Promise<Experiment> {
79
- return this.http.request<Experiment>({
80
- method: "PATCH",
81
- path: `/v1/experiments/${encodeURIComponent(id)}`,
82
- body: input,
83
- });
84
- }
85
-
86
- delete(id: Uuid): Promise<void> {
87
- return this.http.request<void>({
88
- method: "DELETE",
89
- path: `/v1/experiments/${encodeURIComponent(id)}`,
90
- expect: "empty",
91
- });
92
- }
93
-
94
- startById(id: Uuid): Promise<Experiment> {
95
- return this.http.request<Experiment>({
96
- method: "POST",
97
- path: `/v1/experiments/${encodeURIComponent(id)}/start`,
98
- body: {},
99
- });
100
- }
101
-
102
- endById(id: Uuid): Promise<Experiment> {
103
- return this.http.request<Experiment>({
104
- method: "POST",
105
- path: `/v1/experiments/${encodeURIComponent(id)}/end`,
106
- body: {},
107
- });
108
- }
109
-
110
- cancelById(id: Uuid): Promise<Experiment> {
111
- return this.http.request<Experiment>({
112
- method: "POST",
113
- path: `/v1/experiments/${encodeURIComponent(id)}/cancel`,
114
- body: {},
115
- });
116
- }
117
-
118
- async runById(id: Uuid, opts?: RunRequest): Promise<Runner> {
119
- const spec = await this.http.request<RunnerSpec>({
120
- method: "POST",
121
- path: `/v1/experiments/${encodeURIComponent(id)}/run`,
122
- body: toRunBody(opts) ?? {},
123
- });
124
- const source: RunnerSource = {
125
- kind: "experiment",
126
- id,
127
- options: opts,
128
- };
129
- return new Runner(this.client, source, spec);
130
- }
131
- }
132
-
133
- export class ExperimentHandle {
134
- constructor(
135
- private readonly api: ExperimentsApi,
136
- private readonly id: Uuid,
137
- ) {}
138
-
139
- run(opts?: RunRequest): Promise<Runner> {
140
- return this.api.runById(this.id, opts);
141
- }
142
-
143
- start(): Promise<Experiment> {
144
- return this.api.startById(this.id);
145
- }
146
-
147
- end(): Promise<Experiment> {
148
- return this.api.endById(this.id);
149
- }
150
-
151
- cancel(): Promise<Experiment> {
152
- return this.api.cancelById(this.id);
153
- }
154
- }
155
-
156
- export type ExperimentHandleFactory = (id: Uuid) => ExperimentHandle;
157
-
158
- export function attachExperiments(
159
- client: IntrospectionClient,
160
- http: HttpClient,
161
- ): ExperimentsApi & ExperimentHandleFactory {
162
- const api = new ExperimentsApi(http, client);
163
- const factory: ExperimentHandleFactory = (id: Uuid) =>
164
- new ExperimentHandle(api, id);
165
- const hybrid = factory as ExperimentsApi & ExperimentHandleFactory;
166
- hybrid.list = api.list.bind(api);
167
- hybrid.get = api.get.bind(api);
168
- hybrid.create = api.create.bind(api);
169
- hybrid.update = api.update.bind(api);
170
- hybrid.delete = api.delete.bind(api);
171
- hybrid.startById = api.startById.bind(api);
172
- hybrid.endById = api.endById.bind(api);
173
- hybrid.cancelById = api.cancelById.bind(api);
174
- hybrid.runById = api.runById.bind(api);
175
- return hybrid;
176
- }
@@ -1,74 +0,0 @@
1
- import type {
2
- Paginated,
3
- Recipe,
4
- RecipeCreate,
5
- RecipeListParams,
6
- RecipeUpdate,
7
- Uuid,
8
- } from "@introspection-sdk/types";
9
- import type { HttpClient } from "../http.js";
10
- import { Paginator, cursorPaginate } from "../pagination.js";
11
-
12
- /**
13
- * Programmatic CRUD for `/v1/recipes` on the CP.
14
- *
15
- * Recipes are immutable build artefacts (repository + git ref + commit
16
- * sha + optional sub-path). They are referenced by runtimes via
17
- * `runtime.recipe_id` and by experiment arms via `arm.recipe_id`.
18
- */
19
- export class RecipesApi {
20
- constructor(private readonly http: HttpClient) {}
21
-
22
- /**
23
- * List recipes matching `params`. `await` the result for the first
24
- * page, or `for await` it to stream every recipe across pages (fetched
25
- * lazily — `limit` sets the page size, `next` the starting cursor; stop
26
- * early to stop fetching).
27
- */
28
- list(params: RecipeListParams): Paginator<Recipe> {
29
- return cursorPaginate(
30
- (next) =>
31
- this.http.request<Paginated<Recipe>>({
32
- method: "GET",
33
- path: "/v1/recipes",
34
- query: { ...params, next } as unknown as Record<string, unknown>,
35
- }),
36
- params.next,
37
- );
38
- }
39
-
40
- get(id: Uuid): Promise<Recipe> {
41
- return this.http.request<Recipe>({
42
- method: "GET",
43
- path: `/v1/recipes/${encodeURIComponent(id)}`,
44
- });
45
- }
46
-
47
- create(input: RecipeCreate): Promise<Recipe> {
48
- return this.http.request<Recipe>({
49
- method: "POST",
50
- path: "/v1/recipes",
51
- body: input,
52
- });
53
- }
54
-
55
- update(id: Uuid, input: RecipeUpdate): Promise<Recipe> {
56
- return this.http.request<Recipe>({
57
- method: "PATCH",
58
- path: `/v1/recipes/${encodeURIComponent(id)}`,
59
- body: input,
60
- });
61
- }
62
-
63
- delete(id: Uuid): Promise<void> {
64
- return this.http.request<void>({
65
- method: "DELETE",
66
- path: `/v1/recipes/${encodeURIComponent(id)}`,
67
- expect: "empty",
68
- });
69
- }
70
- }
71
-
72
- export function attachRecipes(http: HttpClient): RecipesApi {
73
- return new RecipesApi(http);
74
- }
@@ -1,31 +0,0 @@
1
- import {
2
- RuntimeHandle,
3
- RuntimesClient,
4
- attachRuntimes as attachSharedRuntimes,
5
- isUuid,
6
- type RuntimeHandleFactory as SharedRuntimeHandleFactory,
7
- } from "@introspection-sdk/http";
8
- import type { HttpClient } from "../http.js";
9
- import type { IntrospectionClient } from "../client.js";
10
- import { Runner } from "../runner.js";
11
-
12
- export { RuntimeHandle, isUuid };
13
-
14
- export class RuntimesApi extends RuntimesClient<Runner> {
15
- constructor(
16
- http: HttpClient,
17
- private readonly client: IntrospectionClient,
18
- ) {
19
- super(http, (source, spec) => new Runner(this.client, source, spec));
20
- }
21
- }
22
-
23
- export type RuntimeHandleFactory = SharedRuntimeHandleFactory<Runner>;
24
-
25
- export function attachRuntimes(
26
- client: IntrospectionClient,
27
- http: HttpClient,
28
- ): RuntimesApi & RuntimeHandleFactory {
29
- const api = new RuntimesApi(http, client);
30
- return attachSharedRuntimes(api) as RuntimesApi & RuntimeHandleFactory;
31
- }
package/src/runner.ts DELETED
@@ -1,213 +0,0 @@
1
- import {
2
- RunnerExpiredError,
3
- type RunnerContext,
4
- type RunnerDeployment,
5
- type RunnerSpec,
6
- type RunRequest,
7
- type Uuid,
8
- } from "@introspection-sdk/types";
9
- import {
10
- ConversationsApi,
11
- EventsApi,
12
- FilesApi,
13
- MetricsApi,
14
- SharesApi,
15
- TasksApi,
16
- } from "@introspection-sdk/http";
17
- import { HttpClient } from "./http.js";
18
- import type { IntrospectionClient } from "./client.js";
19
-
20
- /**
21
- * Where this Runner came from, so `refresh()` can call CP again with the
22
- * same arguments to obtain a fresh `RunnerSpec` (manual escape hatch only;
23
- * not auto-scheduled).
24
- */
25
- export type RunnerSource =
26
- | { kind: "runtime"; id: Uuid; options?: RunRequest }
27
- | { kind: "experiment"; id: Uuid; options?: RunRequest };
28
-
29
- /**
30
- * Live handle to a Data Plane sandbox. Holds the bearer JWT, the DP
31
- * endpoint URL, and the runtime/experiment context, and exposes the
32
- * runner-bound `tasks`, `files`, `conversations`, `events`, and
33
- * `metrics` namespaces (the telemetry reads are Data-Plane-scoped and so
34
- * hang off the runner, which carries the DP bearer + `events:read`).
35
- *
36
- * In v1 of the agent-session-based design, token refresh is handled
37
- * server-side by the DP materializer attached to the agent session — the
38
- * SDK does NOT auto-refresh and does NOT install a 401 safety-net. The
39
- * `refresh()` method is kept as a manual escape hatch that re-calls the
40
- * CP `/run` route to mint a brand-new spec.
41
- */
42
- export class Runner {
43
- private spec: RunnerSpec;
44
- private http: HttpClient;
45
- private closed = false;
46
-
47
- // Public API surfaces.
48
- readonly tasks: TasksApi;
49
- readonly files: FilesApi;
50
- readonly conversations: ConversationsApi;
51
- readonly events: EventsApi;
52
- readonly metrics: MetricsApi;
53
- readonly shares: SharesApi;
54
-
55
- constructor(
56
- private readonly client: IntrospectionClient,
57
- private readonly source: RunnerSource,
58
- spec: RunnerSpec,
59
- ) {
60
- this.spec = spec;
61
- this.http = this.buildHttp();
62
- this.tasks = new TasksApi(this.guardedHttp(this.http));
63
- this.files = new FilesApi(this.guardedHttp(this.http));
64
- this.conversations = new ConversationsApi(this.guardedHttp(this.http));
65
- this.events = new EventsApi(this.guardedHttp(this.http));
66
- this.metrics = new MetricsApi(this.guardedHttp(this.http));
67
- this.shares = new SharesApi(this.guardedHttp(this.http));
68
- }
69
-
70
- // --- public accessors ---
71
-
72
- /** DP REST base URL the runner is bound to. */
73
- get dpEndpoint(): string {
74
- return this.spec.deployment.endpoint;
75
- }
76
-
77
- /** Routing target — DP endpoint / slug / region. */
78
- get deployment(): Readonly<RunnerDeployment> {
79
- return Object.freeze({ ...this.spec.deployment });
80
- }
81
-
82
- /** Session lifetime (ISO-8601 string). */
83
- get expires_at(): string {
84
- return this.spec.expires_at;
85
- }
86
-
87
- /** Session ID assigned by CP. */
88
- get session_id(): string {
89
- return this.spec.session_id;
90
- }
91
-
92
- /** Resolved runtime / arm / recipe / identity / caller context. */
93
- get context(): Readonly<RunnerContext> {
94
- return Object.freeze({ ...this.spec.runtime_context });
95
- }
96
-
97
- /** True once `close()` has been called. */
98
- get isClosed(): boolean {
99
- return this.closed;
100
- }
101
-
102
- // --- lifecycle ---
103
-
104
- /**
105
- * Manual escape hatch: re-call CP `/v1/runtimes/{id}/run` or
106
- * `/v1/experiments/{id}/run` with the original `RunRequest` and replace
107
- * this runner's in-memory spec with a fresh one.
108
- *
109
- * Not auto-scheduled — in v1 the DP materializer refreshes the
110
- * underlying access token transparently for the agent-session-backed
111
- * runner. Call this only if you have an explicit reason to mint a new
112
- * session (e.g. you held a runner across a very long pause).
113
- */
114
- async refresh(): Promise<void> {
115
- if (this.closed) {
116
- throw new RunnerExpiredError({
117
- message: "Runner has been closed",
118
- status: 401,
119
- code: "runner_expired",
120
- });
121
- }
122
- const fresh = await this.requestFreshSpec();
123
- this.spec = fresh;
124
- // Note: we intentionally don't swap the underlying `http` here — the
125
- // constructor-time bindings stay stable for the lifetime of the Runner.
126
- // Callers wanting a freshly-bound Runner should call
127
- // `client.runtimes(id).run(...)` again.
128
- }
129
-
130
- /**
131
- * Best-effort close — flips a local `isClosed` flag so subsequent
132
- * `runner.tasks` / `runner.files` / `runner.conversations` calls
133
- * throw a friendly error. No
134
- * server-side revoke is performed; future work will route a revoke via
135
- * the CP locator-token path.
136
- */
137
- async close(): Promise<void> {
138
- this.closed = true;
139
- }
140
-
141
- // --- internals ---
142
-
143
- private buildHttp(): HttpClient {
144
- const advanced = this.client.advancedOptions;
145
- return new HttpClient({
146
- apiUrl: this.spec.deployment.endpoint,
147
- token: this.spec.session_token,
148
- additionalHeaders: advanced.additionalHeaders,
149
- fetch: advanced.fetch,
150
- });
151
- }
152
-
153
- /**
154
- * Wrap an HttpClient so that calls after `close()` fail with a clear
155
- * `RunnerExpiredError` instead of hitting the network with a stale
156
- * bearer. No 401 retry / refresh logic — that is the DP materializer's
157
- * job in v1.
158
- */
159
- private guardedHttp(http: HttpClient): HttpClient {
160
- const proxy: HttpClient = Object.create(http);
161
- proxy.request = async <T>(
162
- opts: Parameters<HttpClient["request"]>[0],
163
- ): Promise<T> => {
164
- this.assertOpen();
165
- return http.request<T>(opts);
166
- };
167
- proxy.stream = async (
168
- opts: Parameters<HttpClient["stream"]>[0],
169
- ): Promise<Response> => {
170
- this.assertOpen();
171
- return http.stream(opts);
172
- };
173
- return proxy;
174
- }
175
-
176
- private assertOpen(): void {
177
- if (this.closed) {
178
- throw new RunnerExpiredError({
179
- message: "Runner has been closed",
180
- status: 401,
181
- code: "runner_expired",
182
- });
183
- }
184
- }
185
-
186
- private async requestFreshSpec(): Promise<RunnerSpec> {
187
- const http = this.client.cpHttp;
188
- const body = toRunBody(this.source.options);
189
- if (this.source.kind === "runtime") {
190
- return await http.request<RunnerSpec>({
191
- method: "POST",
192
- path: `/v1/runtimes/${encodeURIComponent(this.source.id)}/run`,
193
- body,
194
- });
195
- }
196
- return await http.request<RunnerSpec>({
197
- method: "POST",
198
- path: `/v1/experiments/${encodeURIComponent(this.source.id)}/run`,
199
- body,
200
- });
201
- }
202
- }
203
-
204
- function toRunBody(opts?: RunRequest): Record<string, unknown> {
205
- if (!opts) return {};
206
- const out: Record<string, unknown> = {};
207
- if (opts.identity) out.identity = opts.identity;
208
- if (opts.caller) out.caller = opts.caller;
209
- if (opts.agent_name !== undefined) out.agent_name = opts.agent_name;
210
- if (opts.ttl_seconds !== undefined) out.ttl_seconds = opts.ttl_seconds;
211
- if (opts.scope !== undefined) out.scope = opts.scope;
212
- return out;
213
- }
package/src/types.ts DELETED
@@ -1,13 +0,0 @@
1
- /**
2
- * Re-export shared types and functions from @introspection-sdk/types
3
- */
4
- export type {
5
- AdvancedOptions,
6
- IntrospectionClientOptions,
7
- FeedbackOptions,
8
- UserTraits,
9
- } from "@introspection-sdk/types";
10
-
11
- export type { GenAiContext, IdentityContext } from "@introspection-sdk/types";
12
-
13
- export { generateEventId } from "@introspection-sdk/types";
package/src/utils.ts DELETED
@@ -1,95 +0,0 @@
1
- import { DiagLogLevel, DiagLogger } from "@opentelemetry/api";
2
- import { HttpsProxyAgent } from "https-proxy-agent";
3
- import { getProxyForUrl } from "proxy-from-env";
4
-
5
- /**
6
- * Attach a forward-proxy agent to OTLP exporter options when a proxy is
7
- * configured for the exporter's endpoint.
8
- *
9
- * The OTLP proto exporters use Node's `http`/`https` stack, so this uses
10
- * `HttpsProxyAgent` (an `http.Agent`) rather than the undici dispatcher from
11
- * `@introspection-sdk/introspection-proxy` — a dispatcher only applies to
12
- * `fetch`. Unlike undici's `EnvHttpProxyAgent`, `HttpsProxyAgent` ignores
13
- * `NO_PROXY`, so we resolve the proxy per-endpoint with `proxy-from-env`'s
14
- * {@link getProxyForUrl}, which returns `""` when the host matches `NO_PROXY`.
15
- * This keeps in-cluster endpoints (e.g. `*.svc.cluster.local`) on a direct
16
- * connection instead of tunnelling them through the egress proxy, which has no
17
- * route for them.
18
- */
19
- export function withOtlpHttpsProxy<T extends { url?: string }>(options: T): T {
20
- const proxyUrl = options.url ? getProxyForUrl(options.url) : "";
21
- if (!proxyUrl) return options;
22
-
23
- return {
24
- ...options,
25
- httpAgentOptions: () => new HttpsProxyAgent(proxyUrl),
26
- } as T;
27
- }
28
-
29
- /**
30
- * Logger for introspection-sdk package.
31
- * Uses OpenTelemetry's diagnostic logger.
32
- */
33
- class IntrospectionLogger implements DiagLogger {
34
- private logLevel: DiagLogLevel;
35
-
36
- constructor() {
37
- const logLevelStr = (
38
- process.env.INTROSPECTION_LOG_LEVEL || "INFO"
39
- ).toUpperCase();
40
- this.logLevel = this.parseLogLevel(logLevelStr);
41
- }
42
-
43
- private parseLogLevel(level: string): DiagLogLevel {
44
- switch (level) {
45
- case "ERROR":
46
- return DiagLogLevel.ERROR;
47
- case "WARN":
48
- return DiagLogLevel.WARN;
49
- case "INFO":
50
- return DiagLogLevel.INFO;
51
- case "DEBUG":
52
- return DiagLogLevel.DEBUG;
53
- case "VERBOSE":
54
- return DiagLogLevel.VERBOSE;
55
- default:
56
- return DiagLogLevel.INFO;
57
- }
58
- }
59
-
60
- private shouldLog(level: DiagLogLevel): boolean {
61
- return level <= this.logLevel;
62
- }
63
-
64
- error(...args: unknown[]): void {
65
- if (this.shouldLog(DiagLogLevel.ERROR)) {
66
- console.error("[introspection-sdk]", ...args);
67
- }
68
- }
69
-
70
- warn(...args: unknown[]): void {
71
- if (this.shouldLog(DiagLogLevel.WARN)) {
72
- console.warn("[introspection-sdk]", ...args);
73
- }
74
- }
75
-
76
- info(...args: unknown[]): void {
77
- if (this.shouldLog(DiagLogLevel.INFO)) {
78
- console.info("[introspection-sdk]", ...args);
79
- }
80
- }
81
-
82
- debug(...args: unknown[]): void {
83
- if (this.shouldLog(DiagLogLevel.DEBUG)) {
84
- console.debug("[introspection-sdk]", ...args);
85
- }
86
- }
87
-
88
- verbose(...args: unknown[]): void {
89
- if (this.shouldLog(DiagLogLevel.VERBOSE)) {
90
- console.debug("[introspection-sdk]", ...args);
91
- }
92
- }
93
- }
94
-
95
- export const logger = new IntrospectionLogger();
package/src/version.ts DELETED
@@ -1,2 +0,0 @@
1
- /** Version information for introspection-sdk package. */
2
- export const VERSION = "0.1.0";
package/tsconfig.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "@repo/typescript-config/react-library.json",
3
- "compilerOptions": {
4
- "outDir": "dist"
5
- },
6
- "include": ["src"],
7
- "exclude": ["node_modules", "dist"]
8
- }