@deepagents/context 0.31.0 → 0.32.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 (33) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +202 -17
  4. package/dist/index.js.map +4 -4
  5. package/dist/lib/fragments/socratic.d.ts +21 -0
  6. package/dist/lib/fragments/socratic.d.ts.map +1 -0
  7. package/dist/lib/sandbox/agent-os-sandbox.d.ts +84 -0
  8. package/dist/lib/sandbox/agent-os-sandbox.d.ts.map +1 -0
  9. package/dist/lib/sandbox/container-tool.d.ts +3 -1
  10. package/dist/lib/sandbox/container-tool.d.ts.map +1 -1
  11. package/dist/lib/sandbox/docker-sandbox.d.ts +8 -3
  12. package/dist/lib/sandbox/docker-sandbox.d.ts.map +1 -1
  13. package/dist/lib/sandbox/index.d.ts +2 -1
  14. package/dist/lib/sandbox/index.d.ts.map +1 -1
  15. package/dist/lib/tracing/batch-processor.d.ts +19 -0
  16. package/dist/lib/tracing/batch-processor.d.ts.map +1 -0
  17. package/dist/lib/tracing/exporter.d.ts +22 -0
  18. package/dist/lib/tracing/exporter.d.ts.map +1 -0
  19. package/dist/lib/tracing/ids.d.ts +4 -0
  20. package/dist/lib/tracing/ids.d.ts.map +1 -0
  21. package/dist/lib/tracing/index.d.ts +7 -0
  22. package/dist/lib/tracing/index.d.ts.map +1 -0
  23. package/dist/lib/tracing/index.js +661 -0
  24. package/dist/lib/tracing/index.js.map +7 -0
  25. package/dist/lib/tracing/openai-traces-integration.d.ts +20 -0
  26. package/dist/lib/tracing/openai-traces-integration.d.ts.map +1 -0
  27. package/dist/lib/tracing/processor.d.ts +26 -0
  28. package/dist/lib/tracing/processor.d.ts.map +1 -0
  29. package/dist/lib/tracing/serialization.d.ts +7 -0
  30. package/dist/lib/tracing/serialization.d.ts.map +1 -0
  31. package/dist/lib/tracing/types.d.ts +90 -0
  32. package/dist/lib/tracing/types.d.ts.map +1 -0
  33. package/package.json +18 -5
package/dist/index.d.ts CHANGED
@@ -10,6 +10,7 @@ export * from './lib/fragments/domain.ts';
10
10
  export * from './lib/fragments/message/environment-reminder.ts';
11
11
  export * from './lib/fragments/message/user.ts';
12
12
  export * from './lib/fragments/reasoning.ts';
13
+ export * from './lib/fragments/socratic.ts';
13
14
  export * from './lib/fragments/user.ts';
14
15
  export * from './lib/guardrail.ts';
15
16
  export * from './lib/guardrails/error-recovery.guardrail.ts';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,iCAAiC,CAAC;AAChD,cAAc,qCAAqC,CAAC;AACpD,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iDAAiD,CAAC;AAChE,cAAc,iCAAiC,CAAC;AAChD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,8CAA8C,CAAC;AAC7D,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC;AAChC,cAAc,sCAAsC,CAAC;AACrD,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qCAAqC,CAAC;AACpD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,iCAAiC,CAAC;AAChD,cAAc,qCAAqC,CAAC;AACpD,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iDAAiD,CAAC;AAChE,cAAc,iCAAiC,CAAC;AAChD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,8CAA8C,CAAC;AAC7D,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC;AAChC,cAAc,sCAAsC,CAAC;AACrD,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qCAAqC,CAAC;AACpD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC"}
package/dist/index.js CHANGED
@@ -4152,6 +4152,68 @@ function selfCritique(checks = DEFAULT_SELF_CRITIQUE_CHECKS) {
4152
4152
  });
4153
4153
  }
4154
4154
 
4155
+ // packages/context/src/lib/fragments/socratic.ts
4156
+ function socraticPrompting() {
4157
+ return [
4158
+ role(
4159
+ "You are a deep, methodical thinker. Before producing any output, you reason through the problem by asking and answering foundational questions. You never treat a request as a simple task to complete \u2014 you first build understanding through inquiry, then apply that understanding to produce high-quality output."
4160
+ ),
4161
+ fragment(
4162
+ "socratic_prompting",
4163
+ hint(
4164
+ "When given a task, do not jump straight to producing output. Instead, decompose the task into foundational questions that, once answered, will make the output significantly better. Answer those questions first, then synthesize your answers into the final output."
4165
+ ),
4166
+ principle({
4167
+ title: "Question-first decomposition",
4168
+ description: 'Every task hides assumptions about what "good" looks like. Surface those assumptions by asking what makes the output effective before attempting to produce it.',
4169
+ policies: [
4170
+ 'Ask "What makes X effective/compelling/useful?" before producing X.',
4171
+ "Identify the criteria, frameworks, or principles that govern quality for this type of output.",
4172
+ "Do not skip this step even when the task seems straightforward \u2014 obvious tasks often have non-obvious quality dimensions."
4173
+ ]
4174
+ }),
4175
+ principle({
4176
+ title: "Multi-dimensional inquiry",
4177
+ description: "Explore the problem from multiple angles \u2014 emotional, logical, practical, audience-specific \u2014 through targeted questions.",
4178
+ policies: [
4179
+ "Ask about the audience: Who is this for? What do they care about?",
4180
+ "Ask about constraints: What must this include or avoid?",
4181
+ "Ask about effectiveness: What separates great output from mediocre output in this domain?",
4182
+ "Ask about structure: How should this be organized for maximum impact?"
4183
+ ]
4184
+ }),
4185
+ principle({
4186
+ title: "Framework discovery before application",
4187
+ description: "Build or recall a relevant framework by reasoning through questions, then explicitly apply that framework to the specific task.",
4188
+ policies: [
4189
+ "First derive the framework: What principles govern this type of work?",
4190
+ 'Then apply it: "Now, using these principles, produce the specific output."',
4191
+ "The framework should emerge from your reasoning, not from a template."
4192
+ ]
4193
+ }),
4194
+ workflow({
4195
+ task: "Socratic reasoning process",
4196
+ steps: [
4197
+ "Identify the core task and desired output type.",
4198
+ "Formulate 2-5 foundational questions about what makes this output effective.",
4199
+ "Answer each question, drawing on relevant knowledge and frameworks.",
4200
+ "Synthesize answers into a coherent set of principles or criteria.",
4201
+ "Apply the discovered framework to produce the specific output.",
4202
+ "Verify the output satisfies the criteria you identified."
4203
+ ]
4204
+ }),
4205
+ example({
4206
+ question: "How should I prompt for a value proposition for my AI analytics tool?",
4207
+ answer: "What makes a value proposition compelling to B2B buyers? What emotional and logical triggers should it hit? Now apply that framework to an AI analytics tool that helps teams make faster data-driven decisions."
4208
+ }),
4209
+ example({
4210
+ question: "How should I prompt for a 30-day LinkedIn content calendar for B2B SaaS?",
4211
+ answer: "What types of LinkedIn content generate the most engagement in B2B SaaS? What posting frequency avoids audience fatigue? How should topics build on each other? Now design a 30-day calendar using these principles."
4212
+ })
4213
+ )
4214
+ ];
4215
+ }
4216
+
4155
4217
  // packages/context/src/lib/guardrails/error-recovery.guardrail.ts
4156
4218
  import chalk2 from "chalk";
4157
4219
  var errorRecoveryGuardrail = {
@@ -4260,6 +4322,107 @@ function render(tag, ...fragments) {
4260
4322
  return renderer.render([wrapped]);
4261
4323
  }
4262
4324
 
4325
+ // packages/context/src/lib/sandbox/agent-os-sandbox.ts
4326
+ import "bash-tool";
4327
+ var textDecoder = new TextDecoder();
4328
+ var AgentOsSandboxError = class extends Error {
4329
+ constructor(message2) {
4330
+ super(message2);
4331
+ this.name = "AgentOsSandboxError";
4332
+ }
4333
+ };
4334
+ var AgentOsNotAvailableError = class extends AgentOsSandboxError {
4335
+ constructor(cause) {
4336
+ super(
4337
+ "@rivet-dev/agent-os-core is not installed. Install it with: npm install @rivet-dev/agent-os-core @rivet-dev/agent-os-common"
4338
+ );
4339
+ this.name = "AgentOsNotAvailableError";
4340
+ this.cause = cause;
4341
+ }
4342
+ };
4343
+ var AgentOsCreationError = class extends AgentOsSandboxError {
4344
+ constructor(message2, cause) {
4345
+ super(`Failed to create Agent OS instance: ${message2}`);
4346
+ this.name = "AgentOsCreationError";
4347
+ this.cause = cause;
4348
+ }
4349
+ };
4350
+ async function importAgentOs() {
4351
+ try {
4352
+ return await import("@rivet-dev/agent-os-core");
4353
+ } catch (error) {
4354
+ throw new AgentOsNotAvailableError(
4355
+ error instanceof Error ? error : void 0
4356
+ );
4357
+ }
4358
+ }
4359
+ async function createAgentOsSandbox(options = {}) {
4360
+ const { AgentOs } = await importAgentOs();
4361
+ let os;
4362
+ try {
4363
+ os = await AgentOs.create(options);
4364
+ } catch (error) {
4365
+ const err = error instanceof Error ? error : new Error(String(error));
4366
+ throw new AgentOsCreationError(err.message, err);
4367
+ }
4368
+ return {
4369
+ async executeCommand(command) {
4370
+ try {
4371
+ const result = await os.exec(command);
4372
+ return {
4373
+ stdout: result.stdout,
4374
+ stderr: result.stderr,
4375
+ exitCode: result.exitCode
4376
+ };
4377
+ } catch (error) {
4378
+ const err = error;
4379
+ return {
4380
+ stdout: err.stdout || "",
4381
+ stderr: err.stderr || err.message || "",
4382
+ exitCode: err.exitCode ?? 1
4383
+ };
4384
+ }
4385
+ },
4386
+ async readFile(path3) {
4387
+ try {
4388
+ const bytes = await os.readFile(path3);
4389
+ return textDecoder.decode(bytes);
4390
+ } catch (error) {
4391
+ throw new Error(
4392
+ `Failed to read file "${path3}": ${error instanceof Error ? error.message : String(error)}`
4393
+ );
4394
+ }
4395
+ },
4396
+ async writeFiles(files) {
4397
+ const results = await os.writeFiles(
4398
+ files.map((f) => ({
4399
+ path: f.path,
4400
+ content: typeof f.content === "string" ? f.content : new Uint8Array(f.content)
4401
+ }))
4402
+ );
4403
+ const failures = results.filter((r) => !r.success);
4404
+ if (failures.length > 0) {
4405
+ const details = failures.map((f) => `${f.path}: ${f.error}`).join(", ");
4406
+ throw new Error(`Failed to write files: ${details}`);
4407
+ }
4408
+ },
4409
+ async dispose() {
4410
+ try {
4411
+ await os.dispose();
4412
+ } catch {
4413
+ }
4414
+ }
4415
+ };
4416
+ }
4417
+ async function useAgentOsSandbox(options, fn) {
4418
+ const sandbox = await createAgentOsSandbox(options);
4419
+ try {
4420
+ return await fn(sandbox);
4421
+ } finally {
4422
+ await sandbox.dispose();
4423
+ }
4424
+ }
4425
+
4263
4426
  // packages/context/src/lib/sandbox/binary-bridges.ts
4264
4427
  import { existsSync } from "fs";
4265
4428
  import { defineCommand } from "just-bash";
@@ -4356,6 +4519,11 @@ function resolveRealCwd(ctx) {
4356
4519
  return realCwd;
4357
4520
  }
4358
4521
 
4522
+ // packages/context/src/lib/sandbox/container-tool.ts
4523
+ import {
4524
+ createBashTool
4525
+ } from "bash-tool";
4526
+
4359
4527
  // packages/context/src/lib/sandbox/docker-sandbox.ts
4360
4528
  import "bash-tool";
4361
4529
  import spawn2 from "nano-spawn";
@@ -4448,10 +4616,10 @@ var ComposeStartError = class extends DockerSandboxError {
4448
4616
  }
4449
4617
  };
4450
4618
  function isDebianBased(image) {
4619
+ const lower = image.toLowerCase();
4620
+ if (lower.includes("alpine")) return false;
4451
4621
  const debianPatterns = ["debian", "ubuntu", "node", "python"];
4452
- return debianPatterns.some(
4453
- (pattern) => image.toLowerCase().includes(pattern)
4454
- );
4622
+ return debianPatterns.some((pattern) => lower.includes(pattern));
4455
4623
  }
4456
4624
  function isDockerfileOptions(opts) {
4457
4625
  return "dockerfile" in opts;
@@ -4463,9 +4631,18 @@ var DockerSandboxStrategy = class {
4463
4631
  context;
4464
4632
  mounts;
4465
4633
  resources;
4466
- constructor(mounts = [], resources = {}) {
4634
+ env;
4635
+ constructor(mounts = [], resources = {}, env = {}) {
4636
+ for (const key of Object.keys(env)) {
4637
+ if (key.length === 0 || key.includes("=")) {
4638
+ throw new DockerSandboxError(
4639
+ `Invalid environment variable key: "${key}"`
4640
+ );
4641
+ }
4642
+ }
4467
4643
  this.mounts = mounts;
4468
4644
  this.resources = resources;
4645
+ this.env = env;
4469
4646
  }
4470
4647
  /**
4471
4648
  * Template method - defines the algorithm skeleton for creating a sandbox.
@@ -4522,6 +4699,9 @@ var DockerSandboxStrategy = class {
4522
4699
  "/workspace"
4523
4700
  // Set working directory
4524
4701
  ];
4702
+ for (const [key, value] of Object.entries(this.env)) {
4703
+ args.push("-e", `${key}=${value}`);
4704
+ }
4525
4705
  for (const mount of this.mounts) {
4526
4706
  const mode = mount.readOnly !== false ? "ro" : "rw";
4527
4707
  args.push("-v", `${mount.hostPath}:${mount.containerPath}:${mode}`);
@@ -4625,8 +4805,8 @@ var RuntimeStrategy = class extends DockerSandboxStrategy {
4625
4805
  image;
4626
4806
  packages;
4627
4807
  binaries;
4628
- constructor(image = "alpine:latest", packages = [], binaries = [], mounts, resources) {
4629
- super(mounts, resources);
4808
+ constructor(image = "alpine:latest", packages = [], binaries = [], mounts, resources, env) {
4809
+ super(mounts, resources, env);
4630
4810
  this.image = image;
4631
4811
  this.packages = packages;
4632
4812
  this.binaries = binaries;
@@ -4795,8 +4975,8 @@ var DockerfileStrategy = class extends DockerSandboxStrategy {
4795
4975
  imageTag;
4796
4976
  dockerfile;
4797
4977
  dockerContext;
4798
- constructor(dockerfile, dockerContext = ".", mounts, resources) {
4799
- super(mounts, resources);
4978
+ constructor(dockerfile, dockerContext = ".", mounts, resources, env) {
4979
+ super(mounts, resources, env);
4800
4980
  this.dockerfile = dockerfile;
4801
4981
  this.dockerContext = dockerContext;
4802
4982
  this.imageTag = this.computeImageTag();
@@ -4969,7 +5149,8 @@ async function createDockerSandbox(options = {}) {
4969
5149
  options.dockerfile,
4970
5150
  options.context,
4971
5151
  options.mounts,
4972
- options.resources
5152
+ options.resources,
5153
+ options.env
4973
5154
  );
4974
5155
  } else {
4975
5156
  strategy = new RuntimeStrategy(
@@ -4977,7 +5158,8 @@ async function createDockerSandbox(options = {}) {
4977
5158
  options.packages,
4978
5159
  options.binaries,
4979
5160
  options.mounts,
4980
- options.resources
5161
+ options.resources,
5162
+ options.env
4981
5163
  );
4982
5164
  }
4983
5165
  return strategy.create();
@@ -4992,9 +5174,6 @@ async function useSandbox(options, fn) {
4992
5174
  }
4993
5175
 
4994
5176
  // packages/context/src/lib/sandbox/container-tool.ts
4995
- import {
4996
- createBashTool
4997
- } from "bash-tool";
4998
5177
  async function createContainerTool(options = {}) {
4999
5178
  let sandboxOptions;
5000
5179
  let bashOptions;
@@ -5003,12 +5182,12 @@ async function createContainerTool(options = {}) {
5003
5182
  sandboxOptions = { compose, service, resources };
5004
5183
  bashOptions = rest;
5005
5184
  } else if (isDockerfileOptions(options)) {
5006
- const { dockerfile, context, mounts, resources, ...rest } = options;
5007
- sandboxOptions = { dockerfile, context, mounts, resources };
5185
+ const { dockerfile, context, mounts, resources, env, ...rest } = options;
5186
+ sandboxOptions = { dockerfile, context, mounts, resources, env };
5008
5187
  bashOptions = rest;
5009
5188
  } else {
5010
- const { image, packages, binaries, mounts, resources, ...rest } = options;
5011
- sandboxOptions = { image, packages, binaries, mounts, resources };
5189
+ const { image, packages, binaries, mounts, resources, env, ...rest } = options;
5190
+ sandboxOptions = { image, packages, binaries, mounts, resources, env };
5012
5191
  bashOptions = rest;
5013
5192
  }
5014
5193
  const sandbox = await createDockerSandbox(sandboxOptions);
@@ -7549,6 +7728,9 @@ function visualizeGraph(data) {
7549
7728
  return lines.join("\n");
7550
7729
  }
7551
7730
  export {
7731
+ AgentOsCreationError,
7732
+ AgentOsNotAvailableError,
7733
+ AgentOsSandboxError,
7552
7734
  BM25SkillClassifier,
7553
7735
  BinaryInstallError,
7554
7736
  ComposeStartError,
@@ -7596,6 +7778,7 @@ export {
7596
7778
  clarification,
7597
7779
  correction,
7598
7780
  createAdaptivePollingState,
7781
+ createAgentOsSandbox,
7599
7782
  createBinaryBridges,
7600
7783
  createContainerTool,
7601
7784
  createDockerSandbox,
@@ -7660,6 +7843,7 @@ export {
7660
7843
  selfCritique,
7661
7844
  skills,
7662
7845
  skillsReminder,
7846
+ socraticPrompting,
7663
7847
  soul,
7664
7848
  staticChatTitle,
7665
7849
  stop,
@@ -7670,6 +7854,7 @@ export {
7670
7854
  term,
7671
7855
  toFragment,
7672
7856
  toMessageFragment,
7857
+ useAgentOsSandbox,
7673
7858
  useSandbox,
7674
7859
  user,
7675
7860
  visualizeGraph,